📄 immutablecell.java
字号:
* with the specified key. Returns this ImmutableCell if it doesn't contain parameter with the specified key. * @param key Variable Key to remove. * @return ImmutableCell without Variable with the specified key. * @throws NullPointerException if key is null */ public ImmutableCell withoutParam(Variable.AttrKey key) { Variable[] params = arrayWithoutVariable(this.params, key); if (this.params == params) return this; return new ImmutableCell(this.cellId, this.groupName, this.creationDate, this.revisionDate, this.techId, this.flags, getVars(), params); } /** * Returns ImmutableCell which differs from this ImmutableCell by additional Variable. * If this ImmutableCell has Variable with the same key as new, the old variable will not be in new * ImmutableCell. * @param var additional Variable. * @return ImmutableCell with additional Variable. * @throws NullPointerException if var is null */ public ImmutableCell withVariable(Variable var) { if (var.getTextDescriptor().isParam()) throw new IllegalArgumentException("Variable " + var + " is param"); if (var.isAttribute() && searchVar(params, var.getKey()) >= 0) throw new IllegalArgumentException(this + " has parameter with the same name as variable " + var); if (!paramsAllowed()) var = var.withParam(false); Variable[] vars = arrayWithVariable(var); if (this.getVars() == vars) return this; return new ImmutableCell(this.cellId, this.groupName, this.creationDate, this.revisionDate, this.techId, this.flags, vars, this.params); } /** * Returns ImmutableCell which differs from this ImmutableCell by removing Variable * with the specified key. Returns this ImmutableCell if it doesn't contain variable with the specified key. * @param key Variable Key to remove. * @return ImmutableCell without Variable with the specified key. * @throws NullPointerException if key is null */ public ImmutableCell withoutVariable(Variable.Key key) { Variable[] vars = arrayWithoutVariable(key); if (this.getVars() == vars) return this; return new ImmutableCell(this.cellId, this.groupName, this.creationDate, this.revisionDate, this.techId, this.flags, vars, params); } /** * Returns ImmutableCell which differs from this ImmutableCell by renamed Ids. * @param idMapper a map from old Ids to new Ids. * @return ImmutableCell with renamed Ids. */ ImmutableCell withRenamedIds(IdMapper idMapper) { Variable[] vars = arrayWithRenamedIds(idMapper); Variable[] params = arrayWithRenamedIds(this.params, idMapper); CellId cellId = idMapper.get(this.cellId); if (getVars() == vars && this.params == params && this.cellId == cellId) return this; return new ImmutableCell(cellId, this.groupName, this.creationDate, this.revisionDate, this.techId, this.flags, vars, params); } /** * Returns ImmutableCell which differs from this ImmutableCell by removing all Variables. * Returns this ImmutableCell if it hasn't variables. * @return ImmutableCell without Variables. */ public ImmutableCell withoutVariables() { if (this.getNumVariables() == 0 && params.length == 0) return this; return new ImmutableCell(this.cellId, this.groupName, this.creationDate, this.revisionDate, this.techId, this.flags, Variable.NULL_ARRAY, Variable.NULL_ARRAY); } void checkSimilarParams(ImmutableCell that) { if (this.params.length != that.params.length) throw new IllegalArgumentException("Different params in " + this + " and " + that); for (int i = 0; i < this.params.length; i++) { Variable thisParam = this.params[i]; Variable thatParam = that.params[i]; if (thisParam.getKey() != thatParam.getKey()) throw new IllegalArgumentException("Different params in " + this + " and " + that); if (thisParam.getUnit() != thatParam.getUnit()) throw new IllegalArgumentException("Different units of param " + thisParam.getKey() + " in " + this + " and " + that); if (thisParam.withObject(thatParam.getObject()) != thisParam) throw new IllegalArgumentException("Different values of param " + thisParam.getKey() + " in " + this + " and " + that); } } /** * Returns LibId of the Library to which this ImmutableCell belongs. */ public LibId getLibId() { return cellId.libId; } /** * Writes this ImmutableCell to IdWriter. * @param writer where to write. */ void write(IdWriter writer) throws IOException { writer.writeNodeProtoId(cellId); writer.writeString(groupName.toString()); writer.writeLong(creationDate); writer.writeLong(revisionDate); writer.writeBoolean(techId != null); if (techId != null) writer.writeTechId(techId); writer.writeInt(flags); super.write(writer); writeVars(params, writer); } /** * Reads ImmutableCell from SnapshotReader. * @param reader where to read. */ static ImmutableCell read(IdReader reader) throws IOException { CellId cellId = (CellId)reader.readNodeProtoId(); String groupNameString = reader.readString(); CellName groupName = CellName.parseName(groupNameString); long creationDate = reader.readLong(); long revisionDate = reader.readLong(); boolean hasTechId = reader.readBoolean(); TechId techId = hasTechId ? reader.readTechId() : null; int flags = reader.readInt(); boolean hasVars = reader.readBoolean(); Variable[] vars = hasVars ? readVars(reader) : Variable.NULL_ARRAY; Variable[] params = readVars(reader); return new ImmutableCell(cellId, groupName, creationDate, revisionDate, techId, flags, vars, params); } /** * Return a hash code value for fields of this object. * Variables of objects are not compared */ public int hashCodeExceptVariables() { return cellId.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 ImmutableCell)) return false; ImmutableCell that = (ImmutableCell)o; return this.cellId == that.cellId && this.groupName == that.groupName && this.creationDate == that.creationDate && this.revisionDate == that.revisionDate && this.techId == that.techId && this.flags == that.flags && this.params == that.params; } /** * Checks invariant of this ImmutableCell. * @throws AssertionError if invariant is broken. */ public void check() { super.check(true); assert cellId != null; assert groupName.getVersion() == 0; assert groupName.getView() == View.SCHEMATIC; assert techId == null || techId.idManager == cellId.idManager; for (int i = 0; i < params.length; i++) { Variable param = params[i]; param.check(true, true); assert param.getTextDescriptor().isParam() && param.getTextDescriptor().isInherit(); if (i > 0) assert params[i - 1].getKey().compareTo(param.getKey()) < 0; assert searchVar(param.getKey()) < 0; } if (params.length > 0) { assert paramsAllowed(); for (Variable var: getVars()) { if (var.isAttribute()) assert searchVar(params, var.getKey()) < 0; } } else { assert params == Variable.NULL_ARRAY; } } /** * Tells if parameters are allowed on this ImmutableCell. * Currently parameters are allowed only on icon and scheamtic cells. * @return true if parameters are allowed on this ImmutableCell */ public boolean paramsAllowed() { return cellId.isIcon() || cellId.isSchematic(); } /** * Method to return true if bus names are allowed in this Cell * @return true if bus names are allowed in this Cell */ public boolean busNamesAllowed() { // A hack: bus names are allowed in Clipboard until Clipboard becomes a GUI object return cellId.isIcon() || cellId.isSchematic() || cellId.libId.libName.equals("Clipboard!!"); } @Override public String toString() { return cellId.toString(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -