001/**
002 * UnlimitedDecimalPrimitive.java
003 *
004 * Copyright (c) 2004-2012, Nicole C. Tedesco.  All rights reserved.
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at:
009 *
010 * http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018
019package net.sf.jaccumulator.unlimiteds;
020
021import java.math.BigDecimal;
022import java.math.BigInteger;
023
024import net.sf.jaccumulator.ConcurrencyStrategy;
025import net.sf.jaccumulator.primitives.SealedPrimitive;
026import net.sf.jaccumulator.reals.Real;
027import net.sf.jaccumulator.reals.SealedReal;
028import net.sf.jaccumulator.scalars.SealedScalar;
029
030/**
031 * An unlimited {@link BigInteger integer} precision {@link Real real}
032 * implementation
033 *
034 * @since JAccumulator 4.0
035 * @author Nicole Tedesco (<a
036 *         href="mailto:Nicole@NicoleTedesco.com">Nicole@NicoleTedesco.com</a>)
037 */
038public final class UnlimitedDecimalPrimitive
039    extends
040        AbstractUnlimitedDecimalPrimitive<UnlimitedDecimalPrimitive>
041{
042    private static final long serialVersionUID = 3437138851995481029L;
043
044    private BigDecimal        _theValue;
045
046    public UnlimitedDecimalPrimitive()
047    {
048        super();
049    }
050
051    public UnlimitedDecimalPrimitive( final BigDecimal aValue )
052    {
053        super(aValue);
054    }
055
056    public UnlimitedDecimalPrimitive( final BigInteger aValue )
057    {
058        super(aValue);
059    }
060
061    public UnlimitedDecimalPrimitive( final boolean aValue )
062    {
063        super(aValue);
064    }
065
066    public UnlimitedDecimalPrimitive( final byte aValue )
067    {
068        super(aValue);
069    }
070
071    public UnlimitedDecimalPrimitive( final char aValue )
072    {
073        super(aValue);
074    }
075
076    public UnlimitedDecimalPrimitive( final double aValue )
077    {
078        super(aValue);
079    }
080
081    public UnlimitedDecimalPrimitive( final float aValue )
082    {
083        super(aValue);
084    }
085
086    public UnlimitedDecimalPrimitive( final int aValue )
087    {
088        super(aValue);
089    }
090
091    public UnlimitedDecimalPrimitive( final long aValue )
092    {
093        super(aValue);
094    }
095
096    public UnlimitedDecimalPrimitive(
097        final SealedUnlimitedDecimalValue aValue )
098    {
099        super(aValue);
100    }
101
102    public UnlimitedDecimalPrimitive( final short aValue )
103    {
104        super(aValue);
105    }
106
107    public UnlimitedDecimalPrimitive( final String aValue )
108    {
109        super(aValue);
110    }
111
112    @Override
113    public final UnlimitedDecimalPrimitive copy() {
114        return new UnlimitedDecimalPrimitive(this.toUnlimitedDecimal());
115    }
116
117    @Override
118    public final UnlimitedDecimalPrimitive copyUsing( final BigDecimal aValue )
119    {
120        return new UnlimitedDecimalPrimitive(aValue);
121    }
122
123    @Override
124    public final UnlimitedDecimalPrimitive copyUsing( final BigInteger aValue )
125    {
126        return new UnlimitedDecimalPrimitive(aValue);
127    }
128
129    @Override
130    public final UnlimitedDecimalPrimitive copyUsing( final boolean aValue ) {
131        return new UnlimitedDecimalPrimitive(aValue);
132    }
133
134    @Override
135    public final UnlimitedDecimalPrimitive copyUsing( final byte aValue ) {
136        return new UnlimitedDecimalPrimitive(aValue);
137    }
138
139    @Override
140    public final UnlimitedDecimalPrimitive copyUsing( final char aValue ) {
141        return new UnlimitedDecimalPrimitive(aValue);
142    }
143
144    @Override
145    public final UnlimitedDecimalPrimitive copyUsing( final double aValue ) {
146        return new UnlimitedDecimalPrimitive(aValue);
147    }
148
149    @Override
150    public final UnlimitedDecimalPrimitive copyUsing( final float aValue ) {
151        return new UnlimitedDecimalPrimitive(aValue);
152    }
153
154    @Override
155    public final UnlimitedDecimalPrimitive copyUsing( final int aValue ) {
156        return new UnlimitedDecimalPrimitive(aValue);
157    }
158
159    @Override
160    public final UnlimitedDecimalPrimitive copyUsing( final long aValue ) {
161        return new UnlimitedDecimalPrimitive(aValue);
162    }
163
164    @Override
165    public final UnlimitedDecimalPrimitive copyUsing( final short aValue ) {
166        return new UnlimitedDecimalPrimitive(aValue);
167    }
168
169    @Override
170    public final UnlimitedDecimalPrimitive copyUsingPrimitive(
171        final SealedPrimitive<?> aValue )
172    {
173        return new UnlimitedDecimalPrimitive(aValue);
174    }
175
176    @Override
177    public final UnlimitedDecimalPrimitive copyUsingReal(
178        final SealedReal<?> aValue )
179    {
180        return new UnlimitedDecimalPrimitive(aValue);
181    }
182
183    @Override
184    public final UnlimitedDecimalPrimitive copyUsingScalar(
185        final SealedScalar<?> aValue )
186    {
187        return new UnlimitedDecimalPrimitive(aValue.doubleValue());
188    }
189
190    @Override
191    public final UnlimitedDecimalPrimitive copyUsingText(
192        final CharSequence aValue )
193    {
194        return new UnlimitedDecimalPrimitive(aValue.toString());
195    }
196
197    @Override
198    public final UnlimitedDecimalPrimitive decrement()
199        throws UnsupportedOperationException,
200            ArithmeticException,
201            IllegalArgumentException
202    {
203        this._theValue = this._theValue.subtract(BigDecimal.ONE);
204        return this;
205    }
206
207    @Override
208    public final ConcurrencyStrategy getConcurrency() {
209        return ConcurrencyStrategy.SEQUENTIAL;
210    }
211
212    @Override
213    public final UnlimitedDecimalPrimitive increment()
214        throws UnsupportedOperationException,
215            ArithmeticException,
216            IllegalArgumentException
217    {
218        this._theValue = this._theValue.add(BigDecimal.ONE);
219        return this;
220    }
221
222    @Override
223    public final UnlimitedDecimalPrimitive setReal(
224        final BigDecimal aValue )
225        throws UnsupportedOperationException,
226            IllegalArgumentException,
227            ArithmeticException,
228            NullPointerException
229    {
230        this._theValue = aValue;
231        return this;
232    }
233
234    @Override
235    public final BigDecimal toUnlimitedDecimal() {
236        return this._theValue;
237    }
238}