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 potential (voltage).
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 ElectricalPotentialUnit extends LinearUnit<ElectricalPotentialUnit>
20  {
21      /** */
22      private static final long serialVersionUID = 20140607L;
23  
24      /** the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram. */
25      private final MassUnit massUnit;
26  
27      /** the unit of length for the electrical potential difference (voltage) unit, e.g., meters. */
28      private final LengthUnit lengthUnit;
29  
30      /** the unit of electrical current for the electrical potential difference (voltage) unit, e.g., Ampere. */
31      private final ElectricalCurrentUnit electricalCurrentUnit;
32  
33      /** the unit of time for the electrical potential difference (voltage) unit, e.g., second. */
34      private final DurationUnit durationUnit;
35  
36      /** The SI unit for electrical potential is Volt. */
37      public static final ElectricalPotentialUnit SI;
38  
39      /** Volt. */
40      public static final ElectricalPotentialUnit VOLT;
41  
42      /** nanovolt. */
43      public static final ElectricalPotentialUnit NANOVOLT;
44  
45      /** microvolt. */
46      public static final ElectricalPotentialUnit MICROVOLT;
47  
48      /** millivolt. */
49      public static final ElectricalPotentialUnit MILLIVOLT;
50  
51      /** kilovolt. */
52      public static final ElectricalPotentialUnit KILOVOLT;
53  
54      /** megavolt. */
55      public static final ElectricalPotentialUnit MEGAVOLT;
56  
57      /** gigavolt. */
58      public static final ElectricalPotentialUnit GIGAVOLT;
59  
60      /** statvolt. */
61      public static final ElectricalPotentialUnit STATVOLT;
62  
63      /** abvolt. */
64      public static final ElectricalPotentialUnit ABVOLT;
65  
66      static
67      {
68          SI = new ElectricalPotentialUnit(MassUnit.KILOGRAM, LengthUnit.METER, ElectricalCurrentUnit.AMPERE, DurationUnit.SECOND,
69                  "ElectricalPotentialUnit.volt", "ElectricalPotentialUnit.V", SI_DERIVED, true);
70          VOLT = SI;
71          NANOVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.nanovolt", "ElectricalPotentialUnit.nV", SI_DERIVED,
72                  VOLT, 1.0E-9, true);
73          MICROVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.microvolt", "ElectricalPotentialUnit.muV", SI_DERIVED,
74                  VOLT, 1.0E-6, true);
75          MILLIVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.millivolt", "ElectricalPotentialUnit.mV", SI_DERIVED,
76                  VOLT, 0.001, true);
77          KILOVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.kilovolt", "ElectricalPotentialUnit.kV", SI_DERIVED,
78                  VOLT, 1000.0, true);
79          MEGAVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.megavolt", "ElectricalPotentialUnit.MV", SI_DERIVED,
80                  VOLT, 1.0E6, true);
81          GIGAVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.gigavolt", "ElectricalPotentialUnit.GV", SI_DERIVED,
82                  VOLT, 1.0E9, true);
83          STATVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.statvolt", "ElectricalPotentialUnit.statV", CGS_ESU,
84                  VOLT, 299.792458, true);
85          ABVOLT = new ElectricalPotentialUnit("ElectricalPotentialUnit.abvolt", "ElectricalPotentialUnit.abV", CGS_EMU, VOLT,
86                  1.0E-8, true);
87      }
88  
89      /**
90       * Define an ElectricalPotentialUnit based on its constituent base units, e.g. a V = km.m^2/A.s^3.
91       * @param massUnit the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram
92       * @param lengthUnit the unit of length for the electrical potential difference (voltage) unit, e.g., meter
93       * @param electricalCurrentUnit the unit of electrical current for the electrical potential difference (voltage) unit, e.g.,
94       *            Ampere
95       * @param durationUnit the unit of time for the electrical potential difference (voltage) unit, e.g., second
96       * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
97       * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
98       *            otherwise the abbreviation itself
99       * @param unitSystem the unit system, e.g. SI or Imperial
100      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
101      */
102     @SuppressWarnings("checkstyle:parameternumber")
103     private ElectricalPotentialUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
104             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String nameOrNameKey,
105             final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem, final boolean standardUnit)
106     {
107         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, VOLT,
108                 massUnit.getScaleFactor() * lengthUnit.getScaleFactor() * lengthUnit.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 ElectricalPotentialUnit based on its constituent base units, e.g. a V = km.m^2/A.s^3.
119      * @param massUnit the unit of mass for the electrical potential difference (voltage) unit, e.g., kilogram
120      * @param lengthUnit the unit of length for the electrical potential difference (voltage) unit, e.g., meter
121      * @param electricalCurrentUnit the unit of electrical current for the electrical potential difference (voltage) unit, e.g.,
122      *            Ampere
123      * @param durationUnit the unit of time for the electrical potential difference (voltage) unit, e.g., second
124      * @param name the long name of the unit
125      * @param abbreviation the abbreviation of the unit
126      * @param unitSystem the unit system, e.g. SI or Imperial
127      */
128     public ElectricalPotentialUnit(final MassUnit massUnit, final LengthUnit lengthUnit,
129             final ElectricalCurrentUnit electricalCurrentUnit, final DurationUnit durationUnit, final String name,
130             final String abbreviation, final UnitSystem unitSystem)
131     {
132         this(massUnit, lengthUnit, electricalCurrentUnit, durationUnit, name, abbreviation, unitSystem, false);
133     }
134 
135     /**
136      * Build an ElectricalPotentialUnit based on power divided by current (V=W/A).
137      * @param powerUnit the unit of power for the electrical potential difference (voltage) unit, e.g., Watt
138      * @param electricalCurrentUnit the unit of electrical current for the electrical potential difference (voltage) unit, e.g.,
139      *            Ampere
140      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
141      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
142      *            otherwise the abbreviation itself
143      * @param unitSystem the unit system, e.g. SI or Imperial
144      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
145      */
146     private ElectricalPotentialUnit(final PowerUnit powerUnit, final ElectricalCurrentUnit electricalCurrentUnit,
147             final String nameOrNameKey, final String abbreviationOrAbbreviationKey, final UnitSystem unitSystem,
148             final boolean standardUnit)
149     {
150         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, VOLT,
151                 powerUnit.getScaleFactor() / electricalCurrentUnit.getScaleFactor(), standardUnit);
152         this.massUnit = powerUnit.getMassUnit();
153         this.lengthUnit = powerUnit.getLengthUnit();
154         this.electricalCurrentUnit = electricalCurrentUnit;
155         this.durationUnit = powerUnit.getDurationUnit();
156     }
157 
158     /**
159      * Build a user-defined ElectricalPotentialUnit based on power divided by current (V=W/A).
160      * @param powerUnit the unit of power for the electrical potential difference (voltage) unit, e.g., Watt
161      * @param electricalCurrentUnit the unit of electrical current for the electrical potential difference (voltage) unit, e.g.,
162      *            Ampere
163      * @param name the long name of the unit
164      * @param abbreviation the abbreviation of the unit
165      * @param unitSystem the unit system, e.g. SI or Imperial
166      */
167     public ElectricalPotentialUnit(final PowerUnit powerUnit, final ElectricalCurrentUnit electricalCurrentUnit,
168             final String name, final String abbreviation, final UnitSystem unitSystem)
169     {
170         this(powerUnit, electricalCurrentUnit, name, abbreviation, unitSystem, false);
171     }
172 
173     /**
174      * Build an ElectricalPotentialUnit with a conversion factor to another ElectricalPotentialUnit, e.g. a kV = 1000 V.
175      * @param nameOrNameKey if standardUnit: the key to the locale file for the long name of the unit, otherwise the name itself
176      * @param abbreviationOrAbbreviationKey if standardUnit: the key to the locale file for the abbreviation of the unit,
177      *            otherwise the abbreviation itself
178      * @param unitSystem the unit system, e.g. SI or Imperial
179      * @param referenceUnit the unit to convert to
180      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
181      * @param standardUnit indicates whether it is a standard unit with a definition in the locale, or a user-defined unit
182      */
183     private ElectricalPotentialUnit(final String nameOrNameKey, final String abbreviationOrAbbreviationKey,
184             final UnitSystem unitSystem, final ElectricalPotentialUnit referenceUnit, final double scaleFactorToReferenceUnit,
185             final boolean standardUnit)
186     {
187         super(nameOrNameKey, abbreviationOrAbbreviationKey, unitSystem, referenceUnit, scaleFactorToReferenceUnit,
188                 standardUnit);
189         this.massUnit = referenceUnit.getMassUnit();
190         this.lengthUnit = referenceUnit.getLengthUnit();
191         this.electricalCurrentUnit = referenceUnit.getElectricalCurrentUnit();
192         this.durationUnit = referenceUnit.getDurationUnit();
193     }
194 
195     /**
196      * Build a user-defined ElectricalPotentialUnit with a conversion factor to another ElectricalPotentialUnit.
197      * @param name the long name of the unit
198      * @param abbreviation the abbreviation of the unit
199      * @param unitSystem the unit system, e.g. SI or Imperial
200      * @param referenceUnit the unit to convert to
201      * @param scaleFactorToReferenceUnit multiply a value in this unit by the factor to convert to the given reference unit
202      */
203     public ElectricalPotentialUnit(final String name, final String abbreviation, final UnitSystem unitSystem,
204             final ElectricalPotentialUnit referenceUnit, final double scaleFactorToReferenceUnit)
205     {
206         this(name, abbreviation, unitSystem, referenceUnit, scaleFactorToReferenceUnit, false);
207     }
208 
209     /**
210      * @return massUnit
211      */
212     public final MassUnit getMassUnit()
213     {
214         return this.massUnit;
215     }
216 
217     /**
218      * @return lengthUnit
219      */
220     public final LengthUnit getLengthUnit()
221     {
222         return this.lengthUnit;
223     }
224 
225     /**
226      * @return electricalCurrentUnit
227      */
228     public final ElectricalCurrentUnit getElectricalCurrentUnit()
229     {
230         return this.electricalCurrentUnit;
231     }
232 
233     /**
234      * @return durationUnit
235      */
236     public final DurationUnit getDurationUnit()
237     {
238         return this.durationUnit;
239     }
240 
241     /** {@inheritDoc} */
242     @Override
243     public final ElectricalPotentialUnit getStandardUnit()
244     {
245         return VOLT;
246     }
247 
248     /** {@inheritDoc} */
249     @Override
250     public final String getSICoefficientsString()
251     {
252         return "kgm2/s3A";
253     }
254 
255 }