/** * @return the number of Unit. * @libsbml.deprecated use {@link #getUnitCount()} */ public int getNumUnits() { return getUnitCount(); }
/** * Creates an HTML string representation of this UnitDefinition. * @param ud * * @return */ public static String toHTML(UnitDefinition ud) { StringBuilder sb = new StringBuilder(); if (ud != null) { for (int i = 0; i < ud.getUnitCount(); i++) { Unit unit = ud.getUnit(i); if (i > 0) { sb.append(' '); sb.append(C_DOT); sb.append(' '); } sb.append(toHTML(unit)); } } return sb.toString(); }
/** * Creates an HTML string representation of this UnitDefinition. * @param ud * * @return */ public static String toHTML(UnitDefinition ud) { StringBuilder sb = new StringBuilder(); if (ud != null) { for (int i = 0; i < ud.getUnitCount(); i++) { Unit unit = ud.getUnit(i); if (i > 0) { sb.append(' '); sb.append(C_DOT); sb.append(' '); } sb.append(toHTML(unit)); } } return sb.toString(); }
/** * Flag to indicate whether or not units have been fully declared for this * value. * * @return */ public boolean containsUndeclaredUnits() { return !isSetUnit() || (getUnits().getUnitCount() == 0); }
/** * Flag to indicate whether or not units have been fully declared for this * value. * * @return */ public boolean containsUndeclaredUnits() { return !isSetUnit() || (getUnits().getUnitCount() == 0); }
/** * Returns the number of {@link Unit}s of this {@link Model}. * * @return the number of {@link Unit}s of this {@link Model}. */ public int getUnitCount() { int count = 0; if (isSetListOfUnitDefinitions()) { for (UnitDefinition ud : getListOfUnitDefinitions()) { count += ud.getUnitCount(); } } return count; }
@Override public boolean check(ValidationContext ctx, SBaseWithDerivedUnit sb) { UnitDefinition ud = ValidationTools.getDerivedUnitDefinition(ctx, sb); return ud != null && ud.getUnitCount() > 0 && !ud.getUnit(0).isInvalid(); } };
@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; } };
/** * Checks if this UnitDefinition is invalid. * * @return {@code true} if this UnitDefinition is invalid. */ public boolean isInvalid() { UnitDefinition ud = clone().simplify(); if (ud.getUnitCount() == 1) { return ud.getUnit(0).isInvalid(); } return false; }
@Override public boolean check(ValidationContext ctx, Model m) { if (m.isSetVolumeUnits()) { UnitDefinition ud = m.getVolumeUnitsInstance(); if (ud != null && ud.getUnitCount() == 0) { return false; } if (ud != null) { return ud.isVariantOfVolume() || ud.isVariantOfDimensionless(); } } return true; } };
@Override public boolean check(ValidationContext ctx, Model m) { if (m.isSetTimeUnits()) { UnitDefinition ud = m.getTimeUnitsInstance(); if (ud != null && ud.getUnitCount() == 0) { return false; } if (ud != null) { return ud.isVariantOfTime() || ud.isVariantOfDimensionless(); } } return true; } };
@Override public boolean check(ValidationContext ctx, Model m) { if (m.isSetAreaUnits()) { UnitDefinition ud = m.getAreaUnitsInstance(); if (ud != null && ud.getUnitCount() == 0) { return false; } if (ud != null) { return ud.isVariantOfArea() || ud.isVariantOfDimensionless(); } } return true; } };
@Override public boolean check(ValidationContext ctx, Model m) { if (m.isSetLengthUnits()) { UnitDefinition ud = m.getLengthUnitsInstance(); if (ud != null && ud.getUnitCount() == 0) { return false; } if (ud != null) { return ud.isVariantOfLength() || ud.isVariantOfDimensionless(); } } return true; } };
@Override public boolean check(ValidationContext ctx, Model m) { if (m.isSetExtentUnits()) { UnitDefinition ud = m.getExtentUnitsInstance(); if (ud != null && ud.getUnitCount() == 0) { return false; } if (ud != null) { return ud.isVariantOfSubstance() || ud.isVariantOfDimensionless(); } } return true; } };
/** * Throws an {@link IllegalArgumentException} if the given units do not * represent a dimensionless or invalid unit. * * @param units */ protected void checkForDimensionlessOrInvalidUnits(UnitDefinition units) { units.simplify(); String illegal = null; if (units.getUnitCount() == 1) { Kind kind = units.getUnit(0).getKind(); if ((kind != Kind.DIMENSIONLESS) && (kind != Kind.ITEM) && (kind != Kind.RADIAN) && (kind != Kind.STERADIAN) && (kind != Kind.INVALID)) { illegal = kind.toString(); } } else { illegal = units.toString(); } if (illegal != null && (!allowInvalidModel) ) { throw new IllegalArgumentException( new UnitException(MessageFormat.format( "An invalid or dimensionless unit is required but given is {0}.", illegal))); } }
/** * Tests whether this {@link UnitDefinition} contains * exactly one {@link Unit} that itself represents a {@link Kind}, i.e., * multiplier = 1, exponent = 1, scale = 1. Note that this method requires * the level and version attributes of this {@link UnitDefinition} to be * set. * * @return {@code true} if this {@link UnitDefinition} contains * exactly one {@link Unit} that itself represents a simple {@link Kind}. */ public boolean isUnitKind() { if (getUnitCount() == 1) { return Unit.isUnitKind(getUnit(0).getKind(), getLevel(), getVersion()); } return false; }
@Override public boolean check(ValidationContext ctx, UnitDefinition ud) { if (ud.getId().equals("length")) { if (ctx.isLevelAndVersionLesserEqualThan(2, 1)) { // Meter not allowed on L2V1 if (ctx.isLevelAndVersionEqualTo(2, 1) && ud.getUnitCount() > 0 && ud.getUnit(0).getKind() == Kind.METER) { return false; } return ud.isVariantOfLength(); } else { return ud.isVariantOfLength() || ud.isVariantOfDimensionless(); } } return true; } };
private boolean isVariantOfArea(ValidationContext ctx, UnitDefinition ud) { // TODO - to really use the level and version of the context, we need to clone the UnitDefinition // and change the level and version of the UnitDefinition and Unit instances so that all the methods // on UnitDefinition or Unit use this level and version as well. if (ctx.getLevel() == 1) { return ud.isVariantOfArea(); } ud = ud.clone().simplify(); if (ud.getUnitCount() == 1) { Unit u = ud.getUnit(0); return u.getKind() == Kind.METRE && u.getExponent() == 2; } return false; } };
@Override @SuppressWarnings("deprecation") public String getDerivedUnits() { UnitDefinition ud = getDerivedUnitDefinition(); Model m = getModel(); if (m != null) { if (m.getUnitDefinition(ud.getId()) != null) { return ud.getId(); } } if (ud.getUnitCount() == 1) { Unit u = ud.getUnit(0); if ((u.getOffset() == 0) && (u.getMultiplier() == 1) && (u.getScale() == 0) && (u.getExponent() == 1)) { return u.getKind().toString().toLowerCase(); } } return null; }
/** * Tests if the given unit is a predefined unit, meaning it is one of the five SBML predefined * unit identifiers ('substance', 'volume', 'area', 'length' or 'time'). * * @param ud a unit definition * @return {@code true} if the given unit is a predefined unit. */ public static boolean isPredefined(UnitDefinition ud) { if (ud.getLevel() > 2) { return false; } if (ud.getUnitCount() == 1) { UnitDefinition predef = getPredefinedUnit(ud.getId(), ud.getLevel(), ud.getVersion()); if ((predef != null) && Unit.isPredefined(ud.getId(), ud.getLevel())) { return ud.equals(predef); } } return false; }