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