001/**
002 * DoublePrimitive.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"); you may not
007 * use this file except in compliance with the License. You may obtain a copy of
008 * 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, WITHOUT
014 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
015 * License for the specific language governing permissions and limitations under
016 * the License.
017 */
018
019package net.sf.jaccumulator.doubles;
020
021import java.math.BigDecimal;
022import java.math.BigInteger;
023
024import net.sf.jaccumulator.ConcurrencyStrategy;
025import net.sf.jaccumulator.lex.To;
026import net.sf.jaccumulator.primitives.Primitive;
027import net.sf.jaccumulator.scalars.SealedScalar;
028
029/**
030 * A {@code double} precision {@link Primitive primitive} implementation
031 * 
032 * @since JAccumulator 4.0
033 * @author Nicole Tedesco (<a
034 *         href="mailto:Nicole@NicoleTedesco.com">Nicole@NicoleTedesco.com</a>)
035 */
036public final class DoublePrimitive
037    extends
038        AbstractDoublePrimitive<DoublePrimitive>
039{
040    private static final long serialVersionUID = -2919177388413795954L;
041
042    private double _theValue;
043
044    public DoublePrimitive()
045    {
046        super();
047        this._theValue = 0.0D;
048    }
049
050    public DoublePrimitive( final BigDecimal aValue )
051    {
052        this(aValue.doubleValue());
053    }
054
055    public DoublePrimitive( final BigInteger aValue )
056    {
057        this(aValue.doubleValue());
058    }
059
060    public DoublePrimitive( final boolean aValue )
061    {
062        this(To.doubleValue(aValue));
063    }
064
065    public DoublePrimitive( final byte aValue )
066    {
067        this((double)aValue);
068    }
069
070    public DoublePrimitive( final char aValue )
071    {
072        this((double)aValue);
073    }
074
075    public DoublePrimitive( final double aValue )
076    {
077        super();
078        this._theValue = aValue;
079    }
080
081    public DoublePrimitive( final float aValue )
082    {
083        this((double)aValue);
084    }
085
086    public DoublePrimitive( final int aValue )
087    {
088        this((double)aValue);
089    }
090
091    public DoublePrimitive( final long aValue )
092    {
093        this((double)aValue);
094    }
095
096    public DoublePrimitive( final SealedScalar<?> aValue )
097    {
098        this(aValue.doubleValue());
099    }
100
101    public DoublePrimitive( final short aValue )
102    {
103        this((double)aValue);
104    }
105
106    public DoublePrimitive( final String aValue )
107    {
108        this();
109        To.SCALAR.reactToText(aValue, this);
110    }
111
112    @Override
113    public final DoublePrimitive copy()
114    {
115        return new DoublePrimitive(this._theValue);
116    }
117
118    @Override
119    public final DoublePrimitive copyUsing( final double aValue )
120    {
121        return new DoublePrimitive(aValue);
122    }
123
124    @Override
125    public final DoublePrimitive decrement()
126        throws UnsupportedOperationException,
127            ArithmeticException,
128            IllegalArgumentException
129    {
130        --this._theValue;
131        return this;
132    }
133
134    @Override
135    public final DoublePrimitive difference( final double aValue )
136        throws UnsupportedOperationException,
137            IllegalArgumentException,
138            ArithmeticException
139    {
140        this._theValue -= aValue;
141        return this;
142    }
143
144    @Override
145    public final double doublePostDecrement()
146        throws UnsupportedOperationException,
147            ArithmeticException,
148            IllegalArgumentException
149    {
150        return this._theValue--;
151    }
152
153    @Override
154    public final double doublePostIncrement()
155        throws UnsupportedOperationException,
156            ArithmeticException,
157            IllegalArgumentException
158    {
159        return this._theValue++;
160    }
161
162    @Override
163    public final double doubleValue()
164    {
165        return this._theValue;
166    }
167
168    @Override
169    public final ConcurrencyStrategy getConcurrency()
170    {
171        return ConcurrencyStrategy.SEQUENTIAL;
172    }
173
174    @Override
175    public final DoublePrimitive increment()
176        throws UnsupportedOperationException,
177            ArithmeticException,
178            IllegalArgumentException
179    {
180        ++this._theValue;
181        return this;
182    }
183
184    @Override
185    public final DoublePrimitive mod( final double aValue )
186        throws UnsupportedOperationException,
187            IllegalArgumentException,
188            ArithmeticException
189    {
190        this._theValue %= aValue;
191        return this;
192    }
193
194    @Override
195    public final DoublePrimitive product( final double aValue )
196        throws UnsupportedOperationException,
197            IllegalArgumentException,
198            ArithmeticException
199    {
200        this._theValue *= aValue;
201        return this;
202    }
203
204    @Override
205    public final DoublePrimitive quotient( final double aValue )
206        throws UnsupportedOperationException,
207            IllegalArgumentException,
208            ArithmeticException
209    {
210        this._theValue /= aValue;
211        return this;
212    }
213
214    @Override
215    public final DoublePrimitive setScalar( final double aValue )
216        throws UnsupportedOperationException,
217            IllegalArgumentException,
218            ArithmeticException
219    {
220        this._theValue = aValue;
221        return this;
222    }
223
224    @Override
225    public final DoublePrimitive sum( final double aValue )
226        throws UnsupportedOperationException,
227            IllegalArgumentException,
228            ArithmeticException
229    {
230        this._theValue += aValue;
231        return this;
232    }
233}