View Javadoc
1   package org.djunits.unit;
2   
3   import org.djunits.unit.unitsystem.UnitSystem;
4   
5   /**
6    * Helper class to create arbitrary SI units.
7    * <p>
8    * Copyright (c) 2015-2018 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
9    * BSD-style license. See <a href="http://djunits.org/docs/license.html">DJUNITS License</a>.
10   * <p>
11   * $LastChangedDate: 2018-01-28 03:17:44 +0100 (Sun, 28 Jan 2018) $, @version $Revision: 256 $, by $Author: averbraeck $,
12   * initial version Jun 15, 2014 <br>
13   * @author <a href="http://www.tbm.tudelft.nl/averbraeck">Alexander Verbraeck</a>
14   */
15  public class SIUnit extends Unit<SIUnit>
16  {
17      /** */
18      private static final long serialVersionUID = 20140615L;
19  
20      /**
21       * Create an arbitrary SI unit based on a coefficient string, such as m3/cd2.
22       * @param siCoefficientString String; textual description of the unit.
23       */
24      public SIUnit(final String siCoefficientString)
25      {
26          super(siCoefficientString, siCoefficientString, UnitSystem.SI_DERIVED, true);
27      }
28  
29      /**
30       * Create an arbitrary SI unit based on a coefficient string, such as m3/cd2.
31       * @param siCoefficientString String; textual description of the unit.
32       * @param standardUnit boolean; if true; the new unit is standard and there should be localization info; if false;
33       *            localization will not be available
34       */
35      public SIUnit(final String siCoefficientString, final boolean standardUnit)
36      {
37          super(siCoefficientString, siCoefficientString, UnitSystem.SI_DERIVED, standardUnit);
38      }
39  
40      /** {@inheritDoc} */
41      @Override
42      public final SIUnit getStandardUnit()
43      {
44          return this;
45      }
46  
47      /** {@inheritDoc} */
48      @Override
49      public final String getSICoefficientsString()
50      {
51          if (null == this.getAbbreviationKey())
52          {
53              return this.getAbbreviation().replace("SIUnit.", ""); // FIXME: this is horrible / PK
54              // We need a better way to determine if a unit is supposed to have localization information.
55          }
56          return this.getAbbreviationKey().replace("SIUnit.", "");
57      }
58  
59  }