001/**
002 * AbstractAccumulator.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;
020
021import java.math.BigDecimal;
022import java.math.BigInteger;
023
024import net.sf.jaccumulator.primitives.Constant;
025import net.sf.jaccumulator.primitives.Primitive;
026import net.sf.jaccumulator.primitives.SealedPrimitive;
027import net.sf.jaccumulator.reals.SealedReal;
028import net.sf.jaccumulator.scalars.SealedScalar;
029import net.sf.jupperware.association.AssociativeList;
030import net.sf.jupperware.association.RandomAccessAssociativeList;
031
032/**
033 * Common behavior for Accumulators with read-only {@link Primitive}
034 * {@link #getTarget() targets} and read-only {@link #members() relationship}
035 * collections
036 * 
037 * @param <ACCUMULATOR>
038 *        this {@link Accumulator} type
039 * @since JAccumulator 4.0
040 * @author Nicole Tedesco (<a
041 *         href="mailto:nicole@tedesco.name">nicole@tedesco.name</a>)
042 */
043public abstract class AbstractConstantAccumulator<ACCUMULATOR extends AbstractConstantAccumulator<ACCUMULATOR>>
044    extends
045        AbstractStickyTarget<ACCUMULATOR>
046{
047    private static final long serialVersionUID = -2537818512832816382L;
048
049    public static final AssociativeList<Accumulator<?>,Accumulator<?>> EMPTY_MEMBERS = new RandomAccessAssociativeList<Accumulator<?>,Accumulator<?>>().toUnmodifiableInstance();
050
051    public AbstractConstantAccumulator()
052    {
053        super(Constant.ZERO, EMPTY_MEMBERS);
054    }
055
056    public AbstractConstantAccumulator( final Accumulator<?> anAccumulator )
057    {
058        super(Constant.toConstant(anAccumulator.getTarget()),
059            anAccumulator.members().toUnmodifiableInstance());
060    }
061
062    public AbstractConstantAccumulator( final BigDecimal aTarget )
063    {
064        this(Constant.valueOf(aTarget));
065    }
066
067    public AbstractConstantAccumulator( final BigInteger aTarget )
068    {
069        this(Constant.valueOf(aTarget));
070    }
071
072    public AbstractConstantAccumulator( final boolean aTarget )
073    {
074        this(Constant.valueOf(aTarget));
075    }
076
077    public AbstractConstantAccumulator( final byte aTarget )
078    {
079        this(Constant.valueOf(aTarget));
080    }
081
082    public AbstractConstantAccumulator( final char aTarget )
083    {
084        this(Constant.valueOf(aTarget));
085    }
086
087    public AbstractConstantAccumulator( final double aTarget )
088    {
089        this(Constant.valueOf(aTarget));
090    }
091
092    public AbstractConstantAccumulator( final Enum<?> aTarget )
093    {
094        this(Constant.valueOf(aTarget));
095    }
096
097    public AbstractConstantAccumulator( final float aTarget )
098    {
099        this(Constant.valueOf(aTarget));
100    }
101
102    public AbstractConstantAccumulator( final int aTarget )
103    {
104        this(Constant.valueOf(aTarget));
105    }
106
107    public AbstractConstantAccumulator( final long aTarget )
108    {
109        this(Constant.valueOf(aTarget));
110    }
111
112    public AbstractConstantAccumulator( final Primitive<?> aTarget )
113    {
114        super(Constant.toConstant(aTarget), EMPTY_MEMBERS);
115    }
116
117    public AbstractConstantAccumulator(
118        final Primitive<?> aTarget,
119        final AssociativeList<Accumulator<?>,Accumulator<?>> members )
120    {
121        super(Constant.toConstant(aTarget), members.toUnmodifiableInstance());
122    }
123
124    public AbstractConstantAccumulator( final short aTarget )
125    {
126        this(Constant.valueOf(aTarget));
127    }
128
129    public AbstractConstantAccumulator( final String aTarget )
130    {
131        this(Constant.valueOfText(aTarget));
132    }
133
134    @Override
135    @SuppressWarnings( "unchecked" )
136    public final ACCUMULATOR copy()
137    {
138        return (ACCUMULATOR)this;
139    }
140
141    @Override
142    @SuppressWarnings( "unchecked" )
143    public final ACCUMULATOR copySharing( final Accumulator<?> anAccumulator )
144    {
145        return (ACCUMULATOR)this;
146    }
147
148    @Override
149    @SuppressWarnings( "unchecked" )
150    public final ACCUMULATOR copySharing(
151        final AssociativeList<Accumulator<?>,Accumulator<?>> members )
152    {
153        return (ACCUMULATOR)this;
154    }
155
156    @Override
157    @SuppressWarnings( "unchecked" )
158    public final ACCUMULATOR copySharing( final Primitive<?> aTarget )
159    {
160        return (ACCUMULATOR)this;
161    }
162
163    @Override
164    @SuppressWarnings( "unchecked" )
165    public final ACCUMULATOR copySharing(
166        final Primitive<?> aTarget,
167        final AssociativeList<Accumulator<?>,Accumulator<?>> members )
168    {
169        return (ACCUMULATOR)this;
170    }
171
172    @Override
173    @SuppressWarnings( "unchecked" )
174    public final ACCUMULATOR copyUsing( final BigDecimal aValue )
175    {
176        return (ACCUMULATOR)this;
177    }
178
179    @Override
180    @SuppressWarnings( "unchecked" )
181    public final ACCUMULATOR copyUsing( final BigInteger aValue )
182    {
183        return (ACCUMULATOR)this;
184    }
185
186    @Override
187    @SuppressWarnings( "unchecked" )
188    public final ACCUMULATOR copyUsing( final boolean aValue )
189    {
190        return (ACCUMULATOR)this;
191    }
192
193    @Override
194    @SuppressWarnings( "unchecked" )
195    public final ACCUMULATOR copyUsing( final byte aValue )
196    {
197        return (ACCUMULATOR)this;
198    }
199
200    @Override
201    @SuppressWarnings( "unchecked" )
202    public final ACCUMULATOR copyUsing( final char aValue )
203    {
204        return (ACCUMULATOR)this;
205    }
206
207    @Override
208    @SuppressWarnings( "unchecked" )
209    public final ACCUMULATOR copyUsing( final double aValue )
210    {
211        return (ACCUMULATOR)this;
212    }
213
214    @Override
215    @SuppressWarnings( "unchecked" )
216    public final ACCUMULATOR copyUsing( final float aValue )
217    {
218        return (ACCUMULATOR)this;
219    }
220
221    @Override
222    @SuppressWarnings( "unchecked" )
223    public final ACCUMULATOR copyUsing( final int aValue )
224    {
225        return (ACCUMULATOR)this;
226    }
227
228    @Override
229    @SuppressWarnings( "unchecked" )
230    public final ACCUMULATOR copyUsing( final long aValue )
231    {
232        return (ACCUMULATOR)this;
233    }
234
235    @Override
236    @SuppressWarnings( "unchecked" )
237    public final ACCUMULATOR copyUsing( final short aValue )
238    {
239        return (ACCUMULATOR)this;
240    }
241
242    @Override
243    @SuppressWarnings( "unchecked" )
244    public final ACCUMULATOR copyUsingAccumulator(
245        final SealedAccumulator<?> anAccumulator )
246    {
247        return (ACCUMULATOR)this;
248    }
249
250    @Override
251    @SuppressWarnings( "unchecked" )
252    public final ACCUMULATOR copyUsingPrimitive( final SealedPrimitive<?> aValue )
253    {
254        return (ACCUMULATOR)this;
255    }
256
257    @Override
258    @SuppressWarnings( "unchecked" )
259    public final ACCUMULATOR copyUsingReal( final SealedReal<?> aValue )
260    {
261        return (ACCUMULATOR)this;
262    }
263
264    @Override
265    @SuppressWarnings( "unchecked" )
266    public final ACCUMULATOR copyUsingScalar( final SealedScalar<?> aValue )
267    {
268        return (ACCUMULATOR)this;
269    }
270
271    @Override
272    @SuppressWarnings( "unchecked" )
273    public final ACCUMULATOR copyUsingText( final CharSequence aValue )
274    {
275        return (ACCUMULATOR)this;
276    }
277
278    @Override
279    public final boolean isConfigurable()
280    {
281        return false;
282    }
283
284    @Override
285    public final boolean isElastic()
286    {
287        return false;
288    }
289
290    @Override
291    public final boolean isExpandable()
292    {
293        return false;
294    }
295
296    @Override
297    public final boolean isReducible()
298    {
299        return false;
300    }
301}