1 /*******************************************************************************
\r
2 * Copyright (c) 2010 Association for Decentralized Information Management in
\r
4 * All rights reserved. This program and the accompanying materials
\r
5 * are made available under the terms of the Eclipse Public License v1.0
\r
6 * which accompanies this distribution, and is available at
\r
7 * http://www.eclipse.org/legal/epl-v10.html
\r
10 * VTT Technical Research Centre of Finland - initial API and implementation
\r
11 *******************************************************************************/
\r
12 package org.simantics.databoard.accessor.interestset;
14 import java.util.Map;
\r
16 import org.simantics.databoard.annotations.Optional;
\r
17 import org.simantics.databoard.type.ArrayType;
\r
20 * Interest set of an Array Type.
23 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
25 public class ArrayInterestSet extends InterestSet {
27 public static final ArrayInterestSet MONITOR_EVERYTHING = new ArrayInterestSet(true, null, true, null, null, null);
30 /** Interested in notification of element assignments, add and removal (excludes the value) */
31 public boolean notification;
32 /** Interested in notifications to elements by index, (excludes the value). Sorted array of indices. */
33 public @Optional int[] notifications;
36 /** Interested in all notification and value assignments */
38 /** Interested in values by element (includes change). Sorted array of indices */
39 public @Optional int[] values;
42 /** Component Interest of the contents of values. Incl. interest in change and value. <code>null</code> if no interest. */
43 public @Optional InterestSet componentInterest;
44 /** Component Interests of the contents of values of specific elements (incl. interest in change and value), <code>null</code> if no interest. */
45 public @Optional Map<Integer, InterestSet> componentInterests;
49 * Create an array interest set
51 * @param notification interested in add, remove and change to assignment of all elements
52 * @param specificNotifications interested in add, remove and change to assignment of all specific elements
53 * @param values interested in add, remove and change to assignment of all elements, incl. new values
54 * @param specificValues interested in add, remove and change to assignment of all specific elements, incl. new values
55 * @param componentInterest Interest of the changes of values and their sub-value changes of all elements
56 * @param componentInterests Interest of the changes of values and their sub-value changes of specific elements
58 public ArrayInterestSet(boolean notification, int[] specificNotifications, boolean values, int[] specificValues, InterestSet componentInterest, Map<Integer, InterestSet> componentInterests) {
59 this.notification = notification;
60 this.notifications = specificNotifications;
62 this.values = specificValues;
63 this.componentInterest = componentInterest;
64 this.componentInterests = componentInterests;
68 * Returns true, if interested in element assignment, add, removal.
69 * This excludes interest in the new values.
71 * @return true if interested in notifications
73 public boolean inNotifications() {
74 return notification | value | (componentInterest!=null);
78 * Returns true, if interested in assignment of the element at specific <tt>index</tt>
81 * @return true if interested in notifications of a specific element
83 public boolean inNotificationsOf(int elementIndex) {
84 if (notification || value) return true;
86 if (notifications!=null) {
87 for (int i=0; i<notifications.length; i++) {
88 if (notifications[i] == elementIndex) return true;
93 for (int i=0; i<values.length; i++) {
94 if (values[i] == elementIndex) return true;
98 if (componentInterests!=null) {
99 InterestSet compositeInterest = componentInterests.get( elementIndex );
100 return compositeInterest!=null;
106 * Returns true, if interested in all new value assignments
108 * @return true if interested in values of any element
110 public boolean inValues() {
111 return value | (componentInterest!=null);
115 * Returns true, if interested in value assignment of a element at
118 * @param elementIndex
119 * @return true if interested in the values of a specific element
121 public boolean inValuesOf(int elementIndex) {
122 if (value | componentInterest!=null) return true;
125 for (int i=0; i<values.length; i++) {
126 if (values[i] == elementIndex) return true;
130 if (componentInterests!=null?componentInterests.containsKey(elementIndex):false) return true;
135 * Get the interest of the contents of every value
137 * @return component interest set or <code>null</code>
139 public InterestSet getComponentInterest() {
140 return componentInterest;
144 * Get composite interest of component value of element at <code>index</code>
146 * @param index element index
147 * @return composite interest set or <code>null</code>
149 public InterestSet getComponentInterest(int index) {
150 if (componentInterests==null) return null;
151 return componentInterests.get(index);