001/**
002 * BooleanPrimitive.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.booleans;
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 * {@link ConcurrencyStrategy#SEQUENTIAL Sequential} {@code boolean} precision
031 * {@link Primitive primitive} implementation
032 * 
033 * @since JAccumulator 4.0
034 * @author Nicole Tedesco (<a
035 *         href="mailto:Nicole@NicoleTedesco.com">Nicole@NicoleTedesco.com</a>)
036 */
037public final class BooleanPrimitive
038    extends
039        AbstractBooleanPrimitive<BooleanPrimitive>
040{
041    private static final long serialVersionUID = 899525245275943720L;
042
043    private boolean _theValue;
044
045    public BooleanPrimitive()
046    {
047        this(false);
048    }
049
050    public BooleanPrimitive( final BigDecimal aValue )
051    {
052        this(To.booleanValue(aValue));
053    }
054
055    public BooleanPrimitive( final BigInteger aValue )
056    {
057        this(To.booleanValue(aValue));
058    }
059
060    public BooleanPrimitive( final boolean aValue )
061    {
062        super();
063        this._theValue = aValue;
064    }
065
066    public BooleanPrimitive( final byte aValue )
067    {
068        this(To.booleanValue(aValue));
069    }
070
071    public BooleanPrimitive( final char aValue )
072    {
073        this(To.booleanValue(aValue));
074    }
075
076    public BooleanPrimitive( final double aValue )
077    {
078        this(To.booleanValue(aValue));
079    }
080
081    public BooleanPrimitive( final float aValue )
082    {
083        this(To.booleanValue(aValue));
084    }
085
086    public BooleanPrimitive( final int aValue )
087    {
088        this(To.booleanValue(aValue));
089    }
090
091    public BooleanPrimitive( final long aValue )
092    {
093        this(To.booleanValue(aValue));
094    }
095
096    public BooleanPrimitive( final SealedScalar<?> aValue )
097    {
098        this(aValue.booleanValue());
099    }
100
101    public BooleanPrimitive( final short aValue )
102    {
103        this(To.booleanValue(aValue));
104    }
105
106    public BooleanPrimitive( final String aValue )
107    {
108        this();
109        To.SCALAR.reactToText(aValue, this);
110    }
111
112    @Override
113    public final BooleanPrimitive and( final boolean aValue )
114        throws UnsupportedOperationException,
115            IllegalArgumentException,
116            ArithmeticException
117    {
118        this._theValue &= aValue;
119        return this;
120    }
121
122    @Override
123    public final boolean booleanValue()
124    {
125        return this._theValue;
126    }
127
128    @Override
129    public final BooleanPrimitive copy()
130    {
131        return new BooleanPrimitive(this._theValue);
132    }
133
134    @Override
135    public final BooleanPrimitive copyUsing( final boolean aValue )
136    {
137        return new BooleanPrimitive(aValue);
138    }
139
140    @Override
141    public final ConcurrencyStrategy getConcurrency()
142    {
143        return ConcurrencyStrategy.SEQUENTIAL;
144    }
145
146    @Override
147    public final BooleanPrimitive not()
148        throws UnsupportedOperationException,
149            IllegalArgumentException,
150            ArithmeticException
151    {
152        this._theValue ^= true;
153        return this;
154    }
155
156    @Override
157    public final BooleanPrimitive or( final boolean aValue )
158        throws UnsupportedOperationException,
159            IllegalArgumentException,
160            ArithmeticException
161    {
162        this._theValue |= aValue;
163        return this;
164    }
165
166    @Override
167    public final BooleanPrimitive setScalar( final boolean aValue )
168        throws UnsupportedOperationException,
169            IllegalArgumentException,
170            ArithmeticException
171    {
172        this._theValue = aValue;
173        return this;
174    }
175
176    @Override
177    public final BooleanPrimitive xor( final boolean aValue )
178        throws UnsupportedOperationException,
179            IllegalArgumentException,
180            ArithmeticException
181    {
182        this._theValue ^= aValue;
183        return this;
184    }
185}