/** * Return true if this ucar.units.Unit is convertible to secs. * * @param uu check this Unit * @return true if its a Time */ static public boolean isTimeUnit(ucar.units.Unit uu) { return uu.isCompatible(secsUnit); }
/** * Return true if this ucar.units.Unit is convertible to secs. * * @param uu check this Unit * @return true if its a Time */ static public boolean isTimeUnit(ucar.units.Unit uu) { return uu.isCompatible(secsUnit); }
/** * Return true if this ucar.units.Unit is convertible to secs. * * @param uu check this Unit * @return true if its a Time */ static public boolean isTimeUnit(ucar.units.Unit uu) { return uu.isCompatible(secsUnit); }
/** * Constructs from a "from" unit and a "to" unit. * @param fromUnit The unit from which to convert. * @param toUnit The unit to which to convert. * @throws ConversionException The units are not convertible. */ protected ConverterImpl(Unit fromUnit, Unit toUnit) throws ConversionException { if (!fromUnit.isCompatible(toUnit)) throw new ConversionException(fromUnit, toUnit); }
/** * Constructs from a "from" unit and a "to" unit. * @param fromUnit The unit from which to convert. * @param toUnit The unit to which to convert. * @throws ConversionException The units are not convertible. */ protected ConverterImpl(Unit fromUnit, Unit toUnit) throws ConversionException { if (!fromUnit.isCompatible(toUnit)) throw new ConversionException(fromUnit, toUnit); }
/** * Return true if this ucar.units.Unit is a Date. * * @param uu check this Unit * @return true if its a Date */ static public boolean isDateUnit(ucar.units.Unit uu) { boolean ok = uu.isCompatible(dateReferenceUnit); if (!ok) return false; try { uu.getConverterTo(dateReferenceUnit); return true; } catch (ConversionException e) { return false; } }
/** * Return true if this ucar.units.Unit is a Date. * * @param uu check this Unit * @return true if its a Date */ static public boolean isDateUnit(ucar.units.Unit uu) { boolean ok = uu.isCompatible(dateReferenceUnit); if (!ok) return false; try { uu.getConverterTo(dateReferenceUnit); return true; } catch (ConversionException e) { return false; } }
/** * Return true if this ucar.units.Unit is a Date. * * @param uu check this Unit * @return true if its a Date */ static public boolean isDateUnit(ucar.units.Unit uu) { boolean ok = uu.isCompatible(dateReferenceUnit); if (!ok) return false; try { uu.getConverterTo(dateReferenceUnit); return true; } catch (ConversionException e) { return false; } }
/** * Indicates if a unit is a time unit. * * @param unit The unit in question. * @return {@code true} if and only if {@code unit} is a time unit. * @Throws UnitSystemException if the unit system can't be initialized. */ private static boolean isTimeUnit(final Unit unit) throws UnitSystemException { return unit.isCompatible(UnitSystemManager.instance().getBaseUnit( BaseQuantity.TIME)); }
/** * Indicates if a unit is a time unit. * * @param unit The unit in question. * @return {@code true} if and only if {@code unit} is a time unit. * @Throws UnitSystemException if the unit system can't be initialized. */ private static boolean isTimeUnit(final Unit unit) throws UnitSystemException { return unit.isCompatible(UnitSystemManager.instance().getBaseUnit( BaseQuantity.TIME)); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is compatible to unitString2, * meaning one can be converted to the other. * If either unit string is illegal, return false. * @param unitString check if this is compatible with unitString * @return true if compatible */ public boolean isCompatible(String unitString) { Unit uuWant; try { UnitFormat format = UnitFormatManager.instance(); uuWant = format.parse(unitString); } catch (Exception e) { if (debugParse) System.out.println("Parse " + unitString + " got Exception1 " + e); return false; } return uu.isCompatible(uuWant); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws Exception if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws UnitException if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
/** * Return true if unitString1 is convertible to unitString2 * * @param unitString1 compare this unit * @param unitString2 compare this unit * @return true if the 2 units are compatible * @throws Exception if units parsing fails */ static public boolean isCompatibleWithExceptions(String unitString1, String unitString2) throws Exception { UnitFormat format = UnitFormatManager.instance(); Unit uu1 = format.parse(unitString1); Unit uu2 = format.parse(unitString2); return uu1.isCompatible(uu2); }
/** * Constructs from a reference unit, a time origin, and an identifier. * * @param unit The reference time unit. * @param origin The time origin. * @param id The identifier. * @throws BadUnitException <code>unit</code> is not a unit of time. */ public TimeScaleUnit(final Unit unit, final Date origin, final UnitName id) throws BadUnitException, UnitSystemException { super(id); if (!unit.isCompatible(UnitSystemManager.instance().getBaseUnit( BaseQuantity.TIME))) { throw new BadUnitException("\"" + unit + "\" is not a unit of time"); } _unit = unit; _origin = origin; }
public void testTimeConversion() throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit t1, t2; t1 = format.parse("secs since 1999-01-01 00:00:00"); t2 = format.parse("secs since 1999-01-02 00:00:00"); assert(t1.isCompatible( t2)); logger.debug("t2.convertTo(0.0, t1) = {}", t2.convertTo(0.0, t1)); Assert2.assertNearlyEquals(86400.0, t2.convertTo(0.0, t1)); }
public void testTimeConversion2() throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit t1, t2; t1 = format.parse("hours since 1999-01-01 00:00:00"); t2 = format.parse("hours since 1999-01-02 00:00:00"); assert(t1.isCompatible( t2)); Assert2.assertNearlyEquals(24.0, t2.convertTo(0.0, t1)); }
public void testBasic() throws UnitException { UnitFormat format = UnitFormatManager.instance(); Unit meter = format.parse("meter"); Unit second = format.parse("second"); Unit meterPerSecondUnit = meter.divideBy(second); Unit knot = format.parse("knot"); assert (meterPerSecondUnit.isCompatible(knot)); logger.debug("5 knots is {} {}", knot.convertTo(5, meterPerSecondUnit), format.format(meterPerSecondUnit)); Assert2.assertNearlyEquals(2.5722222f, knot.convertTo(5, meterPerSecondUnit)); }