/** * Copy constructor that converts the given {@link omero.model.Time} * based on the given enum string. * * @param target String representation of the CODE enum */ public TimeI(Time value, String target) throws BigResult { String source = value.getUnit().toString(); if (target.equals(source)) { setValue(value.getValue()); setUnit(value.getUnit()); } else { UnitsTime targetUnit = UnitsTime.valueOf(target); Conversion conversion = conversions.get(value.getUnit()).get(targetUnit); if (conversion == null) { throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit(), target)); } double orig = value.getValue(); BigDecimal big = conversion.convert(orig); double converted = big.doubleValue(); if (Double.isInfinite(converted)) { throw new BigResult(big, "Failed to convert " + source + ":" + target); } setValue(converted); setUnit(targetUnit); } }
/** * Copy constructor that converts the given {@link omero.model.Temperature} * based on the given enum string. * * @param target String representation of the CODE enum */ public TemperatureI(Temperature value, String target) throws BigResult { String source = value.getUnit().toString(); if (target.equals(source)) { setValue(value.getValue()); setUnit(value.getUnit()); } else { UnitsTemperature targetUnit = UnitsTemperature.valueOf(target); Conversion conversion = conversions.get(value.getUnit()).get(targetUnit); if (conversion == null) { throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit(), target)); } double orig = value.getValue(); BigDecimal big = conversion.convert(orig); double converted = big.doubleValue(); if (Double.isInfinite(converted)) { throw new BigResult(big, "Failed to convert " + source + ":" + target); } setValue(converted); setUnit(targetUnit); } }
/** * Copy constructor that converts the given {@link omero.model.Length} * based on the given enum string. * * @param target String representation of the CODE enum */ public LengthI(Length value, String target) throws BigResult { String source = value.getUnit().toString(); if (target.equals(source)) { setValue(value.getValue()); setUnit(value.getUnit()); } else { UnitsLength targetUnit = UnitsLength.valueOf(target); Conversion conversion = conversions.get(value.getUnit()).get(targetUnit); if (conversion == null) { throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit(), target)); } double orig = value.getValue(); BigDecimal big = conversion.convert(orig); double converted = big.doubleValue(); if (Double.isInfinite(converted)) { throw new BigResult(big, "Failed to convert " + source + ":" + target); } setValue(converted); setUnit(targetUnit); } }
/** * Copy constructor that converts the given {@link omero.model.Pressure} * based on the given enum string. * * @param target String representation of the CODE enum */ public PressureI(Pressure value, String target) throws BigResult { String source = value.getUnit().toString(); if (target.equals(source)) { setValue(value.getValue()); setUnit(value.getUnit()); } else { UnitsPressure targetUnit = UnitsPressure.valueOf(target); Conversion conversion = conversions.get(value.getUnit()).get(targetUnit); if (conversion == null) { throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit(), target)); } double orig = value.getValue(); BigDecimal big = conversion.convert(orig); double converted = big.doubleValue(); if (Double.isInfinite(converted)) { throw new BigResult(big, "Failed to convert " + source + ":" + target); } setValue(converted); setUnit(targetUnit); } }
/** * Copy constructor that converts the given {@link omero.model.Power} * based on the given enum string. * * @param target String representation of the CODE enum */ public PowerI(Power value, String target) throws BigResult { String source = value.getUnit().toString(); if (target.equals(source)) { setValue(value.getValue()); setUnit(value.getUnit()); } else { UnitsPower targetUnit = UnitsPower.valueOf(target); Conversion conversion = conversions.get(value.getUnit()).get(targetUnit); if (conversion == null) { throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit(), target)); } double orig = value.getValue(); BigDecimal big = conversion.convert(orig); double converted = big.doubleValue(); if (Double.isInfinite(converted)) { throw new BigResult(big, "Failed to convert " + source + ":" + target); } setValue(converted); setUnit(targetUnit); } }
/** * Copy constructor that converts the given {@link omero.model.ElectricPotential} * based on the given enum string. * * @param target String representation of the CODE enum */ public ElectricPotentialI(ElectricPotential value, String target) throws BigResult { String source = value.getUnit().toString(); if (target.equals(source)) { setValue(value.getValue()); setUnit(value.getUnit()); } else { UnitsElectricPotential targetUnit = UnitsElectricPotential.valueOf(target); Conversion conversion = conversions.get(value.getUnit()).get(targetUnit); if (conversion == null) { throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit(), target)); } double orig = value.getValue(); BigDecimal big = conversion.convert(orig); double converted = big.doubleValue(); if (Double.isInfinite(converted)) { throw new BigResult(big, "Failed to convert " + source + ":" + target); } setValue(converted); setUnit(targetUnit); } }
/** * Copy constructor that converts the given {@link omero.model.Frequency} * based on the given enum string. * * @param target String representation of the CODE enum */ public FrequencyI(Frequency value, String target) throws BigResult { String source = value.getUnit().toString(); if (target.equals(source)) { setValue(value.getValue()); setUnit(value.getUnit()); } else { UnitsFrequency targetUnit = UnitsFrequency.valueOf(target); Conversion conversion = conversions.get(value.getUnit()).get(targetUnit); if (conversion == null) { throw new RuntimeException(String.format( "%f %s cannot be converted to %s", value.getValue(), value.getUnit(), target)); } double orig = value.getValue(); BigDecimal big = conversion.convert(orig); double converted = big.doubleValue(); if (Double.isInfinite(converted)) { throw new BigResult(big, "Failed to convert " + source + ":" + target); } setValue(converted); setUnit(targetUnit); } }