Top Description Fields Constructors Methods
net.sf.ehcache.util.counter

public Class CounterImpl

extends Object
implements Counter, Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable, net.sf.ehcache.util.counter.Counter
Known Direct Subclasses
net.sf.ehcache.util.counter.sampled.SampledCounterImpl
Imports
java.io.Serializable, java.util.concurrent.atomic.AtomicLong

A simple counter implementation
Author
Abhishek Sanoujam
Since
1.7

Field Summary

Modifier and TypeField and Description
private AtomicLong

Constructor Summary

AccessConstructor and Description
public
CounterImpl()

Default Constructor

public
CounterImpl(long initialValue)

Constructor with initial value

Method Summary

Modifier and TypeMethod and Description
public long
decrement()

Implements net.sf.ehcache.util.counter.Counter.decrement.

Decrement the counter by 1
public long
decrement(long amount)

Implements net.sf.ehcache.util.counter.Counter.decrement.

Decrement the counter by given amount
public long
getAndSet(long newValue)

Implements net.sf.ehcache.util.counter.Counter.getAndSet.

Returns the value of the counter and sets it to the new value
public long
getValue()

Implements net.sf.ehcache.util.counter.Counter.getValue.

Gets current value of the counter
public long
increment()

Implements net.sf.ehcache.util.counter.Counter.increment.

Increment the counter by 1
public long
increment(long amount)

Implements net.sf.ehcache.util.counter.Counter.increment.

Increment the counter by given amount
public void
setValue(long newValue)

Implements net.sf.ehcache.util.counter.Counter.setValue.

Sets the value of the counter to the supplied value
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

valueback to summary
private AtomicLong value

Constructor Detail

CounterImplback to summary
public CounterImpl()

Default Constructor

CounterImplback to summary
public CounterImpl(long initialValue)

Constructor with initial value

Method Detail

decrementback to summary
public long decrement()

Implements net.sf.ehcache.util.counter.Counter.decrement.

Doc from net.sf.ehcache.util.counter.Counter.decrement.

Decrement the counter by 1

Returns:long

the value after decrementing

decrementback to summary
public long decrement(long amount)

Implements net.sf.ehcache.util.counter.Counter.decrement.

Doc from net.sf.ehcache.util.counter.Counter.decrement.

Decrement the counter by given amount

Returns:long

the value of the counter after decrementing

getAndSetback to summary
public long getAndSet(long newValue)

Implements net.sf.ehcache.util.counter.Counter.getAndSet.

Doc from net.sf.ehcache.util.counter.Counter.getAndSet.

Returns the value of the counter and sets it to the new value

Returns:long

Returns the old value

getValueback to summary
public long getValue()

Implements net.sf.ehcache.util.counter.Counter.getValue.

Doc from net.sf.ehcache.util.counter.Counter.getValue.

Gets current value of the counter

Returns:long

current value of the counter

incrementback to summary
public long increment()

Implements net.sf.ehcache.util.counter.Counter.increment.

Doc from net.sf.ehcache.util.counter.Counter.increment.

Increment the counter by 1

Returns:long

the value after incrementing

incrementback to summary
public long increment(long amount)

Implements net.sf.ehcache.util.counter.Counter.increment.

Doc from net.sf.ehcache.util.counter.Counter.increment.

Increment the counter by given amount

Returns:long

the value of the counter after incrementing

setValueback to summary
public void setValue(long newValue)

Implements net.sf.ehcache.util.counter.Counter.setValue.

Doc from net.sf.ehcache.util.counter.Counter.setValue.

Sets the value of the counter to the supplied value