View Javadoc
1   /*
2    * Oceanus: Java Utilities
3    * Copyright 2012-2026. Tony Washer
4    *
5    * Licensed under the Apache License, Version 2.0 (the "License"); you may not
6    * use this file except in compliance with the License.  You may obtain a copy
7    * of the License at
8    *
9    *   http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
14   * License for the specific language governing permissions and limitations under
15   * the License.
16   */
17  package io.github.tonywasher.joceanus.oceanus.decimal;
18  
19  /**
20   * Represents a Units object.
21   */
22  public class OceanusUnits
23          extends OceanusDecimal {
24      /**
25       * Standard number of decimals for Units.
26       */
27      protected static final int NUM_DECIMALS = 4;
28  
29      /**
30       * Construct a new Units.
31       */
32      public OceanusUnits() {
33          recordScale(NUM_DECIMALS);
34      }
35  
36      /**
37       * Construct a new Units by copying another units.
38       *
39       * @param pUnits the Units to copy
40       */
41      public OceanusUnits(final OceanusUnits pUnits) {
42          super(pUnits.unscaledValue(), pUnits.scale());
43      }
44  
45      /**
46       * Create the units from a byte array.
47       *
48       * @param pBuffer the buffer
49       */
50      public OceanusUnits(final byte[] pBuffer) {
51          super(pBuffer);
52      }
53  
54      /**
55       * Construct a new Units by setting the value explicitly.
56       *
57       * @param pValue the unscaled value
58       * @return the new Rate
59       */
60      public static OceanusUnits getWholeUnits(final long pValue) {
61          final OceanusUnits myUnits = new OceanusUnits();
62          myUnits.setValue(adjustDecimals(pValue, NUM_DECIMALS), NUM_DECIMALS);
63          return myUnits;
64      }
65  
66      /**
67       * Add units to the value.
68       *
69       * @param pValue The units to add to this one.
70       */
71      public void addUnits(final OceanusUnits pValue) {
72          /* Add the value */
73          super.addValue(pValue);
74      }
75  
76      /**
77       * Subtract units from the value.
78       *
79       * @param pValue The units to subtract from this one.
80       */
81      public void subtractUnits(final OceanusUnits pValue) {
82          /* Subtract the value */
83          super.subtractValue(pValue);
84      }
85  
86      @Override
87      public void addValue(final OceanusDecimal pValue) {
88          throw new UnsupportedOperationException();
89      }
90  
91      @Override
92      public void subtractValue(final OceanusDecimal pValue) {
93          throw new UnsupportedOperationException();
94      }
95  }