001/**
002 * CharacterArrayCursor.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.awt.Cursor;
022import java.math.BigDecimal;
023import java.math.BigInteger;
024
025import net.sf.jaccumulator.ConcurrencyStrategy;
026import net.sf.jaccumulator.lex.To;
027import net.sf.jaccumulator.primitives.SealedPrimitive;
028import net.sf.jaccumulator.reals.SealedReal;
029import net.sf.jaccumulator.scalars.SealedScalar;
030
031/**
032 * A {@code char} fixed array {@link Cursor}
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 CharacterArrayCursor
039    extends
040        AbstractCharacterPrimitive<CharacterArrayCursor>
041{
042    private static final long serialVersionUID = 8393932560099520535L;
043
044    private final int _theKey;
045    private final char[] _theSuperstructure;
046
047    public CharacterArrayCursor()
048    {
049        this(new char[0]);
050    }
051
052    public CharacterArrayCursor( final char[] aSuperstructure )
053    {
054        this(aSuperstructure, 0);
055    }
056
057    public CharacterArrayCursor( final char[] aSuperstructure, final int aKey )
058    {
059        this._theSuperstructure = aSuperstructure;
060        this._theKey = aKey;
061    }
062
063    @Override
064    public final CharacterArrayCursor and( final char aValue )
065        throws UnsupportedOperationException,
066            IllegalArgumentException,
067            ArithmeticException
068    {
069        this._theSuperstructure[this._theKey] &= aValue;
070        return this;
071    }
072
073    @Override
074    public final char charPostDecrement()
075        throws UnsupportedOperationException,
076            ArithmeticException,
077            IllegalArgumentException
078    {
079        return this._theSuperstructure[this._theKey]--;
080    }
081
082    @Override
083    public final char charPostIncrement()
084        throws UnsupportedOperationException,
085            ArithmeticException,
086            IllegalArgumentException
087    {
088        return this._theSuperstructure[this._theKey]++;
089    }
090
091    @Override
092    public final char charValue()
093    {
094        return this._theSuperstructure[this._theKey];
095    }
096
097    @Override
098    public final CharacterArrayCursor copy()
099    {
100        return new CharacterArrayCursor(this._theSuperstructure, this._theKey);
101    }
102
103    /**
104     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
105     * type, using the same source domain, but keyed using the value specified
106     * 
107     * @param aKey
108     *        a new cursor
109     * @return a copy (clone) of this cursor initialized using same source
110     *         domain and the specified key
111     */
112    @Override
113    public final CharacterArrayCursor copyUsing( final BigDecimal aKey )
114    {
115        return this.copyUsing(aKey.intValue());
116    }
117
118    /**
119     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
120     * type, using the same source domain, but keyed using the value specified
121     * 
122     * @param aKey
123     *        a new cursor
124     * @return a copy (clone) of this cursor initialized using same source
125     *         domain and the specified key
126     */
127    @Override
128    public final CharacterArrayCursor copyUsing( final BigInteger aKey )
129    {
130        return this.copyUsing(aKey.intValue());
131    }
132
133    /**
134     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
135     * type, using the same source domain, but keyed using the value specified
136     * 
137     * @param aKey
138     *        a new cursor
139     * @return a copy (clone) of this cursor initialized using same source
140     *         domain and the specified key
141     */
142    @Override
143    public final CharacterArrayCursor copyUsing( final boolean aKey )
144    {
145        return this.copyUsing(To.intValue(aKey));
146    }
147
148    /**
149     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
150     * type, using the same source domain, but keyed using the value specified
151     * 
152     * @param aKey
153     *        a new cursor
154     * @return a copy (clone) of this cursor initialized using same source
155     *         domain and the specified key
156     */
157    @Override
158    public final CharacterArrayCursor copyUsing( final byte aKey )
159    {
160        return this.copyUsing((int)aKey);
161    }
162
163    /**
164     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
165     * type, using the same source domain, but keyed using the value specified
166     * 
167     * @param aKey
168     *        a new cursor
169     * @return a copy (clone) of this cursor initialized using same source
170     *         domain and the specified key
171     */
172    @Override
173    public final CharacterArrayCursor copyUsing( final char aKey )
174    {
175        return this.copyUsing((int)aKey);
176    }
177
178    /**
179     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
180     * type, using the same source domain, but keyed using the value specified
181     * 
182     * @param aKey
183     *        a new cursor
184     * @return a copy (clone) of this cursor initialized using same source
185     *         domain and the specified key
186     */
187    @Override
188    public final CharacterArrayCursor copyUsing( final double aKey )
189    {
190        return this.copyUsing((int)aKey);
191    }
192
193    /**
194     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
195     * type, using the same source domain, but keyed using the value specified
196     * 
197     * @param aKey
198     *        a new cursor
199     * @return a copy (clone) of this cursor initialized using same source
200     *         domain and the specified key
201     */
202    @Override
203    public final CharacterArrayCursor copyUsing( final float aKey )
204    {
205        return this.copyUsing((int)aKey);
206    }
207
208    /**
209     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
210     * type, using the same source domain, but keyed using the value specified
211     * 
212     * @param aKey
213     *        a new cursor
214     * @return a copy (clone) of this cursor initialized using same source
215     *         domain and the specified key
216     */
217    @Override
218    public final CharacterArrayCursor copyUsing( final int aKey )
219    {
220        return new CharacterArrayCursor(this._theSuperstructure, aKey);
221    }
222
223    /**
224     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
225     * type, using the same source domain, but keyed using the value specified
226     * 
227     * @param aKey
228     *        a new cursor
229     * @return a copy (clone) of this cursor initialized using same source
230     *         domain and the specified key
231     */
232    @Override
233    public final CharacterArrayCursor copyUsing( final long aKey )
234    {
235        return this.copyUsing((int)aKey);
236    }
237
238    /**
239     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
240     * type, using the same source domain, but keyed using the value specified
241     * 
242     * @param aKey
243     *        a new cursor
244     * @return a copy (clone) of this cursor initialized using same source
245     *         domain and the specified key
246     */
247    @Override
248    public final CharacterArrayCursor copyUsing( final short aKey )
249    {
250        return this.copyUsing((int)aKey);
251    }
252
253    /**
254     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
255     * type, using the same source domain, but keyed using the value specified
256     * 
257     * @param aKey
258     *        a new cursor
259     * @return a copy (clone) of this cursor initialized using same source
260     *         domain and the specified key
261     */
262    @Override
263    public final CharacterArrayCursor copyUsingPrimitive(
264        final SealedPrimitive<?> aKey )
265    {
266        return this.copyUsing(aKey.intValue());
267    }
268
269    /**
270     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
271     * type, using the same source domain, but keyed using the value specified
272     * 
273     * @param aKey
274     *        a new cursor
275     * @return a copy (clone) of this cursor initialized using same source
276     *         domain and the specified key
277     */
278    @Override
279    public final CharacterArrayCursor copyUsingReal( final SealedReal<?> aKey )
280    {
281        return this.copyUsing(aKey.intValue());
282    }
283
284    /**
285     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
286     * type, using the same source domain, but keyed using the value specified
287     * 
288     * @param aKey
289     *        a new cursor
290     * @return a copy (clone) of this cursor initialized using same source
291     *         domain and the specified key
292     */
293    @Override
294    public final CharacterArrayCursor copyUsingScalar(
295        final SealedScalar<?> aKey )
296    {
297        return this.copyUsing(aKey.intValue());
298    }
299
300    /**
301     * Using this {@link Cursor} as a factory, produce a new Cursor of the same
302     * type, using the same source domain, but keyed using the value specified
303     * 
304     * @param aKey
305     *        a new cursor
306     * @return a copy (clone) of this cursor initialized using same source
307     *         domain and the specified key
308     */
309    @Override
310    public final CharacterArrayCursor copyUsingText( final CharSequence aKey )
311    {
312        return super.copyUsingText(aKey);
313    }
314
315    @Override
316    public final CharacterArrayCursor decrement()
317        throws UnsupportedOperationException,
318            ArithmeticException,
319            IllegalArgumentException
320    {
321        --this._theSuperstructure[this._theKey];
322        return this;
323    }
324
325    @Override
326    public final CharacterArrayCursor difference( final char aValue )
327        throws UnsupportedOperationException,
328            IllegalArgumentException,
329            ArithmeticException
330    {
331        this._theSuperstructure[this._theKey] -= aValue;
332        return this;
333    }
334
335    @Override
336    public final ConcurrencyStrategy getConcurrency()
337    {
338        return ConcurrencyStrategy.SEQUENTIAL;
339    }
340
341    @Override
342    public final CharacterArrayCursor increment()
343        throws UnsupportedOperationException,
344            ArithmeticException,
345            IllegalArgumentException
346    {
347        ++this._theSuperstructure[this._theKey];
348        return this;
349    }
350
351    @Override
352    public final CharacterArrayCursor mod( final char aValue )
353        throws UnsupportedOperationException,
354            IllegalArgumentException,
355            ArithmeticException
356    {
357        this._theSuperstructure[this._theKey] %= aValue;
358        return this;
359    }
360
361    @Override
362    public final CharacterArrayCursor not()
363        throws UnsupportedOperationException,
364            IllegalArgumentException,
365            ArithmeticException
366    {
367        this._theSuperstructure[this._theKey] ^= Character.MAX_VALUE;
368        return this;
369    }
370
371    @Override
372    public final CharacterArrayCursor or( final char aValue )
373        throws UnsupportedOperationException,
374            IllegalArgumentException,
375            ArithmeticException
376    {
377        this._theSuperstructure[this._theKey] |= aValue;
378        return this;
379    }
380
381    @Override
382    public final CharacterArrayCursor product( final char aValue )
383        throws UnsupportedOperationException,
384            IllegalArgumentException,
385            ArithmeticException
386    {
387        this._theSuperstructure[this._theKey] *= aValue;
388        return this;
389    }
390
391    @Override
392    public final CharacterArrayCursor quotient( final char aValue )
393        throws UnsupportedOperationException,
394            IllegalArgumentException,
395            ArithmeticException
396    {
397        this._theSuperstructure[this._theKey] /= aValue;
398        return this;
399    }
400
401    @Override
402    public final CharacterArrayCursor setScalar( final char aValue )
403        throws UnsupportedOperationException,
404            IllegalArgumentException,
405            ArithmeticException
406    {
407        this._theSuperstructure[this._theKey] = aValue;
408        return this;
409    }
410
411    @Override
412    public final CharacterArrayCursor shiftLeft( final int count )
413        throws UnsupportedOperationException,
414            IllegalArgumentException,
415            ArithmeticException
416    {
417        this._theSuperstructure[this._theKey] <<= count;
418        return this;
419    }
420
421    @Override
422    public final CharacterArrayCursor shiftRight( final int count )
423        throws UnsupportedOperationException,
424            IllegalArgumentException,
425            ArithmeticException
426    {
427        this._theSuperstructure[this._theKey] >>= count;
428        return this;
429    }
430
431    @Override
432    public final CharacterArrayCursor shiftRightExtendZero( final int count )
433        throws UnsupportedOperationException,
434            IllegalArgumentException,
435            ArithmeticException
436    {
437        this._theSuperstructure[this._theKey] >>>= count;
438        return this;
439    }
440
441    @Override
442    public final CharacterArrayCursor sum( final char aValue )
443        throws UnsupportedOperationException,
444            IllegalArgumentException,
445            ArithmeticException
446    {
447        this._theSuperstructure[this._theKey] += aValue;
448        return this;
449    }
450
451    @Override
452    public final CharacterArrayCursor xor( final char aValue )
453        throws UnsupportedOperationException,
454            IllegalArgumentException,
455            ArithmeticException
456    {
457        this._theSuperstructure[this._theKey] ^= aValue;
458        return this;
459    }
460}