View Javadoc
1   package org.opentrafficsim.core.unit;
2   
3   import static org.opentrafficsim.core.unit.unitsystem.UnitSystem.SI_DERIVED;
4   
5   import org.opentrafficsim.core.unit.unitsystem.UnitSystem;
6   
7   /**
8    * The units of electrical resistance.
9    * <p>
10   * Copyright (c) 2014 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="http://opentrafficsim.org/node/13">OpenTrafficSim License</a>.
12   * <p>
13   * @version May 15, 2014 <br>
14   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
15   */
16  public class ElectricalResistanceUnit extends Unit<ElectricalResistanceUnit>
17  {
18      /** */
19      private static final long serialVersionUID = 20140607L;
20  
21      /** the unit of mass for the electrical resistance unit, e.g., kilogram. */
22      private final MassUnit massUnit;
23  
24      /** the unit of length for the electrical resistance unit, e.g., meters. */
25      private final LengthUnit lengthUnit;
26  
27      /** the unit of electrical current for the electrical resistance unit, e.g., Ampere. */
28      private final ElectricalCurrentUnit electricalCurrentUnit;
29  
30      /** the unit of time for the electrical resistance unit, e.g., second. */
31      private final TimeUnit timeUnit;
32  
33      /** The SI unit for electrical resistance is Ohm. */
34      public static final ElectricalResistanceUnit SI;
35  
36      /** Ohm. */
37      public static final ElectricalResistanceUnit OHM;
38  
39      /** milli-ohm. */
40      public static final ElectricalResistanceUnit MILLIOHM;
41  
42      /** kilo-ohm. */
43      public static final ElectricalResistanceUnit KILOOHM;
44  
45      /** mega-ohm. */
46      public static final ElectricalResistanceUnit MEGAOHM;
47  
48      static
49      {
50          SI =
51                  new ElectricalResistanceUnit(MassUnit.KILOGRAM, LengthUnit.METER, ElectricalCurrentUnit.AMPERE,
52                          TimeUnit.SECOND, "ElectricalResistanceUnit.ohm_(name)", "ElectricalResistanceUnit.ohm",
53                          SI_DERIVED);
54          OHM = SI;
55          MILLIOHM =
56                  new ElectricalResistanceUnit("ElectricalResistanceUnit.milli_ohm", "ElectricalResistanceUnit.m_ohm",
57                          SI_DERIVED, OHM, 0.001);
58          KILOOHM =
59                  new ElectricalResistanceUnit("ElectricalResistanceUnit.kilo_ohm", "ElectricalResistanceUnit.k_ohm",
60                          SI_DERIVED, OHM, 1000.0);
61          MEGAOHM =
62                  new ElectricalResistanceUnit("ElectricalResistanceUnit.mega_ohm", "ElectricalResistanceUnit.M_ohm",
63                          SI_DERIVED, OHM, 1.06);
64      }
65  
66      /**
67       * @param massUnit the unit of mass for the electrical resistance unit, e.g., kilogram
68       * @param lengthUnit the unit of length for the electrical resistance unit, e.g., meter
69       * @param electricalCurrentUnit the unit of electrical current for the electrical resistance unit, e.g., Ampere
70       * @param timeUnit the unit of time for the electrical resistance unit, e.g., second
71       * @param nameKey the key to the locale file for the long name of the unit
72       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
73       * @param unitSystem the unit system, e.g. SI or Imperial
74       */
75      public ElectricalResistanceUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
76              final ElectricalCurrentUnit electricalCurrentUnit, final TimeUnit timeUnit, final String nameKey,
77              final String abbreviationKey, final UnitSystem unitSystem)
78      {
79          super(nameKey, abbreviationKey, unitSystem, OHM, massUnit.getConversionFactorToStandardUnit()
80                  * lengthUnit.getConversionFactorToStandardUnit()
81                  * lengthUnit.getConversionFactorToStandardUnit()
82                  / (electricalCurrentUnit.getConversionFactorToStandardUnit()
83                          * electricalCurrentUnit.getConversionFactorToStandardUnit() * Math.pow(
84                          timeUnit.getConversionFactorToStandardUnit(), 3.0)), true);
85          this.massUnit = massUnit;
86          this.lengthUnit = lengthUnit;
87          this.electricalCurrentUnit = electricalCurrentUnit;
88          this.timeUnit = timeUnit;
89      }
90  
91      /**
92       * @param electricalPotentialUnit the unit of electrical potential difference for the electrical resistance unit,
93       *            e.g., Volt
94       * @param electricalCurrentUnit the unit of electrical current for the electrical resistance unit, e.g., Ampere
95       * @param nameKey the key to the locale file for the long name of the unit
96       * @param abbreviationKey the key to the locale file for the abbreviation of the unit
97       * @param unitSystem the unit system, e.g. SI or Imperial
98       */
99      public ElectricalResistanceUnit(final ElectricalPotentialUnit electricalPotentialUnit,
100             final ElectricalCurrentUnit electricalCurrentUnit, final String nameKey, final String abbreviationKey,
101             final UnitSystem unitSystem)
102     {
103         super(nameKey, abbreviationKey, unitSystem, OHM, electricalPotentialUnit.getConversionFactorToStandardUnit()
104                 / electricalCurrentUnit.getConversionFactorToStandardUnit(), true);
105         this.massUnit = electricalPotentialUnit.getMassUnit();
106         this.lengthUnit = electricalPotentialUnit.getLengthUnit();
107         this.electricalCurrentUnit = electricalCurrentUnit;
108         this.timeUnit = electricalPotentialUnit.getTimeUnit();
109     }
110 
111     /**
112      * @param nameKey the key to the locale file for the long name of the unit
113      * @param abbreviationKey the key to the locale file for the abbreviation of the unit
114      * @param unitSystem the unit system, e.g. SI or Imperial
115      * @param referenceUnit the unit to convert to
116      * @param conversionFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given
117      *            reference unit
118      */
119     public ElectricalResistanceUnit(final String nameKey, final String abbreviationKey, final UnitSystem unitSystem,
120             final ElectricalResistanceUnit referenceUnit, final double conversionFactorToReferenceUnit)
121     {
122         super(nameKey, abbreviationKey, unitSystem, referenceUnit, conversionFactorToReferenceUnit, true);
123         this.massUnit = referenceUnit.getMassUnit();
124         this.lengthUnit = referenceUnit.getLengthUnit();
125         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
126         this.timeUnit = referenceUnit.getTimeUnit();
127     }
128 
129     /**
130      * @return massUnit
131      */
132     public final MassUnit getMassUnit()
133     {
134         return this.massUnit;
135     }
136 
137     /**
138      * @return lengthUnit
139      */
140     public final LengthUnit getLengthUnit()
141     {
142         return this.lengthUnit;
143     }
144 
145     /**
146      * @return electricalCurrentUnit
147      */
148     public final ElectricalCurrentUnit getElectricalCurrentUnit()
149     {
150         return this.electricalCurrentUnit;
151     }
152 
153     /**
154      * @return timeUnit
155      */
156     public final TimeUnit getTimeUnit()
157     {
158         return this.timeUnit;
159     }
160 
161     /** {@inheritDoc} */
162     @Override
163     public final ElectricalResistanceUnit getStandardUnit()
164     {
165         return OHM;
166     }
167 
168     /** {@inheritDoc} */
169     @Override
170     public final String getSICoefficientsString()
171     {
172         return "kg.m2.s-3.A-2";
173     }
174 
175 }