/** * Checks whether the given {@link Unit} and the {@link Unit} represented by * the given {@link String} are equivalent. * * @param unit * @param units * @return * @see #areEquivalent(Unit, Unit) */ public static boolean areEquivalent(Unit unit, String units) { return areEquivalent(unit, new Unit(1d, 0, Unit.Kind.valueOf(units), 1d, unit.getLevel(), unit.getVersion())); }
equivalent &= Unit.areEquivalent(ud1.getUnit(i), ud2.getUnit(i));
/** * <p> * Predicate returning true or false depending on whether two Unit objects * are identical. * </p> * <p> * Two Unit objects are considered to be identical if they match in all * attributes. (Contrast this to the method areEquivalent(Unit unit1, Unit * unit2), which compares Unit objects only with respect to certain * attributes.) * </p> * * @param unit1 * the first Unit object to compare * @param unit2 * the second Unit object to compare * @return {@code true} if all the attributes of unit1 are identical to the * attributes of unit2, {@code false} otherwise. * @see #areEquivalent */ public static boolean areIdentical(Unit unit1, Unit unit2) { boolean identical = areEquivalent(unit1, unit2); identical &= unit1.getOffset() == unit2.getOffset(); identical &= unit1.getMultiplier() == unit2.getMultiplier(); return identical && unit1.getScale() == unit2.getScale(); }
/** * 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; }
for (int i = 0; i < ud1clone.getUnitCount(); i++) { equivalent &= Unit.areEquivalent(ud1clone.getUnit(i), ud2clone.getUnit(i));