001/**
002 * AbstractPrimitive.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.primitives;
020
021import java.util.NoSuchElementException;
022
023import net.sf.jaccumulator.Domain;
024import net.sf.jaccumulator.reals.AbstractReal;
025import net.sf.jaccumulator.scalars.NumericPrecision;
026import net.sf.jaccumulator.scalars.Scalar;
027
028/**
029 * Common read and write behavior for primitive representations
030 * 
031 * @param <PRIMITIVE>
032 *        this primitive type (used to facilitate operation chaining on write
033 *        operations)
034 * @since JAccumulator 4.0
035 * @author Nicole Tedesco (<a
036 *         href="mailto:Nicole@NicoleTedesco.com">Nicole@NicoleTedesco.com</a>)
037 */
038public abstract class AbstractPrimitive<PRIMITIVE extends Primitive<PRIMITIVE>>
039    extends
040        AbstractReal<PRIMITIVE>
041    implements
042        Primitive<PRIMITIVE>
043{
044    private static final long serialVersionUID = 3678613864393976081L;
045
046    public AbstractPrimitive()
047    {
048        super();
049    }
050
051    public AbstractPrimitive(
052        final Domain aDomain,
053        final NumericPrecision aPrecision )
054    {
055        super(aDomain, aPrecision);
056    }
057
058    public AbstractPrimitive( final NumericPrecision aPrecision )
059    {
060        super(Domain.REAL, aPrecision);
061    }
062
063    @Override
064    public final PRIMITIVE andOfPrimitive( final SealedPrimitive<?> aValue )
065        throws UnsupportedOperationException,
066            IllegalArgumentException,
067            ArithmeticException
068    {
069        return this.andOfReal(aValue);
070    }
071
072    @Override
073    public final PRIMITIVE angleWithPrimitive( final SealedPrimitive<?> aValue )
074        throws UnsupportedOperationException,
075            IllegalArgumentException,
076            ArithmeticException
077    {
078        return this.angleWith(aValue.doubleValue());
079    }
080
081    @Override
082    public int compareToText( final CharSequence text )
083    {
084        return this.toString().compareTo(text.toString());
085    }
086
087    @Override
088    public final PRIMITIVE differenceOfPrimitive(
089        final SealedPrimitive<?> aValue )
090        throws UnsupportedOperationException,
091            IllegalArgumentException,
092            ArithmeticException
093    {
094        return this.differenceOfReal(aValue);
095    }
096
097    @Override
098    public final PRIMITIVE hypotenuseWithPrimitive(
099        final SealedPrimitive<?> aValue )
100        throws UnsupportedOperationException,
101            IllegalArgumentException,
102            ArithmeticException
103    {
104        return this.hypotenuseWithReal(aValue);
105    }
106
107    @Override
108    public <P extends Primitive<?>> P inducePrimitiveMaximum( final P aTarget )
109        throws NullPointerException,
110            NoSuchElementException,
111            UnsupportedOperationException,
112            IllegalStateException
113    {
114        this.induceRealMaximum(aTarget);
115        return aTarget;
116    }
117
118    @Override
119    public <P extends Primitive<?>> P inducePrimitiveMinimum( final P aTarget )
120        throws NullPointerException,
121            NoSuchElementException,
122            UnsupportedOperationException,
123            IllegalStateException
124    {
125        this.induceRealMinimum(aTarget);
126        return aTarget;
127    }
128
129    @Override
130    public <SCALAR extends Scalar<?>> SCALAR induceTextSize(
131        final SCALAR aTarget )
132        throws NullPointerException,
133            NoSuchElementException,
134            UnsupportedOperationException,
135            IllegalStateException
136    {
137        aTarget.setScalar(this.toString().length());
138        return aTarget;
139    }
140
141    @Override
142    public final PRIMITIVE modOfPrimitive( final SealedPrimitive<?> aValue )
143        throws UnsupportedOperationException,
144            IllegalArgumentException,
145            ArithmeticException
146    {
147        return this.modOfReal(aValue);
148    }
149
150    @Override
151    public final PRIMITIVE orOfPrimitive( final SealedPrimitive<?> aValue )
152        throws UnsupportedOperationException,
153            IllegalArgumentException,
154            ArithmeticException
155    {
156        return this.orOfReal(aValue);
157    }
158
159    @Override
160    public final PRIMITIVE powerOfPrimitive( final SealedPrimitive<?> aValue )
161        throws UnsupportedOperationException,
162            IllegalArgumentException,
163            ArithmeticException
164    {
165        return this.powerOfScalar(aValue);
166    }
167
168    @Override
169    public final PRIMITIVE productOfPrimitive( final SealedPrimitive<?> aValue )
170        throws UnsupportedOperationException,
171            IllegalArgumentException,
172            ArithmeticException
173    {
174        return this.productOfReal(aValue);
175    }
176
177    @Override
178    public final PRIMITIVE quotientOfPrimitive( final SealedPrimitive<?> aValue )
179        throws UnsupportedOperationException,
180            IllegalArgumentException,
181            ArithmeticException
182    {
183        return this.quotientOfReal(aValue);
184    }
185
186    @Override
187    public final PRIMITIVE sumOfPrimitive( final SealedPrimitive<?> aValue )
188        throws UnsupportedOperationException,
189            IllegalArgumentException,
190            ArithmeticException
191    {
192        return this.sumOfReal(aValue);
193    }
194
195    @Override
196    public Primitive<?> toPrimitive()
197    {
198        return this.copy();
199    }
200
201    @Override
202    public final PRIMITIVE xorOfPrimitive( final SealedPrimitive<?> aValue )
203        throws UnsupportedOperationException,
204            IllegalArgumentException,
205            ArithmeticException
206    {
207        return this.xorOfReal(aValue);
208    }
209}