org.exoplatform.commons.utils
Class AtomicPositiveLong

java.lang.Object
  extended by java.lang.Number
      extended by java.util.concurrent.atomic.AtomicLong
          extended by org.exoplatform.commons.utils.AtomicPositiveLong
All Implemented Interfaces:
java.io.Serializable

public class AtomicPositiveLong
extends java.util.concurrent.atomic.AtomicLong

Extends the @link{AtomicLong} to contain positive longs. If no initial value is provided when the object is created then the value is -1 to indicate that it is not yet initialized.

Version:
$Revision$
Author:
Julien Viet
See Also:
Serialized Form

Constructor Summary
AtomicPositiveLong()
          Create an atomic positive long with no initial value.
AtomicPositiveLong(long initialValue)
          Create an atomic positive long with an inital provided value.
 
Method Summary
 void setIfGreater(long newValue)
          Update the value if the new value is greater than the previous one or if the long is not initialized.
 void setIfLower(long newValue)
          Update the value if the new value is lower than the previous one or if the long is not initialized.
 
Methods inherited from class java.util.concurrent.atomic.AtomicLong
addAndGet, compareAndSet, decrementAndGet, doubleValue, floatValue, get, getAndAdd, getAndDecrement, getAndIncrement, getAndSet, incrementAndGet, intValue, longValue, set, toString, weakCompareAndSet
 
Methods inherited from class java.lang.Number
byteValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AtomicPositiveLong

public AtomicPositiveLong(long initialValue)
                   throws java.lang.IllegalArgumentException
Create an atomic positive long with an inital provided value.

Parameters:
initialValue - the initial value
Throws:
java.lang.IllegalArgumentException - if the value is negative

AtomicPositiveLong

public AtomicPositiveLong()
Create an atomic positive long with no initial value.

Method Detail

setIfGreater

public void setIfGreater(long newValue)
                  throws java.lang.IllegalArgumentException
Update the value if the new value is greater than the previous one or if the long is not initialized.

Parameters:
newValue - the new value
Throws:
java.lang.IllegalArgumentException - if the new value is negative

setIfLower

public void setIfLower(long newValue)
                throws java.lang.IllegalArgumentException
Update the value if the new value is lower than the previous one or if the long is not initialized.

Parameters:
newValue - the new value
Throws:
java.lang.IllegalArgumentException - if the new value is negative


Copyright © 2012 eXo Platform SAS. All Rights Reserved.