/** * Returns the derived {@link UnitDefinition} for the given {@link SBaseWithDerivedUnit}. * * <p> Try to get the derived unit from the user objects first and store it there * for future usage if it is not there. * </p> * * @param ctx the validation context * @param sbase the sbase * @return the derived {@link UnitDefinition} for the given {@link SBaseWithDerivedUnit}. */ public static UnitDefinition getDerivedUnitDefinition(ValidationContext ctx, SBaseWithDerivedUnit sbase) { if (sbase.isSetUserObjects() && sbase.getUserObject(VALIDATION_CACHE_DERIVED_UNIT_DEFINITION) != null) { return (UnitDefinition) sbase.getUserObject(VALIDATION_CACHE_DERIVED_UNIT_DEFINITION); } UnitDefinition derivedUD = null; if (! (sbase instanceof AbstractMathContainer)) { derivedUD = sbase.getDerivedUnitDefinition(); } else { derivedUD = getMathDerivedUnitDefinition(ctx, (MathContainer) sbase); } sbase.putUserObject(VALIDATION_CACHE_DERIVED_UNIT_DEFINITION, derivedUD); return derivedUD; }