View Javadoc
1   package org.djunits.unit;
2   
3   import static org.djunits.unit.unitsystem.UnitSystem.CGS_EMU;
4   import static org.djunits.unit.unitsystem.UnitSystem.CGS_ESU;
5   import static org.djunits.unit.unitsystem.UnitSystem.SI_DERIVED;
6   
7   import org.djunits.unit.unitsystem.UnitSystem;
8   
9   /**
10   * The units of electrical resistance.
11   * <p>
12   * Copyright (c) 2015-2019 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
13   * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
14   * <p>
15   * $LastChangedDate: 2019-01-18 00:35:01 +0100 (Fri, 18 Jan 2019) $, @version $Revision: 324 $, by $Author: averbraeck $,
16   * initial version May 15, 2014 <br>
17   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
18   */
19  public class ElectricalResistanceUnit extends LinearUnit<ElectricalResistanceUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** the unit of mass for the electrical resistance unit, e.g., kilogram. */
25      private final MassUnit massUnit;
26  
27      /** the unit of length for the electrical resistance unit, e.g., meters. */
28      private final LengthUnit lengthUnit;
29  
30      /** the unit of electrical current for the electrical resistance unit, e.g., Ampere. */
31      private final ElectricalCurrentUnit electricalCurrentUnit;
32  
33      /** the unit of time for the electrical resistance unit, e.g., second. */
34      private final DurationUnit durationUnit;
35  
36      /** The SI unit for electrical resistance is Ohm. */
37      public static final ElectricalResistanceUnit SI;
38  
39      /** Ohm. */
40      public static final ElectricalResistanceUnit OHM;
41  
42      /** nano-ohm. */
43      public static final ElectricalResistanceUnit NANOOHM;
44  
45      /** micro-ohm. */
46      public static final ElectricalResistanceUnit MICROOHM;
47  
48      /** milli-ohm. */
49      public static final ElectricalResistanceUnit MILLIOHM;
50  
51      /** kilo-ohm. */
52      public static final ElectricalResistanceUnit KILOOHM;
53  
54      /** mega-ohm. */
55      public static final ElectricalResistanceUnit MEGAOHM;
56  
57      /** giga-ohm. */
58      public static final ElectricalResistanceUnit GIGAOHM;
59  
60      /** ab-ohm. */
61      public static final ElectricalResistanceUnit ABOHM;
62  
63      /** stat-ohm. */
64      public static final ElectricalResistanceUnit STATOHM;
65  
66      static
67      {
68          SI = new ElectricalResistanceUnit(MassUnit.KILOGRAM, LengthUnit.METER, ElectricalCurrentUnit.AMPERE,
69                  DurationUnit.SECOND, "ElectricalResistanceUnit.ohm_(name)", "ElectricalResistanceUnit.ohm", SI_DERIVED, true);
70          OHM = SI;
71          NANOOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.nano_ohm", "ElectricalResistanceUnit.n_ohm",
72                  SI_DERIVED, OHM, 1.0E-9, true);
73          MICROOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.micro_ohm", "ElectricalResistanceUnit.mu_ohm",
74                  SI_DERIVED, OHM, 1.0E-6, true);
75          MILLIOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.milli_ohm", "ElectricalResistanceUnit.m_ohm",
76                  SI_DERIVED, OHM, 1.0E-3, true);
77          KILOOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.kilo_ohm", "ElectricalResistanceUnit.k_ohm",
78                  SI_DERIVED, OHM, 1.0E3, true);
79          MEGAOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.mega_ohm", "ElectricalResistanceUnit.M_ohm",
80                  SI_DERIVED, OHM, 1.0E06, true);
81          GIGAOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.giga_ohm", "ElectricalResistanceUnit.G_ohm",
82                  SI_DERIVED, OHM, 1.0E9, true);
83          ABOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.ab_ohm", "ElectricalResistanceUnit.a_ohm", CGS_EMU, OHM,
84                  1.0E-9, true);
85          STATOHM = new ElectricalResistanceUnit("ElectricalResistanceUnit.stat_ohm", "ElectricalResistanceUnit.st_ohm", CGS_ESU,
86                  OHM, 8.987551787E11, true);
87      }
88  
89      /**
90       * Define an ElectricalResistanceUnit based on its constituent base units, e.g. an Ohm = km.m^2/A^2.s^3.
91       * @param massUnit MassUnit; the unit of mass for the electrical resistance unit, e.g., kilogram
92       * @param lengthUnit LengthUnit; the unit of length for the electrical resistance unit, e.g., meter
93       * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
94       *            e.g., Ampere
95       * @param durationUnit DurationUnit; the unit of time for the electrical resistance unit, e.g., second
96       * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
97       *            name itself
98       * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
99       *            unit, otherwise the abbreviation itself
100      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
101      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
102      *            unit
103      */
104     @SuppressWarnings("checkstyle:parameternumber")
105     private ElectricalResistanceUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
106             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String nameOrNameKey,
107             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
108     {
109         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, OHM,
110                 massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
111                         * lengthUnit.getScaleFactor() / (electricalCurrentUnit.getScaleFactor()
112                                 * electricalCurrentUnit.getScaleFactor() * Math.pow(durationUnit.getScaleFactor(), 3.0)),
113                 standardUnit);
114         this.massUnit = massUnit;
115         this.lengthUnit = lengthUnit;
116         this.electricalCurrentUnit = electricalCurrentUnit;
117         this.durationUnit = durationUnit;
118     }
119 
120     /**
121      * Define a user-defined ElectricalResistanceUnit based on its constituent base units, e.g. an Ohm = km.m^2/A^2.s^3.
122      * @param massUnit MassUnit; the unit of mass for the electrical resistance unit, e.g., kilogram
123      * @param lengthUnit LengthUnit; the unit of length for the electrical resistance unit, e.g., meter
124      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
125      *            e.g., Ampere
126      * @param durationUnit DurationUnit; the unit of time for the electrical resistance unit, e.g., second
127      * @param name String; the long name of the unit
128      * @param abbreviation String; the abbreviation of the unit
129      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
130      */
131     public ElectricalResistanceUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
132             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String name,
133             final String abbreviation, final UnitSystem unitSystem)
134     {
135         this(massUnit, lengthUnit, electricalCurrentUnit, durationUnit, name, abbreviation, unitSystem, false);
136     }
137 
138     /**
139      * Define an ElectricalResistanceUnit based on an electrical potential unit and an electrical current unit, e.g. Ohm = V/A.
140      * @param electricalPotentialUnit ElectricalPotentialUnit; the unit of electrical potential difference for the electrical
141      *            resistance unit, e.g., Volt
142      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
143      *            e.g., Ampere
144      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
145      *            name itself
146      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
147      *            unit, otherwise the abbreviation itself
148      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
149      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
150      *            unit
151      */
152     private ElectricalResistanceUnit(final ElectricalPotentialUnit electricalPotentialUnit,
153             final ElectricalCurrentUnit electricalCurrentUnit, final String nameOrNameKey,
154             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
155     {
156         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, OHM,
157                 electricalPotentialUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor(), standardUnit);
158         this.massUnit = electricalPotentialUnit.getMassUnit();
159         this.lengthUnit = electricalPotentialUnit.getLengthUnit();
160         this.electricalCurrentUnit = electricalCurrentUnit;
161         this.durationUnit = electricalPotentialUnit.getDurationUnit();
162     }
163 
164     /**
165      * Define a user-defined ElectricalResistanceUnit based on an electrical potential unit and an electrical current unit, e.g.
166      * Ohm = V/A.
167      * @param electricalPotentialUnit ElectricalPotentialUnit; the unit of electrical potential difference for the electrical
168      *            resistance unit, e.g., Volt
169      * @param electricalCurrentUnit ElectricalCurrentUnit; the unit of electrical current for the electrical resistance unit,
170      *            e.g., Ampere
171      * @param name String; the long name of the unit
172      * @param abbreviation String; the abbreviation of the unit
173      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
174      */
175     public ElectricalResistanceUnit(final ElectricalPotentialUnit electricalPotentialUnit,
176             final ElectricalCurrentUnit electricalCurrentUnit, final String name, final String abbreviation,
177             final UnitSystem unitSystem)
178     {
179         this(electricalPotentialUnit, electricalCurrentUnit, name, abbreviation, unitSystem, false);
180     }
181 
182     /**
183      * Build a ElectricalResistanceUnit with a conversion factor to another ElectricalResistanceUnit.
184      * @param nameOrNameKey String; if standardUnit: the key to the locale file for the long name of the unit, otherwise the
185      *            name itself
186      * @param abbreviationOrAbbreviationKey String; if standardUnit: the key to the locale file for the abbreviation of the
187      *            unit, otherwise the abbreviation itself
188      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
189      * @param referenceUnit ElectricalResistanceUnit; the unit to convert to
190      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
191      *            unit
192      * @param standardUnit boolean; indicates whether it is a standard unit with a definition in the locale, or a user-defined
193      *            unit
194      */
195     private ElectricalResistanceUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
196             final UnitSystem unitSystem, final ElectricalResistanceUnit referenceUnit, final double scaleFactorToReferenceUnit,
197             final boolean standardUnit)
198     {
199         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
200                 standardUnit);
201         this.massUnit = referenceUnit.getMassUnit();
202         this.lengthUnit = referenceUnit.getLengthUnit();
203         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
204         this.durationUnit = referenceUnit.getDurationUnit();
205     }
206 
207     /**
208      * Build a user-defined ElectricalResistanceUnit with a conversion factor to another ElectricalResistanceUnit.
209      * @param name String; the long name of the unit
210      * @param abbreviation String; the abbreviation of the unit
211      * @param unitSystem UnitSystem; the unit system, e.g. SI or Imperial
212      * @param referenceUnit ElectricalResistanceUnit; the unit to convert to
213      * @param scaleFactorToReferenceUnit double; multiply a value in this unit by the factor to convert to the given reference
214      *            unit
215      */
216     public ElectricalResistanceUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
217             final ElectricalResistanceUnit referenceUnit, final double scaleFactorToReferenceUnit)
218     {
219         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
220     }
221 
222     /**
223      * @return massUnit
224      */
225     public final MassUnit getMassUnit()
226     {
227         return this.massUnit;
228     }
229 
230     /**
231      * @return lengthUnit
232      */
233     public final LengthUnit getLengthUnit()
234     {
235         return this.lengthUnit;
236     }
237 
238     /**
239      * @return electricalCurrentUnit
240      */
241     public final ElectricalCurrentUnit getElectricalCurrentUnit()
242     {
243         return this.electricalCurrentUnit;
244     }
245 
246     /**
247      * @return durationUnit
248      */
249     public final DurationUnit getDurationUnit()
250     {
251         return this.durationUnit;
252     }
253 
254     /** {@inheritDoc} */
255     @Override
256     public final ElectricalResistanceUnit getStandardUnit()
257     {
258         return OHM;
259     }
260 
261     /** {@inheritDoc} */
262     @Override
263     public final String getSICoefficientsString()
264     {
265         return "kgm2/s3A2";
266     }
267 
268 }