001/**
002 * CharacterPrimitive.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.characters;
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 char} 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 CharacterPrimitive
037    extends
038        AbstractCharacterPrimitive<CharacterPrimitive>
039{
040    private static final long serialVersionUID = -5807433605150315421L;
041
042    private char _theValue;
043
044    public CharacterPrimitive()
045    {
046        this('\0');
047    }
048
049    public CharacterPrimitive( final BigDecimal aValue )
050    {
051        this((char)aValue.intValue());
052    }
053
054    public CharacterPrimitive( final BigInteger aValue )
055    {
056        this((char)aValue.intValue());
057    }
058
059    public CharacterPrimitive( final boolean aValue )
060    {
061        this(To.charValue(aValue));
062    }
063
064    public CharacterPrimitive( final byte aValue )
065    {
066        this((char)aValue);
067    }
068
069    public CharacterPrimitive( final char aValue )
070    {
071        super();
072        this._theValue = aValue;
073    }
074
075    public CharacterPrimitive( final double aValue )
076    {
077        this((char)aValue);
078    }
079
080    public CharacterPrimitive( final float aValue )
081    {
082        this((char)aValue);
083    }
084
085    public CharacterPrimitive( final int aValue )
086    {
087        this((char)aValue);
088    }
089
090    public CharacterPrimitive( final long aValue )
091    {
092        this((char)aValue);
093    }
094
095    public CharacterPrimitive( final SealedScalar<?> aValue )
096    {
097        this(aValue.charValue());
098    }
099
100    public CharacterPrimitive( final short aValue )
101    {
102        this((char)aValue);
103    }
104
105    public CharacterPrimitive( final String aValue )
106    {
107        this(firstChar(aValue));
108    }
109
110    @Override
111    public final CharacterPrimitive and( final char aValue )
112        throws UnsupportedOperationException,
113            IllegalArgumentException,
114            ArithmeticException
115    {
116        this._theValue &= aValue;
117        return this;
118    }
119
120    @Override
121    public final char charPostDecrement()
122        throws UnsupportedOperationException,
123            ArithmeticException,
124            IllegalArgumentException
125    {
126        return this._theValue--;
127    }
128
129    @Override
130    public final char charPostIncrement()
131        throws UnsupportedOperationException,
132            ArithmeticException,
133            IllegalArgumentException
134    {
135        return this._theValue++;
136    }
137
138    @Override
139    public final char charValue()
140    {
141        return this._theValue;
142    }
143
144    @Override
145    public final CharacterPrimitive copy()
146    {
147        return new CharacterPrimitive(this._theValue);
148    }
149
150    @Override
151    public final CharacterPrimitive copyUsing( final char aValue )
152    {
153        return new CharacterPrimitive(aValue);
154    }
155
156    @Override
157    public final CharacterPrimitive decrement()
158        throws UnsupportedOperationException,
159            ArithmeticException,
160            IllegalArgumentException
161    {
162        --this._theValue;
163        return this;
164    }
165
166    @Override
167    public final CharacterPrimitive difference( final char aValue )
168        throws UnsupportedOperationException,
169            IllegalArgumentException,
170            ArithmeticException
171    {
172        this._theValue -= aValue;
173        return this;
174    }
175
176    @Override
177    public final ConcurrencyStrategy getConcurrency()
178    {
179        return ConcurrencyStrategy.SEQUENTIAL;
180    }
181
182    @Override
183    public final CharacterPrimitive increment()
184        throws UnsupportedOperationException,
185            ArithmeticException,
186            IllegalArgumentException
187    {
188        ++this._theValue;
189        return this;
190    }
191
192    @Override
193    public final CharacterPrimitive mod( final char aValue )
194        throws UnsupportedOperationException,
195            IllegalArgumentException,
196            ArithmeticException
197    {
198        this._theValue %= aValue;
199        return this;
200    }
201
202    @Override
203    public final CharacterPrimitive not()
204        throws UnsupportedOperationException,
205            IllegalArgumentException,
206            ArithmeticException
207    {
208        this._theValue ^= Character.MAX_VALUE;
209        return this;
210    }
211
212    @Override
213    public final CharacterPrimitive or( final char aValue )
214        throws UnsupportedOperationException,
215            IllegalArgumentException,
216            ArithmeticException
217    {
218        this._theValue |= aValue;
219        return this;
220    }
221
222    @Override
223    public final CharacterPrimitive product( final char aValue )
224        throws UnsupportedOperationException,
225            IllegalArgumentException,
226            ArithmeticException
227    {
228        this._theValue *= aValue;
229        return this;
230    }
231
232    @Override
233    public final CharacterPrimitive quotient( final char aValue )
234        throws UnsupportedOperationException,
235            IllegalArgumentException,
236            ArithmeticException
237    {
238        this._theValue /= aValue;
239        return this;
240    }
241
242    @Override
243    public final CharacterPrimitive setScalar( final char aValue )
244        throws UnsupportedOperationException,
245            IllegalArgumentException,
246            ArithmeticException
247    {
248        this._theValue = aValue;
249        return this;
250    }
251
252    @Override
253    public final CharacterPrimitive shiftLeft( final int count )
254        throws UnsupportedOperationException,
255            IllegalArgumentException,
256            ArithmeticException
257    {
258        this._theValue <<= count;
259        return this;
260    }
261
262    @Override
263    public final CharacterPrimitive shiftRight( final int count )
264        throws UnsupportedOperationException,
265            IllegalArgumentException,
266            ArithmeticException
267    {
268        this._theValue >>= count;
269        return this;
270    }
271
272    @Override
273    public final CharacterPrimitive shiftRightExtendZero( final int count )
274        throws UnsupportedOperationException,
275            IllegalArgumentException,
276            ArithmeticException
277    {
278        this._theValue >>>= count;
279        return this;
280    }
281
282    @Override
283    public final CharacterPrimitive sum( final char aValue )
284        throws UnsupportedOperationException,
285            IllegalArgumentException,
286            ArithmeticException
287    {
288        this._theValue += aValue;
289        return this;
290    }
291
292    @Override
293    public final CharacterPrimitive xor( final char aValue )
294        throws UnsupportedOperationException,
295            IllegalArgumentException,
296            ArithmeticException
297    {
298        this._theValue ^= aValue;
299        return this;
300    }
301}