-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBBoolean.java
More file actions
225 lines (206 loc) · 5.4 KB
/
Copy pathBBoolean.java
File metadata and controls
225 lines (206 loc) · 5.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
package sysmlinjava.valuetypes;
import java.util.Optional;
import sysmlinjava.annotations.Attribute;
import sysmlinjava.units.SysMLinJavaUnits;
/**
* SysMLinJava value type for the SysML Boolean.<br>
* <p>
* Note that the {@code Boolean} name clashes with the {@code java.lang.Boolean}
* name. Therefore, this SysMLinJava version uses the double B spelling
* <p>
* <b>Note:</b> as an {@code ObservableValue} implementation, this value type
* can be "observed" by other objects. {@code ValueObserver}s call the
* {@code addValueObserver()} operation to be notiified (called-back) by the
* {@code Boolean} object of any change in its value. This notification will
* only occur if and when the {@code Boolean value} is changed by a call to the
* {@code setValue()} operation. So, while the {@code Boolean value} is publicly
* accessible and can be changed by direct assignment, the {@code setValue()}
* operation must be used if/when {@code ValueObserver}s are to be notified of
* the change.<br>
*
* @author ModelerOne
*
*/
public class BBoolean extends SysMLValueType
{
/**
* Value for true. Use this only for values that won't change.
*/
public static final BBoolean True = new BBoolean(true);
/**
* Value for false. Use this only for values that won't change.
*/
public static final BBoolean False = new BBoolean(false);
/**
* Attribute for the java boolean value to represent the {@code BBoolean}
* instance
*/
@Attribute
public boolean value;
/**
* Constructor
*
* @param value boolean value that is to be the initial value
*/
public BBoolean(boolean value)
{
super();
this.value = value;
}
/**
* Constructor
*
* @param value boolean value that is to be the initial value
* @param name unique name of the {@code BBoolean} instance
*/
public BBoolean(boolean value, String name)
{
super();
this.value = value;
this.name = Optional.of(name);
}
/**
* Constructor - copy
*
* @param value {@code BBoolean} instance whose value is to be the initial/copy
* value
*/
public BBoolean(BBoolean value)
{
super(value);
this.value = value.value;
}
/**
* Returns {@code BBoolean} instance whose value is that of the specified
* boolean
*
* @param value boolean value that is to be the initial value
* @return instance with specified initial value
*/
public static BBoolean of(boolean value)
{
return new BBoolean(value);
}
/**
* Returns the current boolean value
*
* @return current value
*/
public boolean getValue()
{
return value;
}
/**
* Sets this BBoolean to the specified value and notifies all current value
* change observers, if any.
* <p>
* <b>Note:</b>Use this method to change the BBoolean value if/when notification
* of value change observers is needed.
*
* @param value value to be set as a boolean
*/
public void setValue(boolean value)
{
this.value = value;
notifyValueChangeObservers();
}
/**
* Sets this BBoolean to the specified value and notifies all current value
* change observers, if any.
* <p>
* <b>Note:</b>Use this method to change the BBoolean value if/when notification
* of value change observers is needed.
*
* @param value value to be set as a BBoolean
*/
public void setValue(BBoolean value)
{
this.value = value.value;
notifyValueChangeObservers();
}
/**
* Returns whether current value is true
*
* @return true if value is true, false otherwise
*/
public boolean isTrue()
{
return value;
}
/**
* Returns whether current value is false
*
* @return true if value is false, false otherwise
*/
public boolean isFalse()
{
return !value;
}
/**
* Returns whether this value is equal to specified value
*
* @param bool value to compare
* @return true if bool is equal to this value, false otherwise
*/
public boolean equalTo(BBoolean bool)
{
return value == bool.value;
}
/**
* Returns whether this value is equal to specified value
*
* @param bool value to compare
* @return true if bool is equal to this value, false otherwise
*/
public boolean equalTo(boolean bool)
{
return value == bool;
}
/**
* Returns logical negation (NOT) of this value
*
* @return NOT of this value
*/
public BBoolean not()
{
return new BBoolean(!value);
}
/**
* Returns logical conjunction (AND) of this value with specified value
*
* @param bool value to be ANDed with this
* @return true if this value AND bool value is true, false otherwise
*/
public BBoolean and(BBoolean bool)
{
return new BBoolean(value && bool.value);
}
/**
* Returns logical disjunction (OR) of this value with specified value
*
* @param bool value to be ORed with this
* @return true if this value OR bool value is true, false otherwise
*/
public BBoolean or(BBoolean bool)
{
return new BBoolean(value || bool.value);
}
@Override
protected void createUnits()
{
units = SysMLinJavaUnits.Logical;
}
@Override
public String toString()
{
StringBuilder builder = new StringBuilder();
builder.append("BBoolean [value=");
builder.append(value);
builder.append(", name=");
builder.append(name);
builder.append(", id=");
builder.append(id);
builder.append("]");
return builder.toString();
}
}