44
44
public final static ImmutableExport[] NULL_ARRAY = {};
45
45
public final static ImmutableArrayList<ImmutableExport> EMPTY_LIST = new ImmutableArrayList<ImmutableExport>(NULL_ARRAY);
47
/** set if this port should always be drawn */ private static final int PORTDRAWN = 0400000000;
48
/** set to exclude this port from the icon */ private static final int BODYONLY = 01000000000;
46
/** set if this port should always be drawn */
47
private static final int PORTDRAWN = 0400000000;
48
/** set to exclude this port from the icon */
49
private static final int BODYONLY = 01000000000;
49
50
// /** input/output/power/ground/clock state */ private static final int STATEBITS = 036000000000;
50
/** input/output/power/ground/clock state */ private static final int STATEBITSSHIFTED = 036;
51
/** input/output/power/ground/clock state */ private static final int STATEBITSSH = 27;
53
/** id of this Export. */ public final ExportId exportId;
54
/** name of this ImmutableExport. */ public final Name name;
55
/** The text descriptor of name of ImmutableExport. */ public final TextDescriptor nameDescriptor;
56
/** The nodeId of original PortInst. */ public final int originalNodeId;
57
/** The PortProtoId of orignal PortInst. */ public final PortProtoId originalPortId;
58
/** True if this ImmutableExport to be always drawn. */ public final boolean alwaysDrawn;
59
/** True to exclude this ImmutableExport from the icon. */ public final boolean bodyOnly;
60
/** PortCharacteristic of this ImmutableExport. */ public final PortCharacteristic characteristic;
63
* The private constructor of ImmutableExport. Use the factory "newInstance" instead.
51
/** input/output/power/ground/clock state */
52
private static final int STATEBITSSHIFTED = 036;
53
/** input/output/power/ground/clock state */
54
private static final int STATEBITSSH = 27;
55
/** id of this Export. */
56
public final ExportId exportId;
57
/** name of this ImmutableExport. */
58
public final Name name;
59
/** The text descriptor of name of ImmutableExport. */
60
public final TextDescriptor nameDescriptor;
61
/** The nodeId of original PortInst. */
62
public final int originalNodeId;
63
/** The PortProtoId of orignal PortInst. */
64
public final PortProtoId originalPortId;
65
/** True if this ImmutableExport to be always drawn. */
66
public final boolean alwaysDrawn;
67
/** True to exclude this ImmutableExport from the icon. */
68
public final boolean bodyOnly;
69
/** PortCharacteristic of this ImmutableExport. */
70
public final PortCharacteristic characteristic;
73
* The private constructor of ImmutableExport. Use the factory "newInstance" instead.
64
74
* @param exportId id of new Export.
65
* @param name name of new ImmutableExport.
75
* @param name name of new ImmutableExport.
66
76
* @param nameDescriptor TextDescriptor of name of this ImmutableExport.
67
77
* @param originalNodeId node id of original PortInst.
68
78
* @param originalPortId port proto id of original PortInst.
90
* Returns new ImmutableExport object.
100
* Returns new ImmutableExport object.
91
101
* @param exportId id of new Export.
92
* @param name name of new ImmutableExport.
102
* @param name name of new ImmutableExport.
93
103
* @param nameDescriptor TextDescriptor of name of this ImmutableExport.
94
104
* @param originalNodeId node id of original PortInst.
95
105
* @param originalPortId port proto id of original PortInst.
96
106
* @param alwaysDrawn true if new ImmutableExport is always drawn.
97
107
* @param bodyOnly true to exclude new ImmutableExport from the icon.
98
108
* @param characteristic PortCharacteristic of new ImmutableExport.
99
* @return new ImmutableExport object.
100
* @throws NullPointerException if exportId, name, originalPortId is null.
109
* @return new ImmutableExport object.
110
* @throws NullPointerException if exportId, name, originalPortId is null.
101
111
* @throws IllegalArgumentException if originalNodeId is bad.
103
113
public static ImmutableExport newInstance(ExportId exportId, Name name, TextDescriptor nameDescriptor,
104
int originalNodeId, PortProtoId originalPortId,
105
boolean alwaysDrawn, boolean bodyOnly, PortCharacteristic characteristic) {
106
if (exportId == null) throw new NullPointerException("exportId");
107
if (name == null) throw new NullPointerException("name");
108
if (!name.isValid() || name.hasEmptySubnames() || name.isTempname()) throw new IllegalArgumentException("name");
109
if (nameDescriptor != null)
114
int originalNodeId, PortProtoId originalPortId,
115
boolean alwaysDrawn, boolean bodyOnly, PortCharacteristic characteristic) {
116
if (exportId == null) {
117
throw new NullPointerException("exportId");
120
throw new NullPointerException("name");
122
if (!name.isValid() || name.hasEmptySubnames() || name.isTempname()) {
123
throw new IllegalArgumentException("name");
125
if (nameDescriptor != null) {
110
126
nameDescriptor = nameDescriptor.withDisplayWithoutParam();
111
if (originalNodeId < 0) throw new IllegalArgumentException("originalNodeId");
112
if (originalPortId == null) throw new NullPointerException("orignalPortId");
113
if (characteristic == null) characteristic = PortCharacteristic.UNKNOWN;
114
return new ImmutableExport(exportId, name, nameDescriptor,
128
if (originalNodeId < 0) {
129
throw new IllegalArgumentException("originalNodeId");
131
if (originalPortId == null) {
132
throw new NullPointerException("orignalPortId");
134
if (characteristic == null) {
135
characteristic = PortCharacteristic.UNKNOWN;
137
return new ImmutableExport(exportId, name, nameDescriptor,
115
138
originalNodeId, originalPortId, alwaysDrawn, bodyOnly, characteristic, Variable.NULL_ARRAY);
119
* Returns ImmutableExport which differs from this ImmutableExport by name.
120
* @param name export name key.
121
* @return ImmutableExport which differs from this ImmutableExport by name.
122
* @throws NullPointerException if name is null
124
public ImmutableExport withName(Name name) {
125
if (this.name.toString().equals(name.toString())) return this;
126
if (name == null) throw new NullPointerException("name");
127
if (!name.isValid() || name.hasEmptySubnames() || name.isTempname()) throw new IllegalArgumentException("name");
128
return new ImmutableExport(this.exportId, name, this.nameDescriptor,
142
* Returns ImmutableExport which differs from this ImmutableExport by name.
143
* @param name export name key.
144
* @return ImmutableExport which differs from this ImmutableExport by name.
145
* @throws NullPointerException if name is null
147
public ImmutableExport withName(Name name) {
148
if (this.name.toString().equals(name.toString())) {
152
throw new NullPointerException("name");
154
if (!name.isValid() || name.hasEmptySubnames() || name.isTempname()) {
155
throw new IllegalArgumentException("name");
157
return new ImmutableExport(this.exportId, name, this.nameDescriptor,
129
158
this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, getVars());
133
* Returns ImmutableExport which differs from this ImmutableExport by name descriptor.
162
* Returns ImmutableExport which differs from this ImmutableExport by name descriptor.
134
163
* @param nameDescriptor TextDescriptor of name
135
* @return ImmutableExport which differs from this ImmutableExport by name descriptor.
137
public ImmutableExport withNameDescriptor(TextDescriptor nameDescriptor) {
138
if (nameDescriptor != null)
164
* @return ImmutableExport which differs from this ImmutableExport by name descriptor.
166
public ImmutableExport withNameDescriptor(TextDescriptor nameDescriptor) {
167
if (nameDescriptor != null) {
139
168
nameDescriptor = nameDescriptor.withDisplayWithoutParam();
140
if (this.nameDescriptor == nameDescriptor) return this;
141
return new ImmutableExport(this.exportId, this.name, nameDescriptor,
170
if (this.nameDescriptor == nameDescriptor) {
173
return new ImmutableExport(this.exportId, this.name, nameDescriptor,
142
174
this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, getVars());
146
* Returns ImmutableExport which differs from this ImmutableExport by original port.
178
* Returns ImmutableExport which differs from this ImmutableExport by original port.
147
179
* @param originalNodeId node id of original PortInst.
148
180
* @param originalPortId port proto id of original PortInst.
149
* @return ImmutableExport which differs from this ImmutableExport by original port.
181
* @return ImmutableExport which differs from this ImmutableExport by original port.
150
182
* @throws NullPointerException if originalPortId is null.
152
public ImmutableExport withOriginalPort(int originalNodeId, PortProtoId originalPortId) {
153
if (this.originalNodeId == originalNodeId && this.originalPortId == originalPortId) return this;
154
if (originalPortId == null) throw new NullPointerException("originalPortId");
155
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
184
public ImmutableExport withOriginalPort(int originalNodeId, PortProtoId originalPortId) {
185
if (this.originalNodeId == originalNodeId && this.originalPortId == originalPortId) {
188
if (originalPortId == null) {
189
throw new NullPointerException("originalPortId");
191
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
156
192
originalNodeId, originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, getVars());
160
* Returns ImmutableExport which differs from this ImmutableExport by alwaysDrawn flag.
196
* Returns ImmutableExport which differs from this ImmutableExport by alwaysDrawn flag.
161
197
* @param alwaysDrawn true if new ImmutableExport is always drawn.
162
* @return ImmutableExport which differs from this ImmutableExport by alwaysDrawn flag.
164
public ImmutableExport withAlwaysDrawn(boolean alwaysDrawn) {
165
if (this.alwaysDrawn == alwaysDrawn) return this;
166
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
198
* @return ImmutableExport which differs from this ImmutableExport by alwaysDrawn flag.
200
public ImmutableExport withAlwaysDrawn(boolean alwaysDrawn) {
201
if (this.alwaysDrawn == alwaysDrawn) {
204
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
167
205
this.originalNodeId, this.originalPortId, alwaysDrawn, this.bodyOnly, this.characteristic, getVars());
171
* Returns ImmutableExport which differs from this ImmutableExport by bodyOnly flag.
209
* Returns ImmutableExport which differs from this ImmutableExport by bodyOnly flag.
172
210
* @param bodyOnly true to exclude new ImmutableExport from the icon.
173
* @return ImmutableExport which differs from this ImmutableExport by bodyOnly flag.
175
public ImmutableExport withBodyOnly(boolean bodyOnly) {
176
if (this.bodyOnly == bodyOnly) return this;
177
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
211
* @return ImmutableExport which differs from this ImmutableExport by bodyOnly flag.
213
public ImmutableExport withBodyOnly(boolean bodyOnly) {
214
if (this.bodyOnly == bodyOnly) {
217
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
178
218
this.originalNodeId, this.originalPortId, this.alwaysDrawn, bodyOnly, this.characteristic, getVars());
182
* Returns ImmutableExport which differs from this ImmutableExport by port characteristic.
222
* Returns ImmutableExport which differs from this ImmutableExport by port characteristic.
183
223
* @param characteristic PortCharacteristic of new ImmutableExport.
184
* @return ImmutableExport which differs from this ImmutableExport by port characteristic.
186
public ImmutableExport withCharacteristic(PortCharacteristic characteristic) {
187
if (characteristic == null) characteristic = PortCharacteristic.UNKNOWN;
188
if (this.characteristic == characteristic) return this;
189
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
224
* @return ImmutableExport which differs from this ImmutableExport by port characteristic.
226
public ImmutableExport withCharacteristic(PortCharacteristic characteristic) {
227
if (characteristic == null) {
228
characteristic = PortCharacteristic.UNKNOWN;
230
if (this.characteristic == characteristic) {
233
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
190
234
this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, characteristic, getVars());
194
* Returns ImmutableExport which differs from this ImmutableExport by additional Variable.
238
* Returns ImmutableExport which differs from this ImmutableExport by additional Variable.
195
239
* If this ImmutableExport has Variable with the same key as new, the old variable will not be in new
196
240
* ImmutableExport.
197
* @param var additional Variable.
198
* @return ImmutableExport with additional Variable.
199
* @throws NullPointerException if var is null
241
* @param var additional Variable.
242
* @return ImmutableExport with additional Variable.
243
* @throws NullPointerException if var is null
201
245
public ImmutableExport withVariable(Variable var) {
202
246
Variable[] vars = arrayWithVariable(var.withParam(false));
203
if (this.getVars() == vars) return this;
204
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
247
if (this.getVars() == vars) {
250
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
205
251
this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, vars);
209
* Returns ImmutableExport which differs from this ImmutableExport by removing Variable
255
* Returns ImmutableExport which differs from this ImmutableExport by removing Variable
210
256
* with the specified key. Returns this ImmutableExport if it doesn't contain variable with the specified key.
211
* @param key Variable Key to remove.
212
* @return ImmutableExport without Variable with the specified key.
213
* @throws NullPointerException if key is null
257
* @param key Variable Key to remove.
258
* @return ImmutableExport without Variable with the specified key.
259
* @throws NullPointerException if key is null
215
261
public ImmutableExport withoutVariable(Variable.Key key) {
216
262
Variable[] vars = arrayWithoutVariable(key);
217
if (this.getVars() == vars) return this;
218
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
263
if (this.getVars() == vars) {
266
return new ImmutableExport(this.exportId, this.name, this.nameDescriptor,
219
267
this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, vars);
223
* Returns ImmutableExport which differs from this ImmutableExport by renamed Ids.
224
* @param idMapper a map from old Ids to new Ids.
271
* Returns ImmutableExport which differs from this ImmutableExport by renamed Ids.
272
* @param idMapper a map from old Ids to new Ids.
225
273
* @return ImmutableExport with renamed Ids.
227
275
ImmutableExport withRenamedIds(IdMapper idMapper) {
228
276
Variable[] vars = arrayWithRenamedIds(idMapper);
229
277
ExportId exportId = idMapper.get(this.exportId);
230
278
PortProtoId originalPortId = this.originalPortId;
231
if (originalPortId instanceof ExportId)
232
originalPortId = idMapper.get((ExportId)originalPortId);
233
if (getVars() == vars && this.exportId == exportId && this.originalPortId == originalPortId) return this;
234
return new ImmutableExport(exportId, this.name, this.nameDescriptor,
279
if (originalPortId instanceof ExportId) {
280
originalPortId = idMapper.get((ExportId) originalPortId);
282
if (getVars() == vars && this.exportId == exportId && this.originalPortId == originalPortId) {
285
return new ImmutableExport(exportId, this.name, this.nameDescriptor,
235
286
this.originalNodeId, originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, vars);