View Javadoc
1   package org.djunits.unit.system;
2   
3   import java.util.Objects;
4   
5   import org.djutils.exceptions.Throw;
6   
7   /**
8    * Systems of Units such as SI, including SI-derived; cgs (centimeter-gram-second).
9    * <p>
10   * Copyright (c) 2015-2026 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
11   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>
12   * @author Alexander Verbraeck
13   */
14  public class UnitSystem
15  {
16      /** CGS: centimeter-gram-second system. */
17      public static final UnitSystem CGS = new UnitSystem("CGS", "centimeter-gram-second system");
18  
19      /** CGS ESU: centimeter-gram-second system, electrostatic units. */
20      public static final UnitSystem CGS_ESU = new UnitSystem("CGS-ESU", "centimeter-gram-second system, electrostatic units");
21  
22      /** CGS_EMU: centimeter-gram-second system, electromagnetic units. */
23      public static final UnitSystem CGS_EMU = new UnitSystem("CGS-EMU", "centimeter-gram-second system, electromagnetic units");
24  
25      /** Imperial system. */
26      public static final UnitSystem IMPERIAL = new UnitSystem("Imperial", "Imperial system");
27  
28      /** MTS: meter-tonne-second system. */
29      public static final UnitSystem MTS = new UnitSystem("MTS", "meter-tonne-second system");
30  
31      /** Other (or no) system. */
32      public static final UnitSystem OTHER = new UnitSystem("Other", "other system");
33  
34      /** SI units, accepted for use in addition to SI. */
35      public static final UnitSystem SI_ACCEPTED = new UnitSystem("SI-accepted", "International System of Units (Accepted Unit)");
36  
37      /** SI base units: temperature, time, length, mass, luminous intensity, amount of substance and electric current. */
38      public static final UnitSystem SI_BASE = new UnitSystem("SI", "International System of Units (Base Unit)");
39  
40      /** SI derived units, by combining SI-base elements (and quantifiers such as milli or kilo). */
41      public static final UnitSystem SI_DERIVED = new UnitSystem("SI-derived", "International System of Units (Derived Unit)");
42  
43      /** US additions to the Imperial system. */
44      public static final UnitSystem US_CUSTOMARY = new UnitSystem("US-customary", "US customary system");
45  
46      /** AU: Atomic Unit system. */
47      public static final UnitSystem AU = new UnitSystem("AU", "Atomic Unit system");
48  
49      /** The abbreviation of the unit system, such as cgs. */
50      private final String id;
51  
52      /** The name of the unit system, such as centimeter-gram-second. */
53      private final String name;
54  
55      /**
56       * Construct a new UnitSystem.
57       * @param id the abbreviation of the unit system, such as cgs
58       * @param name the name of the unit system, such as centimeter-gram-second
59       */
60      public UnitSystem(final String id, final String name)
61      {
62          Throw.whenNull(id, "id");
63          Throw.whenNull(name, "name");
64          Throw.when(id.strip().length() == 0, IllegalArgumentException.class, "id cannot be empty");
65          Throw.when(name.strip().length() == 0, IllegalArgumentException.class, "name cannot be empty");
66          this.id = id.strip();
67          this.name = name.strip();
68      }
69  
70      /**
71       * Retrieve the name of this UnitSystem.
72       * @return the name of this UnitSystem, e.g. centimeter-gram-second
73       */
74      public final String getName()
75      {
76          return this.name;
77      }
78  
79      /**
80       * Retrieve the abbreviation of this UnitSystem.
81       * @return the abbreviation of this UnitSystem, e.g., CGS.cgs
82       */
83      public final String getId()
84      {
85          return this.id;
86      }
87  
88      @Override
89      public int hashCode()
90      {
91          return Objects.hash(this.id, this.name);
92      }
93  
94      @Override
95      @SuppressWarnings("checkstyle:needbraces")
96      public boolean equals(final Object obj)
97      {
98          if (this == obj)
99              return true;
100         if (obj == null)
101             return false;
102         if (getClass() != obj.getClass())
103             return false;
104         UnitSystem other = (UnitSystem) obj;
105         return Objects.equals(this.id, other.id) && Objects.equals(this.name, other.name);
106     }
107 
108     @Override
109     public String toString()
110     {
111         return "UnitSystem [id=" + this.id + ", name=" + this.name + "]";
112     }
113 
114 }