001/**
002 * SimpleAccumulator.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.booleans.BooleanPrimitive;
025import net.sf.jaccumulator.bytes.BytePrimitive;
026import net.sf.jaccumulator.characters.CharacterPrimitive;
027import net.sf.jaccumulator.doubles.DoublePrimitive;
028import net.sf.jaccumulator.floats.FloatPrimitive;
029import net.sf.jaccumulator.integers.EnumerationPrimitive;
030import net.sf.jaccumulator.integers.IntegerPrimitive;
031import net.sf.jaccumulator.longs.LongPrimitive;
032import net.sf.jaccumulator.primitives.Primitive;
033import net.sf.jaccumulator.shorts.ShortPrimitive;
034import net.sf.jaccumulator.texts.TextPrimitive;
035import net.sf.jaccumulator.unlimiteds.UnlimitedDecimalPrimitive;
036import net.sf.jaccumulator.unlimiteds.UnlimitedIntegerPrimitive;
037import net.sf.jupperware.association.AssociativeList;
038
039/**
040 * A simple Accumulator with an independent, replaceable {@link #getTarget()
041 * target} Primitive
042 * 
043 * @since JAccumulator 4.0
044 * @author Nicole Tedesco (<a
045 *         href="mailto:nicole@tedesco.name">nicole@tedesco.name</a>)
046 */
047public class SimpleAccumulator
048    extends
049        AbstractSimpleAccumulator<SimpleAccumulator>
050{
051    private static final long serialVersionUID = 3378116194511779442L;
052
053    public SimpleAccumulator()
054    {
055        super();
056    }
057
058    public SimpleAccumulator( final Accumulator<?> anAccumulator )
059    {
060        super(anAccumulator);
061    }
062
063    public SimpleAccumulator( final BigDecimal aTarget )
064    {
065        this(new UnlimitedDecimalPrimitive(aTarget));
066    }
067
068    public SimpleAccumulator( final BigInteger aTarget )
069    {
070        this(new UnlimitedIntegerPrimitive(aTarget));
071    }
072
073    public SimpleAccumulator( final boolean aTarget )
074    {
075        this(new BooleanPrimitive(aTarget));
076    }
077
078    public SimpleAccumulator( final byte aTarget )
079    {
080        this(new BytePrimitive(aTarget));
081    }
082
083    public SimpleAccumulator( final char aTarget )
084    {
085        this(new CharacterPrimitive(aTarget));
086    }
087
088    public SimpleAccumulator( final String aTarget )
089    {
090        this(new TextPrimitive(aTarget));
091    }
092
093    public SimpleAccumulator( final double aTarget )
094    {
095        this(new DoublePrimitive(aTarget));
096    }
097
098    public SimpleAccumulator( final Enum<?> aTarget )
099    {
100        this(new EnumerationPrimitive(aTarget));
101    }
102
103    public SimpleAccumulator( final float aTarget )
104    {
105        this(new FloatPrimitive(aTarget));
106    }
107
108    public SimpleAccumulator( final int aTarget )
109    {
110        this(new IntegerPrimitive(aTarget));
111    }
112
113    public SimpleAccumulator( final long aTarget )
114    {
115        this(new LongPrimitive(aTarget));
116    }
117
118    public SimpleAccumulator( final Primitive<?> aTarget )
119    {
120        super(aTarget);
121    }
122
123    public SimpleAccumulator(
124        final Primitive<?> aTarget,
125        final AssociativeList<Accumulator<?>,Accumulator<?>> members )
126    {
127        super(aTarget, members);
128    }
129
130    public SimpleAccumulator( final short aTarget )
131    {
132        this(new ShortPrimitive(aTarget));
133    }
134
135    @Override
136    public SimpleAccumulator copySharing(
137        final Primitive<?> aTarget,
138        final AssociativeList<Accumulator<?>,Accumulator<?>> members )
139    {
140        return new SimpleAccumulator(this.getTarget(), this.members());
141    }
142}