/** * Constructs from a name. * * @param name The name of the unit. */ private UnknownUnit(final String name) throws NameException { super(UnitName.newUnitName(name, null, name), BaseQuantity.UNKNOWN); }
/** * Factory method for constructing a UnitName from a name. * * @param name * The name of the unit. Shall not be <code> * null</code>. * @throws NameException * <code>name == null</code>. */ public static UnitName newUnitName(final String name) throws NameException { return newUnitName(name, null); }
/** * Factory method for constructing a UnitName from a name. * * @param name * The name of the unit. Shall not be <code> * null</code>. * @throws NameException * <code>name == null</code>. */ public static UnitName newUnitName(final String name) throws NameException { return newUnitName(name, null); }
/** * Constructs from a name. * * @param name The name of the unit. */ private UnknownUnit(final String name) throws NameException { super(UnitName.newUnitName(name, null, name), BaseQuantity.UNKNOWN); }
/** * Returns the identifiers associated with the dimensionless, derived unit. * * @return The identifiers of the dimensionless, derived unit. */ private static UnitName dimensionlessID() { UnitName id; try { id = UnitName.newUnitName("1", "1", "1"); } catch (final NameException e) { id = null; } return id; }
/** * Returns the identifiers associated with the dimensionless, derived unit. * * @return The identifiers of the dimensionless, derived unit. */ private static UnitName dimensionlessID() { UnitName id; try { id = UnitName.newUnitName("1", "1", "1"); } catch (final NameException e) { id = null; } return id; }
/** * Factory method for constructing a UnitName from a name and a plural form * of the name. * * @param name * The name of the unit. Shall not be <code> * null</code>. * @param plural * The plural form of the name. May be <code> * null</code>, in which * case regular plural- forming rules are used to construct the * plural form from the name. * @throws NameException * <code>name == null</code>. */ public static UnitName newUnitName(final String name, final String plural) throws NameException { return newUnitName(name, plural, null); }
/** * Factory method for constructing a UnitName from a name and a plural form * of the name. * * @param name * The name of the unit. Shall not be <code> * null</code>. * @param plural * The plural form of the name. May be <code> * null</code>, in which * case regular plural- forming rules are used to construct the * plural form from the name. * @throws NameException * <code>name == null</code>. */ public static UnitName newUnitName(final String name, final String plural) throws NameException { return newUnitName(name, plural, null); }
/** * Factory method for constructing a derived unit. * * @param name The name of the unit. * @param symbol The symbol for the unit. * @param definition The definition of the unit. * @return The derived unit corresponding to the arguments. */ private static Unit du(final String name, final String symbol, final Unit definition) throws NameException { return definition.clone(UnitName.newUnitName(name, null, symbol)); }
/** * Factory method for constructing a base unit. * * @param name The name of the unit. * @param symbol The symbol for the unit. * @param quantity The base quantity of the unit. * @return The base unit corresponding to the arguments. */ private static BaseUnit bu(final String name, final String symbol, final BaseQuantity quantity) throws NameException, UnitExistsException { return BaseUnit.getOrCreate(UnitName.newUnitName(name, null, symbol), quantity); }
/** * Factory method for constructing a derived unit. * * @param name * The name of the unit. * @param symbol * The symbol for the unit. * @param quantity * The definition of the unit. * @return The derived unit corresponding to the arguments. */ private static Unit du(final String name, final String symbol, final Unit definition) throws NameException { return definition.clone(UnitName.newUnitName(name, null, symbol)); }
/** * Factory method for constructing a base unit. * * @param name * The name of the unit. * @param symbol * The symbol for the unit. * @param quantity * The base quantity of the unit. * @return The base unit corresponding to the arguments. */ private static BaseUnit bu(final String name, final String symbol, final BaseQuantity quantity) throws NameException, UnitExistsException { return BaseUnit.getOrCreate(UnitName.newUnitName(name, null, symbol), quantity); }
/** * Factory method for constructing an identifier from a name, plural, and * symbol. * * @param name * The name for the unit. May be <code>null * </code>. * @param plural * The plural form of the name. If <code>null * </code> and * <code>name</code> is non-<code> * null</code>, then regular * plural-forming rules are used on the name. * @param symbol * The symbol for the unit. May be <code>null * </code>. */ public static UnitID newUnitID(final String name, final String plural, final String symbol) { UnitID id; try { id = name == null ? new UnitSymbol(symbol) : UnitName.newUnitName(name, plural, symbol); } catch (final NameException e) { id = null; // can't happen } return id; }
/** * Factory method for constructing an identifier from a name, plural, and * symbol. * * @param name * The name for the unit. May be <code>null * </code>. * @param plural * The plural form of the name. If <code>null * </code> and * <code>name</code> is non-<code> * null</code>, then regular * plural-forming rules are used on the name. * @param symbol * The symbol for the unit. May be <code>null * </code>. */ public static UnitID newUnitID(final String name, final String plural, final String symbol) { UnitID id; try { id = name == null ? new UnitSymbol(symbol) : UnitName.newUnitName(name, plural, symbol); } catch (final NameException e) { id = null; // can't happen } return id; }
/** * Tests this class. */ public static void main(final String[] args) throws Exception { final BaseUnit meter = new BaseUnit(UnitName.newUnitName("meter", null, "m"), BaseQuantity.LENGTH); System.out .println("meter.getBaseQuantity()=" + meter.getBaseQuantity()); System.out .println("meter.toDerivedUnit(1.)=" + meter.toDerivedUnit(1.)); System.out.println("meter.toDerivedUnit(new float[] {2})[0]=" + meter.toDerivedUnit(new float[] { 2 }, new float[1])[0]); System.out.println("meter.fromDerivedUnit(1.)=" + meter.fromDerivedUnit(1.)); System.out.println("meter.fromDerivedUnit(new float[] {3})[0]=" + meter.fromDerivedUnit(new float[] { 3 }, new float[1])[0]); System.out.println("meter.isCompatible(meter)=" + meter.isCompatible(meter)); final BaseUnit radian = new BaseUnit(UnitName.newUnitName("radian", null, "rad"), BaseQuantity.PLANE_ANGLE); System.out.println("meter.isCompatible(radian)=" + meter.isCompatible(radian)); System.out .println("meter.isDimensionless()=" + meter.isDimensionless()); System.out.println("radian.isDimensionless()=" + radian.isDimensionless()); } }
/** * Tests this class. */ public static void main(final String[] args) throws Exception { final BaseUnit meter = new BaseUnit(UnitName.newUnitName("meter", null, "m"), BaseQuantity.LENGTH); System.out .println("meter.getBaseQuantity()=" + meter.getBaseQuantity()); System.out .println("meter.toDerivedUnit(1.)=" + meter.toDerivedUnit(1.)); System.out.println("meter.toDerivedUnit(new float[] {2})[0]=" + meter.toDerivedUnit(new float[] { 2 }, new float[1])[0]); System.out.println("meter.fromDerivedUnit(1.)=" + meter.fromDerivedUnit(1.)); System.out.println("meter.fromDerivedUnit(new float[] {3})[0]=" + meter.fromDerivedUnit(new float[] { 3 }, new float[1])[0]); System.out.println("meter.isCompatible(meter)=" + meter.isCompatible(meter)); final BaseUnit radian = new BaseUnit(UnitName.newUnitName("radian", null, "rad"), BaseQuantity.PLANE_ANGLE); System.out.println("meter.isCompatible(radian)=" + meter.isCompatible(radian)); System.out .println("meter.isDimensionless()=" + meter.isDimensionless()); System.out.println("radian.isDimensionless()=" + radian.isDimensionless()); } }
new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("second", null, "s"), BaseQuantity.TIME)); System.out.println("timeDimension = \"" + timeDimension + '"'); new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("meter", null, "m"), BaseQuantity.LENGTH)); System.out.println("lengthDimension = \"" + lengthDimension + '"');
new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("second", null, "s"), BaseQuantity.TIME)); System.out.println("timeDimension = \"" + timeDimension + '"'); new UnitDimension( BaseUnit.getOrCreate( UnitName.newUnitName("meter", null, "m"), BaseQuantity.LENGTH)); System.out.println("lengthDimension = \"" + lengthDimension + '"');
/** * Adds a derived unit to the database. * * @param name The name of the unit. * @param definition The definition for the unit. * @param symbol The symbol for the unit. * @param plural The plural form of the name of the unit. * @throws UnitExistsException Attempt to redefine an existing unit. * @throws NameException Bad unit name. * @throws UnitParseException A string specification couldn't be parsed. * @throws SpecificationException Bad string specification. * @throws UnitDBException Problem with the unit database. * @throws PrefixDBException Problem with the prefix database. * @throws NameException Bad unit name. * @throws OperationException Improper unit operation. * @throws UnitSystemException Problem with UnitSystem. */ private void au(final String name, final String definition, final String symbol, final String plural) throws UnitExistsException, NoSuchUnitException, UnitParseException, SpecificationException, UnitDBException, PrefixDBException, OperationException, NameException, UnitSystemException { final Unit unit = format.parse(definition, this); if (unit == null) { throw new NoSuchUnitException(definition); } addUnit(unit.clone(UnitName.newUnitName(name, plural, symbol))); }
throw new NoSuchUnitException(definition); addUnit(unit.clone(UnitName.newUnitName(name, plural, symbol)));