@Override public boolean accepts(Object o) { if (o instanceof UnitDefinition) { return UnitDefinition.areIdentical(ud, (UnitDefinition) o); } return false; }
/** * Checks whether an identical {@link UnitDefinition} like the given * {@link UnitDefinition} is already in this {@link Model}'s * {@link #listOfUnitDefinitions}. If yes, the identifier of the identical * {@link UnitDefinition} will be returned. Otherwise, the given unit is added * to the {@link #listOfUnitDefinitions} and its identifier will be returned. * In any case, this method returns the identifier of a {@link UnitDefinition} * that is part of this {@link Model} at least after calling this method. * * @param units * The unit to be checked and added if no identical * {@link UnitDefinition} can be found. * @return */ public String addUnitDefinitionOrReturnIdenticalUnit(UnitDefinition units) { boolean contains = false; for (UnitDefinition ud : getListOfUnitDefinitions()) { if (UnitDefinition.areIdentical(ud, units)) { units = ud; contains = true; break; } } if (!contains) { addUnitDefinition(units); } return units.getId(); }
@SuppressWarnings("deprecation") @Override public boolean check(ValidationContext ctx, Delay d) { if (d.isSetMath() && (d.getModel().isSetTimeUnits() || ctx.getLevel() < 3)) { UnitDefinition timeUnits = d.getModel().getTimeUnitsInstance(); UnitDefinition delayUnits = d.getDerivedUnitDefinition(); if (ctx.isLevelAndVersionLesserEqualThan(2, 2) && d.getParent().isSetTimeUnits()) { timeUnits = d.getParent().getTimeUnitsInstance(); } if (delayUnits.isInvalid()) { return true; } // check that the units are equivalent return UnitDefinition.areIdentical(delayUnits, timeUnits); } return true; } };