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-2018 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: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, 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 the unit of mass for the electrical resistance unit, e.g., kilogram
92       * @param lengthUnit the unit of length for the electrical resistance unit, e.g., meter
93       * @param electricalCurrentUnit the unit of electrical current for the electrical resistance unit, e.g., Ampere
94       * @param durationUnit the unit of time for the electrical resistance unit, e.g., second
95       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
96       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
97       *            otherwise the abbreviation itself
98       * @param unitSystem the unit system, e.g. SI or Imperial
99       * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
100      */
101     @SuppressWarnings("checkstyle:parameternumber")
102     private ElectricalResistanceUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
103             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String nameOrNameKey,
104             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
105     {
106         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, OHM,
107                 massUnit.getScaleFactor() * lengthUnit.getScaleFactor()
108                         * lengthUnit.getScaleFactor() / (electricalCurrentUnit.getScaleFactor()
109                                 * electricalCurrentUnit.getScaleFactor() * Math.pow(durationUnit.getScaleFactor(), 3.0)),
110                 standardUnit);
111         this.massUnit = massUnit;
112         this.lengthUnit = lengthUnit;
113         this.electricalCurrentUnit = electricalCurrentUnit;
114         this.durationUnit = durationUnit;
115     }
116 
117     /**
118      * Define a user-defined ElectricalResistanceUnit based on its constituent base units, e.g. an Ohm = km.m^2/A^2.s^3.
119      * @param massUnit the unit of mass for the electrical resistance unit, e.g., kilogram
120      * @param lengthUnit the unit of length for the electrical resistance unit, e.g., meter
121      * @param electricalCurrentUnit the unit of electrical current for the electrical resistance unit, e.g., Ampere
122      * @param durationUnit the unit of time for the electrical resistance unit, e.g., second
123      * @param name the long name of the unit
124      * @param abbreviation the abbreviation of the unit
125      * @param unitSystem the unit system, e.g. SI or Imperial
126      */
127     public ElectricalResistanceUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
128             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String name,
129             final String abbreviation, final UnitSystem unitSystem)
130     {
131         this(massUnit, lengthUnit, electricalCurrentUnit, durationUnit, name, abbreviation, unitSystem, false);
132     }
133 
134     /**
135      * Define an ElectricalResistanceUnit based on an electrical potential unit and an electrical current unit, e.g. Ohm = V/A.
136      * @param electricalPotentialUnit the unit of electrical potential difference for the electrical resistance unit, e.g., Volt
137      * @param electricalCurrentUnit the unit of electrical current for the electrical resistance unit, e.g., Ampere
138      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
139      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
140      *            otherwise the abbreviation itself
141      * @param unitSystem the unit system, e.g. SI or Imperial
142      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
143      */
144     private ElectricalResistanceUnit(final ElectricalPotentialUnit electricalPotentialUnit,
145             final ElectricalCurrentUnit electricalCurrentUnit, final String nameOrNameKey,
146             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
147     {
148         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, OHM,
149                 electricalPotentialUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor(), standardUnit);
150         this.massUnit = electricalPotentialUnit.getMassUnit();
151         this.lengthUnit = electricalPotentialUnit.getLengthUnit();
152         this.electricalCurrentUnit = electricalCurrentUnit;
153         this.durationUnit = electricalPotentialUnit.getDurationUnit();
154     }
155 
156     /**
157      * Define a user-defined ElectricalResistanceUnit based on an electrical potential unit and an electrical current unit, e.g.
158      * Ohm = V/A.
159      * @param electricalPotentialUnit the unit of electrical potential difference for the electrical resistance unit, e.g., Volt
160      * @param electricalCurrentUnit the unit of electrical current for the electrical resistance unit, e.g., Ampere
161      * @param name the long name of the unit
162      * @param abbreviation the abbreviation of the unit
163      * @param unitSystem the unit system, e.g. SI or Imperial
164      */
165     public ElectricalResistanceUnit(final ElectricalPotentialUnit electricalPotentialUnit,
166             final ElectricalCurrentUnit electricalCurrentUnit, final String name, final String abbreviation,
167             final UnitSystem unitSystem)
168     {
169         this(electricalPotentialUnit, electricalCurrentUnit, name, abbreviation, unitSystem, false);
170     }
171 
172     /**
173      * Build a ElectricalResistanceUnit with a conversion factor to another ElectricalResistanceUnit.
174      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
175      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
176      *            otherwise the abbreviation itself
177      * @param unitSystem the unit system, e.g. SI or Imperial
178      * @param referenceUnit the unit to convert to
179      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
180      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
181      */
182     private ElectricalResistanceUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
183             final UnitSystem unitSystem, final ElectricalResistanceUnit referenceUnit, final double scaleFactorToReferenceUnit,
184             final boolean standardUnit)
185     {
186         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
187                 standardUnit);
188         this.massUnit = referenceUnit.getMassUnit();
189         this.lengthUnit = referenceUnit.getLengthUnit();
190         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
191         this.durationUnit = referenceUnit.getDurationUnit();
192     }
193 
194     /**
195      * Build a user-defined ElectricalResistanceUnit with a conversion factor to another ElectricalResistanceUnit.
196      * @param name the long name of the unit
197      * @param abbreviation the abbreviation of the unit
198      * @param unitSystem the unit system, e.g. SI or Imperial
199      * @param referenceUnit the unit to convert to
200      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
201      */
202     public ElectricalResistanceUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
203             final ElectricalResistanceUnit referenceUnit, final double scaleFactorToReferenceUnit)
204     {
205         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
206     }
207 
208     /**
209      * @return massUnit
210      */
211     public final MassUnit getMassUnit()
212     {
213         return this.massUnit;
214     }
215 
216     /**
217      * @return lengthUnit
218      */
219     public final LengthUnit getLengthUnit()
220     {
221         return this.lengthUnit;
222     }
223 
224     /**
225      * @return electricalCurrentUnit
226      */
227     public final ElectricalCurrentUnit getElectricalCurrentUnit()
228     {
229         return this.electricalCurrentUnit;
230     }
231 
232     /**
233      * @return durationUnit
234      */
235     public final DurationUnit getDurationUnit()
236     {
237         return this.durationUnit;
238     }
239 
240     /** {@inheritDoc} */
241     @Override
242     public final ElectricalResistanceUnit getStandardUnit()
243     {
244         return OHM;
245     }
246 
247     /** {@inheritDoc} */
248     @Override
249     public final String getSICoefficientsString()
250     {
251         return "kgm2/s3A2";
252     }
253 
254 }