public static Frequency convertFrequency(Frequency value, String target) { String source = value.getUnit().getSymbol(); if (target.equals(source)) { return value; } throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit().getSymbol(), source)); }
/** * FIXME: this should likely take a default so that locations which don't * want an exception can have * * log.warn("Using new PositiveFloat(1.0)!", e); return new * PositiveFloat(1.0); * * or similar. */ public static ome.units.quantity.Frequency convertFrequency(Frequency t) { if (t == null) { return null; } Double v = t.getValue(); String u = t.getUnit().getSymbol(); ome.xml.model.enums.UnitsFrequency units = makeFrequencyUnitXML(u); ome.units.unit.Unit<ome.units.quantity.Frequency> units2 = ome.xml.model.enums.handlers.UnitsFrequencyEnumHandler .getBaseUnit(units); return new ome.units.quantity.Frequency(v, units2); }
/** * FIXME: this should likely take a default so that locations which don't * want an exception can have * * log.warn("Using new PositiveFloat(1.0)!", e); return new * PositiveFloat(1.0); * * or similar. */ public static ome.units.quantity.Frequency convert(Frequency t) { if (t == null) { return null; } Double v = t.getValue(); // Use the code/symbol-mapping in the ome.model.enums files // to convert to the specification value. String u = ome.model.enums.UnitsFrequency.valueOf( t.getUnit().toString()).getSymbol(); ome.xml.model.enums.UnitsFrequency units = makeXMLUnit(u); ome.units.unit.Unit<ome.units.quantity.Frequency> units2 = ome.xml.model.enums.handlers.UnitsFrequencyEnumHandler .getBaseUnit(units); return new ome.units.quantity.Frequency(v, units2); }