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