📄 immutableexport.java
字号:
/** * Returns ImmutableExport which differs from this ImmutableExport by port characteristic. * @param characteristic PortCharacteristic of new ImmutableExport. * @return ImmutableExport which differs from this ImmutableExport by port characteristic. */ public ImmutableExport withCharacteristic(PortCharacteristic characteristic) { if (characteristic == null) characteristic = PortCharacteristic.UNKNOWN; if (this.characteristic == characteristic) return this; return new ImmutableExport(this.exportId, this.name, this.nameDescriptor, this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, characteristic, getVars()); } /** * Returns ImmutableExport which differs from this ImmutableExport by additional Variable. * If this ImmutableExport has Variable with the same key as new, the old variable will not be in new * ImmutableExport. * @param var additional Variable. * @return ImmutableExport with additional Variable. * @throws NullPointerException if var is null */ public ImmutableExport withVariable(Variable var) { Variable[] vars = arrayWithVariable(var.withParam(false)); if (this.getVars() == vars) return this; return new ImmutableExport(this.exportId, this.name, this.nameDescriptor, this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, vars); } /** * Returns ImmutableExport which differs from this ImmutableExport by removing Variable * with the specified key. Returns this ImmutableExport if it doesn't contain variable with the specified key. * @param key Variable Key to remove. * @return ImmutableExport without Variable with the specified key. * @throws NullPointerException if key is null */ public ImmutableExport withoutVariable(Variable.Key key) { Variable[] vars = arrayWithoutVariable(key); if (this.getVars() == vars) return this; return new ImmutableExport(this.exportId, this.name, this.nameDescriptor, this.originalNodeId, this.originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, vars); } /** * Returns ImmutableExport which differs from this ImmutableExport by renamed Ids. * @param idMapper a map from old Ids to new Ids. * @return ImmutableExport with renamed Ids. */ ImmutableExport withRenamedIds(IdMapper idMapper) { Variable[] vars = arrayWithRenamedIds(idMapper); ExportId exportId = idMapper.get(this.exportId); PortProtoId originalPortId = this.originalPortId; if (originalPortId instanceof ExportId) originalPortId = idMapper.get((ExportId)originalPortId); if (getVars() == vars && this.exportId == exportId && this.originalPortId == originalPortId) return this; return new ImmutableExport(exportId, this.name, this.nameDescriptor, this.originalNodeId, originalPortId, this.alwaysDrawn, this.bodyOnly, this.characteristic, vars); } /** * Writes this ImmutableArcInst to IdWriter. * @param writer where to write. */ void write(IdWriter writer) throws IOException { writer.writePortProtoId(exportId); writer.writeNameKey(name); writer.writeTextDescriptor(nameDescriptor); writer.writeNodeId(originalNodeId); writer.writePortProtoId(originalPortId); writer.writeBoolean(alwaysDrawn); writer.writeBoolean(bodyOnly); writer.writeInt(characteristic.getBits()); super.write(writer); } /** * Reads ImmutableExport from SnapshotReader. * @param reader where to read. */ static ImmutableExport read(IdReader reader) throws IOException { ExportId exportId = (ExportId)reader.readPortProtoId(); Name name = reader.readNameKey(); TextDescriptor nameDescriptor = reader.readTextDescriptor(); int originalNodeId = reader.readNodeId(); PortProtoId originalPortId = reader.readPortProtoId(); boolean alwaysDrawn = reader.readBoolean(); boolean bodyOnly = reader.readBoolean(); int bits = reader.readInt(); PortCharacteristic characteristic = PortCharacteristic.findCharacteristic(bits); boolean hasVars = reader.readBoolean(); Variable[] vars = hasVars ? readVars(reader) : Variable.NULL_ARRAY; return new ImmutableExport(exportId, name, nameDescriptor, originalNodeId, originalPortId, alwaysDrawn, bodyOnly, characteristic, vars); } /** * Returns ELIB user bits of this ImmutableExport. * @return ELIB user bits of this ImmutableExport. */ public int getElibBits() { int userBits = characteristic.getBits() << STATEBITSSH; if (alwaysDrawn) userBits |= PORTDRAWN; if (bodyOnly) userBits |= BODYONLY; return userBits; } /** * Get alwaysDrawn Export flag from ELIB user bits. * @param elibBits ELIB user bits. * @return alwaysDrawn flag. */ public static boolean alwaysDrawnFromElib(int elibBits) { return (elibBits & PORTDRAWN) != 0; } /** * Get bodyOnly Export flag from ELIB user bits. * @param elibBits ELIB user bits. * @return bodyOnly flag. */ public static boolean bodyOnlyFromElib(int elibBits) { return (elibBits & BODYONLY) != 0; } /** * Get PortCharacteristic of Export from ELIB user bits. * @param elibBits ELIB user bits. * @return PortCharacteristic. */ public static PortCharacteristic portCharacteristicFromElib(int elibBits) { PortCharacteristic characteristic = PortCharacteristic.findCharacteristic((elibBits >> STATEBITSSH) & STATEBITSSHIFTED); return characteristic != null ? characteristic : PortCharacteristic.UNKNOWN; } /** * Return a hash code value for fields of this object. * Variables of objects are not compared */ public int hashCodeExceptVariables() { return exportId.hashCode(); } /** * Indicates whether fields of other ImmutableElectricObject are equal to fileds of this object. * Variables of objects are not compared. * @param o other ImmutableElectricObject. * @return true if fields of objects are equal. */ public boolean equalsExceptVariables(ImmutableElectricObject o) { if (this == o) return true; if (!(o instanceof ImmutableExport)) return false; ImmutableExport that = (ImmutableExport)o; return this.exportId == that.exportId && this.name == that.name && this.nameDescriptor == that.nameDescriptor && this.originalNodeId == that.originalNodeId && this.originalPortId == that.originalPortId && this.alwaysDrawn == that.alwaysDrawn && this.bodyOnly == that.bodyOnly && this.characteristic == that.characteristic; } /** * Returns name key of string if string is a valid Export name, null if not. * @param name string to test. * @param busAllowed true of arrayed export name is allowed * @return name key or null. */ public static Name validExportName(String name, boolean busAllowed) { if (name == null) return null; Name nameKey = Name.findName(name); return nameKey.isValid() && !nameKey.isTempname() && !nameKey.hasEmptySubnames() && (busAllowed || !nameKey.isBus()) ? nameKey : null; } /** * Checks invariant of this ImmutableExport. * @throws AssertionError if invariant is broken. */ public void check() { super.check(true); assert exportId != null; assert name != null; assert name.isValid() && !name.hasEmptySubnames() && !name.isTempname(); if (nameDescriptor != null) assert nameDescriptor.isDisplay() && !nameDescriptor.isParam(); assert originalNodeId >= 0; assert originalPortId != null; assert characteristic != null; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -