org.opensaml.xml.util
Class IndexingObjectStore<T>

java.lang.Object
  extended by org.opensaml.xml.util.IndexingObjectStore<T>
Type Parameters:
T - type of object being stored

@ThreadSafe
public class IndexingObjectStore<T>
extends Object

This class is used to store instances of objects that may be created independently but are, in face, the same object. For example, KeyInfos contain keys, certs, and CRLs. Multiple unique instances of a KeyInfo may contain, and separately construct, the exact same cert. KeyInfo could, therefore, create a class-level instance of this object store and put certs within it. In this manner the cert is only sitting in memory once and each KeyInfo simply stores a reference (index) to stored object. This store uses basic reference counting to keep track of how many of the respective objects are pointing to an entry. Adding an object that already exists, as determined by the objects hashCode() method, simply increments the reference counter. Removing an object decrements the counter. Only when the counter reaches zero is the object actually freed for garbage collection. Note the instance of an object returned by get(String) need not be the same object as stored via put(Object). However, their hash codes will be equal. Therefore this store should never be used to store objects that produce identical hash codes but are not functionally identical objects.


Constructor Summary
IndexingObjectStore()
          Constructor.
 
Method Summary
 void clear()
          Clears the object store.
 boolean contains(String index)
          Checks whether the store contains an object registered under the given index.
 T get(String index)
          Gets a registered object by its index.
 boolean isEmpty()
          Checks if the store is empty.
 String put(T object)
          Adds the given object to the store.
 void remove(String index)
          Removes the object associated with the given index.
 int size()
          Gets the total number of unique items in the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IndexingObjectStore

public IndexingObjectStore()
Constructor.

Method Detail

clear

public void clear()
Clears the object store.


contains

public boolean contains(String index)
Checks whether the store contains an object registered under the given index.

Parameters:
index - the index to check
Returns:
true if an object is associated with the given index, false if not

isEmpty

public boolean isEmpty()
Checks if the store is empty.

Returns:
true if the store is empty, false if not

put

public String put(T object)
Adds the given object to the store. Technically this method only adds the object if it does not already exist in the store. If it does this method simply increments the reference count of the object.

Parameters:
object - the object to add to the store, may be null
Returns:
the index that may be used to later retrieve the object or null if the object was null

get

public T get(String index)
Gets a registered object by its index.

Parameters:
index - the index of an object previously registered, may be null
Returns:
the registered object or null if no object is registered for that index

remove

public void remove(String index)
Removes the object associated with the given index. Technically this method decrements the reference counter to the object. If, after the decrement, the reference counter is zero then, and only then, is the object actually freed for garbage collection.

Parameters:
index - the index of the object, may be null

size

public int size()
Gets the total number of unique items in the store. This number is unaffected by the reference count of the individual stored objects.

Returns:
number of items in the store


Copyright © 2006-2011 Internet2. All Rights Reserved.