]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.databoard/src/org/simantics/databoard/accessor/interestset/UnionInterestSet.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.databoard / src / org / simantics / databoard / accessor / interestset / UnionInterestSet.java
1 /*******************************************************************************
2  *  Copyright (c) 2010 Association for Decentralized Information Management in
3  *  Industry THTH ry.
4  *  All rights reserved. This program and the accompanying materials
5  *  are made available under the terms of the Eclipse Public License v1.0
6  *  which accompanies this distribution, and is available at
7  *  http://www.eclipse.org/legal/epl-v10.html
8  *
9  *  Contributors:
10  *      VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.databoard.accessor.interestset;
13
14 import org.simantics.databoard.annotations.Optional;
15 import org.simantics.databoard.type.UnionType;
16
17 /**
18  * Interest set of Union Type.
19  * 
20  * @see UnionType
21  * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
22  */
23 public class UnionInterestSet extends InterestSet {
24         
25         public static final UnionInterestSet MONITOR_EVERYTHING = new UnionInterestSet(true, true, null); 
26         
27         /** Interested in the notifications (excludes the value) */
28         public boolean notification = true;
29         /** Interested in the value (includes notification) */  
30         public boolean value = true;
31         /** Component intersts, null if no specific interest */
32         public @Optional InterestSet[] componentInterests;
33                 
34         public UnionInterestSet(boolean notification, boolean value, InterestSet[] componentInterests) {
35                 this.notification = notification;
36                 this.value = value;
37                 this.componentInterests = componentInterests;
38         }
39
40         /**
41          * Returns true, if interested in notification. 
42          * 
43          * @return true, if interested in notification
44          */
45         public boolean inNotifications() {
46                 return notification | value;
47         }       
48         
49         public boolean inNotificationsOf(int tag) {
50                 return notification | value | getComponentInterest(tag)!=null;
51         }
52         
53         /**
54          * Returns true, if interested in the value  
55          * 
56          * @return true, if interested in the value
57          */
58         public boolean inValues() {
59                 return value;
60         }
61         
62         public boolean inValuesOf(int tag) {
63                 return value | getComponentInterest(tag)!=null;
64         }
65
66         /**
67          * Get interest in the component value.
68          * 
69          * @return component interest or <code>null</code>
70          */
71         public InterestSet getComponentInterest(int tag) {
72                 if (componentInterests==null) return null;
73                 return componentInterests[tag];
74         }
75         
76 }
77