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