KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jscience > physics > units > AlternateUnit


1 /*
2  * JScience - Java(TM) Tools and Libraries for the Advancement of Sciences.
3  * Copyright (C) 2005 - JScience (http://jscience.org/)
4  * All rights reserved.
5  *
6  * Permission to use, copy, modify, and distribute this software is
7  * freely granted, provided that this notice is preserved.
8  */

9 package org.jscience.physics.units;
10
11 import org.jscience.physics.quantities.Quantity;
12
13 /**
14  * <p> This class represents an alternate unit. Alternate units are used
15  * in expressions to distinguish between quantities of a different nature
16  * but of the same dimensions (e.g. angle <code>rad</code>,
17  * angular acceleration <code>rad/s²</code>).</p>
18  * <p> Instances of this class are created using the {@link Unit#alternate}
19  * method. For example:<pre>
20  * Unit<Angle> RADIAN = (Unit<Angle>) SI.ONE.alternate("rad");
21  * </pre></p>
22  *
23  * @author <a HREF="mailto:jean-marie@dautelle.com">Jean-Marie Dautelle</a>
24  * @version 1.1, May 24, 2005
25  */

26 class AlternateUnit<Q extends Quantity> extends DerivedUnit<Q> {
27
28     /**
29      * Creates an alternate unit for the specified unit identified by the
30      * specified symbol.
31      *
32      * @param symbol the symbol for this alternate unit.
33      * @param baseUnits the base units from which this unit is derived from.
34      * @param toBaseUnits the converter to the base unit.
35      */

36      protected AlternateUnit(String JavaDoc symbol, Unit<? super Q> parentUnit,
37              Converter toParentUnit) {
38         _symbol = symbol;
39         _parentUnit = parentUnit;
40         _toParentUnit = toParentUnit;
41     }
42
43     /**
44      * Returns the symbol for this alternate unit.
45      *
46      * @return this alternate unit symbol.
47      */

48     public final String JavaDoc getSymbol() {
49         return _symbol;
50     }
51
52     // Implements abstract method.
53
protected boolean equalsImpl(Object JavaDoc that) {
54         return (that instanceof AlternateUnit) &&
55            ((AlternateUnit)that)._symbol.equals(_symbol) &&
56            (((AlternateUnit)that)._parentUnit == _parentUnit)&&
57            (((AlternateUnit)that)._toParentUnit == _toParentUnit);
58     }
59
60     // Implements abstract method.
61
protected int hashCodeImpl() {
62         return _symbol.hashCode();
63     }
64
65     // Implements abstract method.
66
protected final Unit<? super Q> getParentUnitImpl() {
67         return _parentUnit;
68     }
69     
70     // Implements abstract method.
71
protected final Converter toParentUnitImpl() {
72         return _toParentUnit;
73     }
74
75    private static final long serialVersionUID = 1L;
76 }
Popular Tags