public class

ReferenceCounter

extends Object
java.lang.Object
   ↳ com.pnfsoftware.jeb.util.collect.ReferenceCounter<K>

Class Overview

A simple, thread-safe object reference counter.

Note that this utility class has nothing to do with Garbage Collection reference counting.

Summary

Public Constructors
ReferenceCounter()
Create a new reference counter.
Public Methods
synchronized int dec(K key)
Unrecord an object, ie decrement its reference counter by one.
synchronized String formatTopReferences(int top)
synchronized int get(K key)
Get the reference counter for an object.
synchronized boolean has(K key)
Check if an object is currently referenced, ie its reference counter is greater or equal than zero.
synchronized int inc(K key)
Record an object, ie increment its reference counter.
synchronized void load(Collection<? extends K> coll)
synchronized boolean remove(K key)
Remove an object from tracking.
synchronized String toString()
[Expand]
Inherited Methods
From class java.lang.Object

Public Constructors

public ReferenceCounter ()

Create a new reference counter.

Public Methods

public synchronized int dec (K key)

Unrecord an object, ie decrement its reference counter by one. If the object is currently tracked, an exception will be raised.

Parameters
key object
Returns
  • the updated counter for this object
Throws
IllegalArgumentException if the object is not present

public synchronized String formatTopReferences (int top)

public synchronized int get (K key)

Get the reference counter for an object.

Parameters
key object
Returns
  • the counter; 0 if the object is currently not tracked

public synchronized boolean has (K key)

Check if an object is currently referenced, ie its reference counter is greater or equal than zero.

Parameters
key object
Returns
  • true if the object is referenced

public synchronized int inc (K key)

Record an object, ie increment its reference counter.

Parameters
key object
Returns
  • the updated counter for this object

public synchronized void load (Collection<? extends K> coll)

public synchronized boolean remove (K key)

Remove an object from tracking. This method is equivalent to decrementing the object counter until zero.

Parameters
key object
Returns
  • true if the object was actually referenced (ie its counter was >= 1), false if it was not

public synchronized String toString ()