1 package org.djunits.unit;
2
3 import org.djunits.unit.si.SIDimensions;
4 import org.djunits.unit.util.UnitException;
5
6
7
8
9
10
11
12
13
14 public class SIUnit extends Unit<SIUnit>
15 {
16
17 private static final long serialVersionUID = 20190829L;
18
19
20 public static SIUnit DIMLESS = SIUnit.of(SIDimensions.DIMLESS);
21
22 static
23 {
24
25 try
26 {
27 Class.forName("org.djunits.unit.util.UNITS");
28 }
29 catch (ClassNotFoundException exception)
30 {
31 exception.printStackTrace();
32 }
33 }
34
35
36
37
38
39
40
41 public static SIUnit of(final String siString) throws UnitException
42 {
43 return Unit.lookupOrCreateUnitWithSIDimensions(SIDimensions.of(siString));
44 }
45
46
47
48
49
50
51 public static SIUnit of(final SIDimensions siDimensions)
52 {
53 return Unit.lookupOrCreateUnitWithSIDimensions(siDimensions);
54 }
55
56 @Override
57 public String toString()
58 {
59 return getQuantity().getSiDimensions().toString(true, false);
60 }
61
62 @Override
63 @SuppressWarnings("checkstyle:designforextension")
64 public int hashCode()
65 {
66 return getQuantity().getSiDimensions().hashCode();
67 }
68
69 @Override
70 @SuppressWarnings({"checkstyle:designforextension", "checkstyle:needbraces"})
71 public boolean equals(final Object obj)
72 {
73 if (this == obj)
74 return true;
75 if (obj == null)
76 return false;
77 if (getClass() != obj.getClass())
78 return false;
79 SIUnit other = (SIUnit) obj;
80 if (!getQuantity().getSiDimensions().equals(other.getQuantity().getSiDimensions()))
81 return false;
82 return true;
83 }
84
85 }