/** * @return the number of Unit. */ public int getUnitCount() { return isSetListOfUnits() ? listOfUnits.size() : 0; }
/** * Removes the nth {@link Unit} object from this {@link UnitDefinition} object * and returns a * pointer to it. * The caller owns the returned object and is responsible for deleting it. * * @param i * the index of the Unit object to remove * @return the {@link Unit} object removed. As mentioned above, the caller * owns the * returned item. {@code null} is returned if the given index is out * of * range. */ public Unit removeUnit(int i) { if (isSetListOfUnits()) { // Note that ListOf will already notify listeners. Unit u = listOfUnits.remove(i); return u; } return null; }
@Override public boolean check(ValidationContext ctx, UnitDefinition ud) { boolean success = true; if (ud.isSetListOfUnits()) { for (Unit u : ud.getListOfUnits()) { success = success && u.getOffset() == 0; } } return success; }
/** * Creates an {@link UnitDefinition} instance from a given UnitDefinition. * * @param unitDefinition the {@link UnitDefinition} to clone. */ public UnitDefinition(UnitDefinition unitDefinition) { super(unitDefinition); if (unitDefinition.isSetListOfUnits()) { setListOfUnits(unitDefinition.getListOfUnits().clone()); } }
@Override public boolean check(ValidationContext ctx, Parameter p) { UnitDefinition def = p.getUnitsInstance(); if (def != null && def.isSetListOfUnits() && def.getUnitCount() == 1) { // Celsius not allowed return !def.getUnit(0).isCelsius(); } return true; } };
@Override public String toString() { if (isSetName()) { return getName(); } return isSetListOfUnits() ? printUnits(this, true) : super.toString(); }
@Override public boolean check(ValidationContext ctx, UnitDefinition ud) { if (ud.isSetListOfUnits() || ud.isListOfUnitsEmpty()) { return new UnknownElementValidationFunction<TreeNodeWithChangeSupport>().check(ctx, ud.getListOfUnits()); } return true; }
@Override public boolean check(ValidationContext ctx, UnitDefinition ud) { if (ud.isSetListOfUnits() || ud.isListOfUnitsEmpty()) { return new UnknownAttributeValidationFunction<TreeNodeWithChangeSupport>().check(ctx, ud.getListOfUnits()); } return true; } };
@Override public boolean check(ValidationContext ctx, UnitDefinition ud) { boolean success = true; if (ud.isSetListOfUnits()) { for (Unit u : ud.getListOfUnits()) { if (!u.isCelsius()) { success = success && Unit.isUnitKind(u.getKind(), ctx.getLevel(), ctx.getVersion()); } } } return success; } };
/** * Raises this unit definition by the power of the given exponent, i.e., the * exponents of every unit contained by this unit definition are multiplied * with the given exponent. * * @param exponent the exponent * @return a pointer to this {@link UnitDefinition}. */ public UnitDefinition raiseByThePowerOf(double exponent) { if (isSetListOfUnits()) { Unit u; for (int i = listOfUnits.size() - 1; i >= 0; i--) { u = listOfUnits.get(i); u.setExponent(u.getExponent() * exponent); if (u.getExponent() == 0d) { listOfUnits.remove(i); } } } return this; }
/** * Tests if a given unit definition is a variant * of the predefined unit identifier 'dimensionless'. * * @return {@code true} if this UnitDefinition is a variant of the predefined * unit * dimensionless; false otherwise. */ public boolean isVariantOfDimensionless() { if (isSetListOfUnits()) { UnitDefinition ud = clone(); if (isInvalidSBMLAllowed()) { ud.putUserObject(JSBML.ALLOW_INVALID_SBML, Boolean.TRUE); } ud.convertToSIAndSubstanceUnits(); // if after the simplify() call no more units exists, it's dimensionless if (ud.getUnitCount() == 0) { return true; } else if (ud.getUnitCount() == 1) { return ud.getUnit(0).isDimensionless(); } return false; } // If no listOfUnits is set, it's technically dimensionless return true; }
boolean isVariantOfSubstance = false; if (isSetListOfUnits()) { UnitDefinition ud = clone();
if (isSetListOfUnits()) { UnitDefinition ud = clone();
if (isSetListOfUnits()) { UnitDefinition ud = clone();
if (isSetListOfUnits()) { UnitDefinition ud = clone();
boolean isVariantOfLength = false; if (isSetListOfUnits()) { UnitDefinition ud = clone();
boolean isVariantOfArea = false; if (isSetListOfUnits()) { UnitDefinition ud = clone();
if (definition.isSetListOfUnits()) { for (Unit unit : definition.getListOfUnits()) { boolean contains = false;
/** * Tests if a given unit definition is a variant * of the predefined unit identifier 'substance per area'. * * @return {@code true} if this UnitDefinition is a variant of the predefined * unit 'substance per area'. */ public boolean isVariantOfSubstancePerArea() { if (isSetListOfUnits()) { UnitDefinition ud = clone(); if (isInvalidSBMLAllowed()) { ud.putUserObject(JSBML.ALLOW_INVALID_SBML, Boolean.TRUE); } ud.convertToSIAndSubstanceUnits(); if (ud.getUnitCount() == 2) { if (ud.getUnit(0).isVariantOfSubstance()) { Unit two = ud.getUnit(1).clone(); two.setExponent(-two.getExponent()); return two.isVariantOfArea(); } else if (ud.getUnit(1).isVariantOfSubstance()) { Unit one = ud.getUnit(0).clone(); one.setExponent(-one.getExponent()); return one.isVariantOfArea(); } } } return false; }
if (definition.isSetListOfUnits()) { for (Unit unit1 : definition.getListOfUnits()) { Unit unit = unit1.clone();