001/** 002 * FloatPrimitive.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.floats; 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 float} 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 FloatPrimitive 037 extends 038 AbstractFloatPrimitive<FloatPrimitive> 039{ 040 private static final long serialVersionUID = 8984431034604236140L; 041 042 private float _theValue; 043 044 public FloatPrimitive() 045 { 046 super(); 047 this._theValue = 0.0F; 048 } 049 050 public FloatPrimitive( final BigDecimal aValue ) 051 { 052 this(aValue.floatValue()); 053 } 054 055 public FloatPrimitive( final BigInteger aValue ) 056 { 057 this(aValue.floatValue()); 058 } 059 060 public FloatPrimitive( final boolean aValue ) 061 { 062 this(To.floatValue(aValue)); 063 } 064 065 public FloatPrimitive( final byte aValue ) 066 { 067 this((float)aValue); 068 } 069 070 public FloatPrimitive( final char aValue ) 071 { 072 this((float)aValue); 073 } 074 075 public FloatPrimitive( final double aValue ) 076 { 077 this((float)aValue); 078 } 079 080 public FloatPrimitive( final float aValue ) 081 { 082 super(); 083 this._theValue = aValue; 084 } 085 086 public FloatPrimitive( final int aValue ) 087 { 088 this((float)aValue); 089 } 090 091 public FloatPrimitive( final long aValue ) 092 { 093 this((float)aValue); 094 } 095 096 public FloatPrimitive( final SealedScalar<?> aValue ) 097 { 098 this(aValue.floatValue()); 099 } 100 101 public FloatPrimitive( final short aValue ) 102 { 103 this((float)aValue); 104 } 105 106 public FloatPrimitive( final String aValue ) 107 { 108 this(); 109 To.SCALAR.reactToText(aValue, this); 110 } 111 112 @Override 113 public final FloatPrimitive copy() 114 { 115 return new FloatPrimitive(this._theValue); 116 } 117 118 @Override 119 public final FloatPrimitive copyUsing( final float aValue ) 120 { 121 return new FloatPrimitive(aValue); 122 } 123 124 @Override 125 public FloatPrimitive decrement() 126 throws UnsupportedOperationException, 127 IllegalArgumentException, 128 ArithmeticException 129 { 130 --this._theValue; 131 return this; 132 } 133 134 @Override 135 public final FloatPrimitive difference( final float aValue ) 136 throws UnsupportedOperationException, 137 IllegalArgumentException, 138 ArithmeticException 139 { 140 this._theValue -= aValue; 141 return this; 142 } 143 144 @Override 145 public final float floatPostDecrement() 146 throws UnsupportedOperationException, 147 ArithmeticException, 148 IllegalArgumentException 149 { 150 return this._theValue--; 151 } 152 153 @Override 154 public float floatPostIncrement() 155 throws UnsupportedOperationException, 156 ArithmeticException, 157 IllegalArgumentException 158 { 159 return this._theValue++; 160 } 161 162 @Override 163 public final float floatValue() 164 { 165 return this._theValue; 166 } 167 168 @Override 169 public final ConcurrencyStrategy getConcurrency() 170 { 171 return ConcurrencyStrategy.SEQUENTIAL; 172 } 173 174 @Override 175 public FloatPrimitive increment() 176 throws UnsupportedOperationException, 177 ArithmeticException, 178 IllegalArgumentException 179 { 180 ++this._theValue; 181 return this; 182 } 183 184 @Override 185 public final FloatPrimitive mod( final float aValue ) 186 throws UnsupportedOperationException, 187 IllegalArgumentException, 188 ArithmeticException 189 { 190 this._theValue %= aValue; 191 return this; 192 } 193 194 @Override 195 public final FloatPrimitive product( final float aValue ) 196 throws UnsupportedOperationException, 197 IllegalArgumentException, 198 ArithmeticException 199 { 200 this._theValue *= aValue; 201 return this; 202 } 203 204 @Override 205 public final FloatPrimitive quotient( final float aValue ) 206 throws UnsupportedOperationException, 207 IllegalArgumentException, 208 ArithmeticException 209 { 210 this._theValue /= aValue; 211 return this; 212 } 213 214 @Override 215 public final FloatPrimitive setScalar( final float aValue ) 216 throws UnsupportedOperationException, 217 IllegalArgumentException, 218 ArithmeticException 219 { 220 this._theValue = aValue; 221 return this; 222 } 223 224 @Override 225 public final FloatPrimitive sum( final float aValue ) 226 throws UnsupportedOperationException, 227 IllegalArgumentException, 228 ArithmeticException 229 { 230 this._theValue += aValue; 231 return this; 232 } 233}