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
15 import java.util.TreeMap;
\r
17 import org.simantics.databoard.Bindings;
\r
18 import org.simantics.databoard.annotations.Optional;
\r
19 import org.simantics.databoard.binding.mutable.Variant;
\r
20 import org.simantics.databoard.type.MapType;
\r
23 * Interest set of a Map Type.
26 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
28 public class MapInterestSet extends InterestSet {
31 /** Interested in the notifications of entry assignments, add and removal (excludes the value) */
32 public boolean notification; // Assignment Notification
33 /** Interested in the notifications of entry assignments by key (excludes the value). Sorted array of keys */
34 public @Optional Variant[] notifications;
37 /** Interested in new values of entry assignments (includes notification, excludes composite changes)*/
38 public boolean value; // Assignments
39 /** Interested in new values of entry assignments by key (includes notification, excludes composite changes). Sorted array of keys */
40 public @Optional Variant[] values;
43 /** Interest in the contents of values (includes assignment notification and new values) */
44 public @Optional InterestSet componentInterest; // Values
45 /** Interest in the contents of values by key (includes assignment notification and new values) */
46 public @Optional Map<Variant, InterestSet> componentInterests;
48 public MapInterestSet() {}
\r
51 * Create a map interest set
53 * @param notification interested in add, remove and change notifications of entry assignments
54 * @param notifications interested in add, remove and change to assignment of all specific entries
55 * @param value interested in add, remove and change to assignment of all entries, incl. new values
56 * @param values interested in add, remove and change to assignment of all specific entries, incl. new values
57 * @param componentInterest Interest of the changes of values and their sub-value changes of all entries
58 * @param componentInterests Interest of the changes of values and their sub-value changes of specific entries
60 public MapInterestSet(boolean notification, Variant[] notifications, boolean value, Variant[] values, InterestSet componentInterest, Map<Variant, InterestSet> componentInterests) {
61 this.notification = notification;
62 this.notifications = notifications;
65 this.componentInterest = componentInterest;
66 this.componentInterests = componentInterests;
70 * Returns true, if interested in notification of entry add, removal or replacement of container.
71 * This doesn't include interest in the new value
73 * @return true if interested in notifications
75 public boolean inNotifications() {
76 return notification | value | (componentInterest!=null);
80 * Returns true, if interested in notification of entry add, removal or replacement of container of
81 * specific keys. This doesn't include interest in the new value.
83 * @return true if interested in notifications of a specific entry
85 public boolean inNotificationsOf(Variant key) {
86 if (notification || value) return true;
88 if (notifications!=null) {
89 for (int i=0; i<notifications.length; i++) {
90 if (notifications[i] == key) return true;
95 for (int i=0; i<values.length; i++) {
96 if (values[i] == key) return true;
100 if (componentInterests!=null) {
101 InterestSet compositeInterest = componentInterests.get(key);
102 return compositeInterest!=null;
108 * Returns true, if interested in notifications and values of entry assignments.
110 * @return true, if interested in values of entry assignments.
112 public boolean inValues() {
113 return value | (componentInterest!=null);
117 * Returns true, if interested in notifications and values of entry assignments of
120 * @return true, if interested in values of specific entry
122 public boolean inValuesOf(Variant key) {
123 if (value | componentInterest!=null) return true;
126 for (int i=0; i<values.length; i++) {
127 if (values[i] == key) return true;
131 if (componentInterests!=null?componentInterests.containsKey(key):false) return true;
136 * Get the interest of component type of every value.
138 * @return interest of component or <code>null</code>
140 public InterestSet getComponentInterest() {
141 return componentInterest;
145 * Get the interest of component type of entries of <code>key</code>.
147 * @return interest of component or <code>null</code>
149 public InterestSet getComponentInterest(Variant key) {
150 if (componentInterests==null) return null;
151 return componentInterests.get(key);
155 * Add key specific interest. Map is created if null.
\r
160 public void addCompositeInterest(Variant key, InterestSet cis) {
\r
161 if (componentInterests == null) componentInterests = new TreeMap<Variant, InterestSet>( Bindings.VARIANT );
\r
162 componentInterests.put(key, cis);
\r