001/** 002 * BytePrimitive.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.bytes; 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 byte} 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 BytePrimitive 037 extends 038 AbstractBytePrimitive<BytePrimitive> 039{ 040 private static final long serialVersionUID = -200325603265454058L; 041 042 private byte _theValue; 043 044 public BytePrimitive() 045 { 046 this((byte)0); 047 } 048 049 public BytePrimitive( final BigDecimal aValue ) 050 { 051 this(aValue.byteValue()); 052 } 053 054 public BytePrimitive( final BigInteger aValue ) 055 { 056 this(aValue.byteValue()); 057 } 058 059 public BytePrimitive( final boolean aValue ) 060 { 061 this(To.byteValue(aValue)); 062 } 063 064 public BytePrimitive( final byte aValue ) 065 { 066 super(); 067 this._theValue = aValue; 068 } 069 070 public BytePrimitive( final char aValue ) 071 { 072 this((byte)aValue); 073 } 074 075 public BytePrimitive( final double aValue ) 076 { 077 this((byte)aValue); 078 } 079 080 public BytePrimitive( final float aValue ) 081 { 082 this((byte)aValue); 083 } 084 085 public BytePrimitive( final int aValue ) 086 { 087 this((byte)aValue); 088 } 089 090 public BytePrimitive( final long aValue ) 091 { 092 this((byte)aValue); 093 } 094 095 public BytePrimitive( final SealedScalar<?> aValue ) 096 { 097 this(aValue.byteValue()); 098 } 099 100 public BytePrimitive( final short aValue ) 101 { 102 this((byte)aValue); 103 } 104 105 public BytePrimitive( final String aValue ) 106 { 107 this(); 108 To.SCALAR.reactToText(aValue, this); 109 } 110 111 @Override 112 public final BytePrimitive and( final byte aValue ) 113 throws UnsupportedOperationException, 114 IllegalArgumentException, 115 ArithmeticException 116 { 117 this._theValue &= aValue; 118 return this; 119 } 120 121 @Override 122 public final byte bytePostDecrement() 123 throws UnsupportedOperationException, 124 ArithmeticException, 125 IllegalArgumentException 126 { 127 return this._theValue--; 128 } 129 130 @Override 131 public final byte bytePostIncrement() 132 throws UnsupportedOperationException, 133 ArithmeticException, 134 IllegalArgumentException 135 { 136 return this._theValue++; 137 } 138 139 @Override 140 public final byte byteValue() 141 { 142 return this._theValue; 143 } 144 145 @Override 146 public final BytePrimitive copy() 147 { 148 return new BytePrimitive(this._theValue); 149 } 150 151 @Override 152 public final BytePrimitive copyUsing( final byte aValue ) 153 { 154 return new BytePrimitive(aValue); 155 } 156 157 @Override 158 public final BytePrimitive decrement() 159 throws UnsupportedOperationException, 160 ArithmeticException, 161 IllegalArgumentException 162 { 163 --this._theValue; 164 return this; 165 } 166 167 @Override 168 public final BytePrimitive difference( final byte aValue ) 169 throws UnsupportedOperationException, 170 IllegalArgumentException, 171 ArithmeticException 172 { 173 this._theValue -= aValue; 174 return this; 175 } 176 177 @Override 178 public final ConcurrencyStrategy getConcurrency() 179 { 180 return ConcurrencyStrategy.SEQUENTIAL; 181 } 182 183 @Override 184 public final BytePrimitive increment() 185 throws UnsupportedOperationException, 186 ArithmeticException, 187 IllegalArgumentException 188 { 189 ++this._theValue; 190 return this; 191 } 192 193 @Override 194 public final BytePrimitive mod( final byte aValue ) 195 throws UnsupportedOperationException, 196 IllegalArgumentException, 197 ArithmeticException 198 { 199 this._theValue %= aValue; 200 return this; 201 } 202 203 @Override 204 public final BytePrimitive not() 205 throws UnsupportedOperationException, 206 IllegalArgumentException, 207 ArithmeticException 208 { 209 this._theValue ^= (byte)-1; 210 return this; 211 } 212 213 @Override 214 public final BytePrimitive or( final byte aValue ) 215 throws UnsupportedOperationException, 216 IllegalArgumentException, 217 ArithmeticException 218 { 219 this._theValue |= aValue; 220 return this; 221 } 222 223 @Override 224 public final BytePrimitive product( final byte aValue ) 225 throws UnsupportedOperationException, 226 IllegalArgumentException, 227 ArithmeticException 228 { 229 this._theValue *= aValue; 230 return this; 231 } 232 233 @Override 234 public final BytePrimitive quotient( final byte aValue ) 235 throws UnsupportedOperationException, 236 IllegalArgumentException, 237 ArithmeticException 238 { 239 this._theValue /= aValue; 240 return this; 241 } 242 243 @Override 244 public final BytePrimitive setScalar( final byte aValue ) 245 throws UnsupportedOperationException, 246 IllegalArgumentException, 247 ArithmeticException 248 { 249 this._theValue = aValue; 250 return this; 251 } 252 253 @Override 254 public final BytePrimitive shiftLeft( final int count ) 255 throws UnsupportedOperationException, 256 IllegalArgumentException, 257 ArithmeticException 258 { 259 this._theValue <<= count; 260 return this; 261 } 262 263 @Override 264 public final BytePrimitive shiftRight( final int count ) 265 throws UnsupportedOperationException, 266 IllegalArgumentException, 267 ArithmeticException 268 { 269 this._theValue >>= count; 270 return this; 271 } 272 273 @Override 274 public final BytePrimitive shiftRightExtendZero( final int count ) 275 throws UnsupportedOperationException, 276 IllegalArgumentException, 277 ArithmeticException 278 { 279 this._theValue >>>= count; 280 return this; 281 } 282 283 @Override 284 public final BytePrimitive sum( final byte aValue ) 285 throws UnsupportedOperationException, 286 IllegalArgumentException, 287 ArithmeticException 288 { 289 this._theValue += aValue; 290 return this; 291 } 292 293 @Override 294 public final BytePrimitive xor( final byte aValue ) 295 throws UnsupportedOperationException, 296 IllegalArgumentException, 297 ArithmeticException 298 { 299 this._theValue ^= aValue; 300 return this; 301 } 302}