/** * <p> * Returns {@code true} or {@code false} depending on * whether two UnitDefinition objects are compatible. * </p> * <p> * For the purposes of performing this comparison, two * {@link UnitDefinition} objects are considered compatible when they * contain compatible list of {@link Unit} objects. This means two * {@link UnitDefinition} objects are compatible if both satisfy the method * {@link #areEquivalent(UnitDefinition, UnitDefinition)} or one of both has * {@link Kind#INVALID} as {@link Unit.Kind} * * @param ud1 * the first {@link UnitDefinition} object to compare * @param ud2 * the second {@link UnitDefinition} object to compare * @return {@code true} if all the {@link Unit} objects in ud1 are * compatible to the {@link Unit} objects in ud2, {@code false} * otherwise. * @see #areIdentical(UnitDefinition, UnitDefinition) * @see Unit#areEquivalent(Unit, Unit) */ public static boolean areCompatible(UnitDefinition ud1, UnitDefinition ud2) { return areEquivalent(ud1, ud2) || ud2.isInvalid() || ud1.isInvalid(); }
@Override public ASTNodeValue piecewise(List<ASTNode> values) throws SBMLException { int i = 0; ASTNodeValue compiledvalues[] = new ASTNodeValue[values.size()]; for (ASTNode node : values) { compiledvalues[i++] = node.compile(this); } if (values.size() > 2) { ASTNodeValue node = compiledvalues[0]; for (i = 2; i < values.size(); i += 2) { if (!UnitDefinition.areEquivalent(node.getUnits(), compiledvalues[i].getUnits())) { throw new IllegalArgumentException( new UnitException( MessageFormat.format( "Units of some return values in a piecewise function do not match. Given {0} and {1}.", UnitDefinition.printUnits(node.getUnits(), true), UnitDefinition.printUnits(compiledvalues[i].getUnits(), true)))); } } } for (i = 1; i < compiledvalues.length - 1; i += 2) { if (compiledvalues[i].toBoolean()) { return compiledvalues[i - 1]; } } return values.get(i - 1).compile(this); }
@Override public <T> ASTNode2Value<?> piecewise(List<ASTNode2> values) throws SBMLException { int i = 0; ASTNode2Value<?> compiledvalues[] = new ASTNode2Value<?>[values.size()]; for (ASTNode2 node : values) { compiledvalues[i++] = node.compile(this); } if (values.size() > 2) { ASTNode2Value<?> node = compiledvalues[0]; for (i = 2; i < values.size(); i += 2) { if (!UnitDefinition.areEquivalent(node.getUnits(), compiledvalues[i].getUnits())) { throw new IllegalArgumentException( new UnitException( String.format( "Units of some return values in a piecewise function do not match. Given %s and %s.", UnitDefinition.printUnits(node.getUnits(), true), UnitDefinition.printUnits(compiledvalues[i].getUnits(), true)))); } } } for (i = 1; i < compiledvalues.length - 1; i += 2) { if (compiledvalues[i].toBoolean()) { return compiledvalues[i - 1]; } } return values.get(i - 1).compile(this); }
/** * Checks whether the given {@link UnitDefinition} and the * {@link UnitDefinition} or {@link Unit} represented by the given * {@link String} are equivalent. * * @param ud a {@link UnitDefinition} * @param units a String representing either a {@link UnitDefinition} id or a unit {@link Kind}. * @return {@code true} if both units are equivalent * @see #areEquivalent(UnitDefinition, UnitDefinition) * @see Unit#areEquivalent(Unit, Unit) */ public static boolean areEquivalent(UnitDefinition ud, String units) { UnitDefinition ud2 = ud.getModel().getUnitDefinition(units); if (ud2 != null) { return areEquivalent(ud, ud2); } else if (ud.isUnitKind() && Unit.isUnitKind(units, ud.getLevel(), ud.getVersion())) { return Unit.areEquivalent(ud.getUnit(0), units); } return false; }
if (!UnitDefinition.areEquivalent(firstUD, ud)) { check = false; break;
UnitDefinition time = delay.compile(this).getUnits().clone(); if (model.getTimeUnitsInstance() != null) { if (!UnitDefinition.areEquivalent(model.getTimeUnitsInstance(), time)) { throw new IllegalArgumentException(
if (!UnitDefinition.areEquivalent(model.getTimeUnitsInstance(), time)) { throw new IllegalArgumentException(
if (ud2 == null || !UnitDefinition.areEquivalent(ud, ud2)) { if (!UnitDefinition.areEquivalent(ud, def)) { return false;
check = UnitDefinition.areEquivalent(variableUnits, ruleUnits);
return UnitDefinition.areEquivalent(speciesUnits, extendUnits);