001/*
002 * Copyright 2005-2014 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 * 
008 * http://www.osedu.org/licenses/ECL-2.0
009 * 
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.coeus.sys.api.model;
017
018import java.math.BigDecimal;
019
020/**
021 * This class is a wrapper around {@link java.math.BigDecimal}. It exposes the only the
022 * needed functionality of {@link java.math.BigDecimal}, uses a standard
023 * {@link java.math.RoundingMode} of {@link java.math.RoundingMode#HALF_UP}
024 * and uses a standard SCALE of 3.
025 *
026 * This class is, like {@link java.math.BigDecimal}, immutable; even methods which
027 * might be expected to change the value actually just return a new instance
028 * with the new value.
029 */
030public final class ScaleThreeDecimal extends AbstractDecimal<ScaleThreeDecimal> {
031
032    private static final long serialVersionUID = -1132481837308782665L;
033    
034    public static final int SCALE = 3;
035
036    public static final ScaleThreeDecimal ZERO = new ScaleThreeDecimal(0.000);
037    public static final ScaleThreeDecimal ONE_HUNDRED = new ScaleThreeDecimal(100);
038
039    /**
040     * This constructor should never be called except during JAXB unmarshalling.
041     */
042    private ScaleThreeDecimal() {
043        super();
044    }
045
046    public ScaleThreeDecimal(String value) {
047        super(value, SCALE);
048    }
049
050    public ScaleThreeDecimal(int value) {
051        super(value, SCALE);
052    }
053
054    public ScaleThreeDecimal(double value) {
055        super(value, SCALE);
056    }
057
058    public ScaleThreeDecimal(BigDecimal value) {
059        super(value, SCALE);
060    }
061
062    private ScaleThreeDecimal(String value, int scale) {
063        super(value, scale);
064    }
065
066    private ScaleThreeDecimal(int value, int scale) {
067        super(value, scale);
068    }
069
070    private ScaleThreeDecimal(double value, int scale) {
071        super(value, scale);
072    }
073
074    private ScaleThreeDecimal(BigDecimal value, int scale) {
075        super(value, scale);
076    }
077
078    @Override
079    protected ScaleThreeDecimal newInstance(int value) {
080        return new ScaleThreeDecimal(value);
081    }
082
083    @Override
084    protected ScaleThreeDecimal newInstance(BigDecimal value, int scale) {
085        return new ScaleThreeDecimal(value, scale);
086    }
087
088    @Override
089    protected ScaleThreeDecimal zero() {
090        return ZERO;
091    }
092
093    @Override
094    protected ScaleThreeDecimal oneHundred() {return ONE_HUNDRED; }
095}