View Javadoc
1   package org.djunits.demo.examples;
2   
3   import java.util.Map;
4   
5   import org.djunits.unit.AreaUnit;
6   import org.djunits.unit.ElectricalChargeUnit;
7   import org.djunits.unit.FrequencyUnit;
8   import org.djunits.unit.LengthUnit;
9   import org.djunits.unit.LinearDensityUnit;
10  import org.djunits.unit.MassUnit;
11  import org.djunits.unit.Unit;
12  import org.djunits.unit.VolumeUnit;
13  
14  /**
15   * UnitPrefix.java.
16   * <p>
17   * Copyright (c) 2019-2020 Delft University of Technology, PO Box 5, 2600 AA, Delft, the Netherlands. All rights reserved. <br>
18   * BSD-style license. See <a href="https://djunits.org/docs/license.html">DJUNITS License</a>.
19   * <p>
20   * @author <a href="https://www.tudelft.nl/averbraeck" target="_blank">Alexander Verbraeck</a>
21   */
22  public final class UnitPrefix
23  {
24      /** */
25      private UnitPrefix()
26      {
27          // utility class
28      }
29  
30      /**
31   * @param args String[]; not used
32  
33       */
34      public static void main(final String[] args)
35      {
36          print(LengthUnit.BASE.getUnitsByAbbreviation());
37          print(AreaUnit.BASE.getUnitsByAbbreviation());
38          print(VolumeUnit.BASE.getUnitsByAbbreviation());
39          print(ElectricalChargeUnit.BASE.getUnitsByAbbreviation());
40          print(MassUnit.BASE.getUnitsByAbbreviation());
41          print(LinearDensityUnit.BASE.getUnitsByAbbreviation());
42          print(FrequencyUnit.BASE.getUnitsByAbbreviation());
43      }
44  
45      /**
46   * @param unitMap Map&lt;String,? extends Unit&lt;?&gt;&gt;; the map to print
47  
48       */
49      private static void print(final Map<String, ? extends Unit<?>> unitMap)
50      {
51          System.out.println();
52          for (String ab : unitMap.keySet())
53          {
54              Unit<?> unit = unitMap.get(ab);
55              System.out.println((ab + "        ").substring(0, 8) + (unit.getId() + "        ").substring(0, 8) + "  "
56                      + (unit.getName() + "                        ").substring(0, 24) + "   "
57                      + unit.getScale().toStandardUnit(1.0) + "   " + unit.getAbbreviations());
58          }
59      }
60  }