/** * 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; }
/** * 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; }