/** * Returns the dimensionless unit. This is a workaround for what seems to be a bug * in the reference implementation 1.0.1 of unit API. */ private static Unit<Dimensionless> getDimensionless(final SystemOfUnits system) { Unit<Dimensionless> unit = system.getUnit(Dimensionless.class); if (unit == null) try { unit = ((Unit<?>) Class.forName("tec.units.ri.AbstractUnit").getField("ONE").get(null)).asType(Dimensionless.class); } catch (ReflectiveOperationException | ClassCastException e) { throw new IllegalArgumentException("Can not create a dimensionless unit from the given provider."); } return unit; }
/** * Returns the dimensionless unit. This is a workaround for what seems to be a bug * in the reference implementation 1.0.1 of unit API. */ private static Unit<Dimensionless> getDimensionless(final SystemOfUnits system) { Unit<Dimensionless> unit = system.getUnit(Dimensionless.class); if (unit == null) try { unit = ((Unit<?>) Class.forName("tec.units.ri.AbstractUnit").getField("ONE").get(null)).asType(Dimensionless.class); } catch (ReflectiveOperationException | ClassCastException e) { throw new IllegalArgumentException("Can not create a dimensionless unit from the given provider."); } return unit; }
/** * Returns the dimensionless unit. This is a workaround for what seems to be a bug * in the reference implementation 1.0.1 of unit API. */ private static Unit<Dimensionless> getDimensionless(final SystemOfUnits system) { Unit<Dimensionless> unit = system.getUnit(Dimensionless.class); if (unit == null) try { unit = ((Unit<?>) Class.forName("tec.units.ri.AbstractUnit").getField("ONE").get(null)).asType(Dimensionless.class); } catch (ReflectiveOperationException | ClassCastException e) { throw new IllegalArgumentException("Can not create a dimensionless unit from the given provider."); } return unit; }
/** * Returns the dimensionless unit. This is a workaround for what seems to be a bug * in the reference implementation 1.0.1 of unit API. */ private static Unit<Dimensionless> getDimensionless(final SystemOfUnits system) { Unit<Dimensionless> unit = system.getUnit(Dimensionless.class); if (unit == null) try { unit = ((Unit<?>) Class.forName("tec.units.ri.AbstractUnit").getField("ONE").get(null)).asType(Dimensionless.class); } catch (ReflectiveOperationException | ClassCastException e) { throw new IllegalArgumentException("Can not create a dimensionless unit from the given provider."); } return unit; }
/** * Creates a new factory which will use the given system of units. * * @param system the system of units to use for creating base units. */ protected Units(final SystemOfUnits system) { metre = system.getUnit(Length.class); radian = system.getUnit(Angle.class); second = system.getUnit(Time.class); one = getDimensionless(system); kilometre = metre .multiply(1000); degree = radian.multiply(Math.PI/180); day = second.multiply(24*60*60); ppm = one .divide(1000000); }
/** * Returns the dimension for the specified quantity type by aggregating the results of {@link DimensionService} or <code>null</code> if the * specified quantity is unknown. * * @param quantityType * the quantity type. * @return the dimension for the quantity type or <code>null</code>. * @since 1.0.2 */ public static <Q extends Quantity<Q>> Dimension of(Class<Q> quantityType) { // TODO: Track services and aggregate results (register custom // types) Unit<Q> siUnit = Units.getInstance().getUnit(quantityType); if (siUnit == null) logger.log(Level.FINER, "Quantity type: " + quantityType + " unknown"); // we're logging but probably FINER is // enough? return (siUnit != null) ? siUnit.getDimension() : null; }
/** * Returns the dimension for the specified quantity type by aggregating the results of {@link DimensionService} or <code>null</code> if the * specified quantity is unknown. * * @param quantityType * the quantity type. * @return the dimension for the quantity type or <code>null</code>. * @since 1.0.1 */ public static <Q extends Quantity<Q>> Dimension of(Class<Q> quantityType) { // TODO: Track services and aggregate results (register custom // types) Unit<Q> siUnit = Units.getInstance().getUnit(quantityType); if (siUnit == null) logger.log(Level.FINER, "Quantity type: " + quantityType + " unknown"); // we're // logging // but // probably // FINER // is // enough? return (siUnit != null) ? siUnit.getDimension() : null; }
/** * Returns the dimension for the specified quantity type by aggregating the results of {@link DimensionService} or <code>null</code> if the * specified quantity is unknown. * * @param quantityType * the quantity type. * @return the dimension for the quantity type or <code>null</code>. * @since 1.0.1 */ public static <Q extends Quantity<Q>> Dimension of(Class<Q> quantityType) { // TODO: Track services and aggregate results (register custom // types) Unit<Q> siUnit = Units.getInstance().getUnit(quantityType); if (siUnit == null) logger.log(Level.FINER, "Quantity type: " + quantityType + " unknown"); // we're // logging // but // probably // FINER // is // enough? return (siUnit != null) ? siUnit.getDimension() : null; }
/** * Creates a new factory which will use the given system of units. * * @param system the system of units to use for creating base units. */ public Units(final SystemOfUnits system) { metre = system.getUnit(Length.class); radian = system.getUnit(Angle.class); second = system.getUnit(Time.class); pascal = system.getUnit(Pressure.class); one = getDimensionless(system); kilometre = metre .multiply(1000); foot = metre .multiply(0.3048); footSurveyUS = metre .multiply(12 / 39.37); degree = radian.multiply(Math.PI / 180); grad = radian.multiply(Math.PI / 200); arcSecond = radian.multiply(Math.PI / (180*60*60)); microradian = radian.divide(1E6); day = second.multiply(24*60*60); hectopascal = pascal.multiply(100); ppm = one .divide(1000000); }