001/**
002 * UnlimitedIntegerPrimitive.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 UnlimitedIntegerPrimitive
039    extends
040        AbstractUnlimitedIntegerPrimitive<UnlimitedIntegerPrimitive>
041{
042    private static final long serialVersionUID = -4018651161871242783L;
043
044    private BigInteger        _theValue;
045
046    public UnlimitedIntegerPrimitive()
047    {
048        super();
049    }
050
051    public UnlimitedIntegerPrimitive( final BigDecimal aValue )
052    {
053        super(aValue);
054    }
055
056    public UnlimitedIntegerPrimitive( final BigInteger aValue )
057    {
058        super(aValue);
059    }
060
061    public UnlimitedIntegerPrimitive( final boolean aValue )
062    {
063        super(aValue);
064    }
065
066    public UnlimitedIntegerPrimitive( final byte aValue )
067    {
068        super(aValue);
069    }
070
071    public UnlimitedIntegerPrimitive( final char aValue )
072    {
073        super(aValue);
074    }
075
076    public UnlimitedIntegerPrimitive( final double aValue )
077    {
078        super(aValue);
079    }
080
081    public UnlimitedIntegerPrimitive( final float aValue )
082    {
083        super(aValue);
084    }
085
086    public UnlimitedIntegerPrimitive( final int aValue )
087    {
088        super(aValue);
089    }
090
091    public UnlimitedIntegerPrimitive( final long aValue )
092    {
093        super(aValue);
094    }
095
096    public UnlimitedIntegerPrimitive( final SealedPrimitive<?> aValue )
097    {
098        super(aValue);
099    }
100
101    public UnlimitedIntegerPrimitive( final SealedReal<?> aValue )
102    {
103        super(aValue);
104    }
105
106    public UnlimitedIntegerPrimitive( final short aValue )
107    {
108        super(aValue);
109    }
110
111    public UnlimitedIntegerPrimitive( final String aValue )
112    {
113        super(aValue);
114    }
115
116    @Override
117    public final UnlimitedIntegerPrimitive copy() {
118        return new UnlimitedIntegerPrimitive(this.toUnlimitedInteger());
119    }
120
121    @Override
122    public final UnlimitedIntegerPrimitive copyUsing( final BigDecimal aValue )
123    {
124        return new UnlimitedIntegerPrimitive(aValue);
125    }
126
127    @Override
128    public final UnlimitedIntegerPrimitive copyUsing( final BigInteger aValue )
129    {
130        return new UnlimitedIntegerPrimitive(aValue);
131    }
132
133    @Override
134    public final UnlimitedIntegerPrimitive copyUsing( final boolean aValue ) {
135        return new UnlimitedIntegerPrimitive(aValue);
136    }
137
138    @Override
139    public final UnlimitedIntegerPrimitive copyUsing( final byte aValue ) {
140        return new UnlimitedIntegerPrimitive(aValue);
141    }
142
143    @Override
144    public final UnlimitedIntegerPrimitive copyUsing( final char aValue ) {
145        return new UnlimitedIntegerPrimitive(aValue);
146    }
147
148    @Override
149    public final UnlimitedIntegerPrimitive copyUsing( final double aValue ) {
150        return new UnlimitedIntegerPrimitive(aValue);
151    }
152
153    @Override
154    public final UnlimitedIntegerPrimitive copyUsing( final float aValue ) {
155        return new UnlimitedIntegerPrimitive(aValue);
156    }
157
158    @Override
159    public final UnlimitedIntegerPrimitive copyUsing( final int aValue ) {
160        return new UnlimitedIntegerPrimitive(aValue);
161    }
162
163    @Override
164    public final UnlimitedIntegerPrimitive copyUsing( final long aValue ) {
165        return new UnlimitedIntegerPrimitive(aValue);
166    }
167
168    @Override
169    public final UnlimitedIntegerPrimitive copyUsing( final short aValue ) {
170        return new UnlimitedIntegerPrimitive(aValue);
171    }
172
173    @Override
174    public final UnlimitedIntegerPrimitive copyUsingPrimitive(
175        final SealedPrimitive<?> aValue )
176    {
177        return new UnlimitedIntegerPrimitive(aValue);
178    }
179
180    @Override
181    public final UnlimitedIntegerPrimitive copyUsingReal(
182        final SealedReal<?> aValue )
183    {
184        return new UnlimitedIntegerPrimitive(aValue);
185    }
186
187    @Override
188    public final UnlimitedIntegerPrimitive copyUsingScalar(
189        final SealedScalar<?> aValue )
190    {
191        return new UnlimitedIntegerPrimitive(aValue.doubleValue());
192    }
193
194    @Override
195    public final UnlimitedIntegerPrimitive copyUsingText(
196        final CharSequence aValue )
197    {
198        return new UnlimitedIntegerPrimitive(aValue.toString());
199    }
200
201    @Override
202    public final UnlimitedIntegerPrimitive decrement()
203        throws UnsupportedOperationException,
204            ArithmeticException,
205            IllegalArgumentException
206    {
207        this._theValue = this._theValue.subtract(BigInteger.ONE);
208        return this;
209    }
210
211    @Override
212    public final ConcurrencyStrategy getConcurrency() {
213        return ConcurrencyStrategy.SEQUENTIAL;
214    }
215
216    @Override
217    public final UnlimitedIntegerPrimitive increment()
218        throws UnsupportedOperationException,
219            ArithmeticException,
220            IllegalArgumentException
221    {
222        this._theValue = this._theValue.add(BigInteger.ONE);
223        return this;
224    }
225
226    @Override
227    public final UnlimitedIntegerPrimitive setReal(
228        final BigInteger aValue )
229        throws UnsupportedOperationException,
230            IllegalArgumentException,
231            ArithmeticException,
232            NullPointerException
233    {
234        this._theValue = aValue;
235        return this;
236    }
237
238    @Override
239    public final BigInteger toUnlimitedInteger() {
240        return this._theValue;
241    }
242}