View Javadoc
1   /*
2    * Kuali Coeus, a comprehensive research administration system for higher education.
3    * 
4    * Copyright 2005-2015 Kuali, Inc.
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.coeus.sys.api.model;
20  
21  import java.math.BigDecimal;
22  
23  /**
24   * This class is a wrapper around {@link java.math.BigDecimal}. It exposes the only the
25   * needed functionality of {@link java.math.BigDecimal}, uses a standard
26   * {@link java.math.RoundingMode} of {@link java.math.RoundingMode#HALF_UP}
27   * and uses a standard SCALE of 3.
28   *
29   * This class is, like {@link java.math.BigDecimal}, immutable; even methods which
30   * might be expected to change the value actually just return a new instance
31   * with the new value.
32   */
33  public final class ScaleThreeDecimal extends AbstractDecimal<ScaleThreeDecimal> {
34  
35      private static final long serialVersionUID = -1132481837308782665L;
36      
37      public static final int SCALE = 3;
38  
39      public static final ScaleThreeDecimal ZERO = new ScaleThreeDecimal(0.000);
40      public static final ScaleThreeDecimal ONE_HUNDRED = new ScaleThreeDecimal(100);
41  
42      /**
43       * This constructor should never be called except during JAXB unmarshalling.
44       */
45      private ScaleThreeDecimal() {
46          super();
47      }
48  
49      public ScaleThreeDecimal(String value) {
50          super(value, SCALE);
51      }
52  
53      public ScaleThreeDecimal(int value) {
54          super(value, SCALE);
55      }
56  
57      public ScaleThreeDecimal(double value) {
58          super(value, SCALE);
59      }
60  
61      public ScaleThreeDecimal(BigDecimal value) {
62          super(value, SCALE);
63      }
64  
65      private ScaleThreeDecimal(String value, int scale) {
66          super(value, scale);
67      }
68  
69      private ScaleThreeDecimal(int value, int scale) {
70          super(value, scale);
71      }
72  
73      private ScaleThreeDecimal(double value, int scale) {
74          super(value, scale);
75      }
76  
77      private ScaleThreeDecimal(BigDecimal value, int scale) {
78          super(value, scale);
79      }
80  
81      @Override
82      protected ScaleThreeDecimal newInstance(int value) {
83          return new ScaleThreeDecimal(value);
84      }
85  
86      @Override
87      protected ScaleThreeDecimal newInstance(BigDecimal value, int scale) {
88          return new ScaleThreeDecimal(value, scale);
89      }
90  
91      @Override
92      protected ScaleThreeDecimal zero() {
93          return ZERO;
94      }
95  
96      @Override
97      protected ScaleThreeDecimal oneHundred() {return ONE_HUNDRED; }
98  }