amwebarsentitlementservice.storage
Class AMWebARSStorage

java.lang.Object
  |
  +--amwebarsentitlementservice.storage.AMWebARSStorage

public class AMWebARSStorage
extends java.lang.Object

Stores AMWebARSContainers until they are invalid. The AMWebARSStorage maintains the invariant that each request only taskes valid containers into account. That means that for instance the getContainer method only returns valid containers or null.


Constructor Summary
protected AMWebARSStorage()
           
 
Method Summary
 void addContainer(AMWebARSContainer container)
          Adds a container to the AMWebARSStorage.
 boolean checkTimeout(java.lang.String container_type_id, Subject subject)
          Checks whether a container specified by container_type_id and subject is still valid.
 void cleanStorage()
          Removes all containers from the AMWebARSStorage that are invalid at the current time.
 void cleanStorage(long date)
          Removes all containers from the AMWebARSStorage that are invalid at a given date.
 void clear()
          Removes all containers from the AMWebARSStorage.
protected  java.lang.Object clone()
          It isn't permited to clone the object: The clone method throws the CloneNotSupportedException.
 boolean containsContainer(java.lang.String container_type_id, Subject subject)
          Checks whether the AMWebARSStorage contains a specific container for a given container_type_id and a subject.
 boolean equals(java.lang.Object other_object)
          Tests whether this AMWebARSStorage is equal to another.
 AMWebARSContainer getContainer(java.lang.String container_type_id, Subject subject)
          Returns a chached container for a given container_type_id and a Subject.
static AMWebARSStorage getInstance()
          Returns the only instance of the AMWebARSStorage.
 boolean isEmpty()
          Tests whether the AMWebARSStorage is empty.
 AMWebARSContainer removeContainer(java.lang.String container_type_id, Subject subject)
          Removes a container specified by container_type_id and subject from the AMWebARSStorage.
 int size()
          Returns the current number of valid elements.
 java.lang.String toString()
          Returns a string description of the AMWebARSStorage.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AMWebARSStorage

protected AMWebARSStorage()
Method Detail

getInstance

public static AMWebARSStorage getInstance()
Returns the only instance of the AMWebARSStorage.
Returns:
only instance of AMWebARSStorage

clone

protected java.lang.Object clone()
                          throws java.lang.CloneNotSupportedException
It isn't permited to clone the object: The clone method throws the CloneNotSupportedException.
Overrides:
clone in class java.lang.Object
Throws:
java.lang.CloneNotSupportedException -  

getContainer

public AMWebARSContainer getContainer(java.lang.String container_type_id,
                                      Subject subject)
Returns a chached container for a given container_type_id and a Subject. If the container is missing or not valid anymore, null is returned.
Parameters:
container_type_id - id of the container type.
subject - Subject the container was retrieved for.
Returns:
a still valid AMWebARSContainer or null.

addContainer

public void addContainer(AMWebARSContainer container)
Adds a container to the AMWebARSStorage. This container is only added, if it's valid at the current time.
Parameters:
container - AMWebARSContainer which is to be added.
Throws:
NullPointerException - if the container is null.

containsContainer

public boolean containsContainer(java.lang.String container_type_id,
                                 Subject subject)
Checks whether the AMWebARSStorage contains a specific container for a given container_type_id and a subject.
Parameters:
container_type_id - String id of the container
subject - the Subject the container was requested for.
Returns:
true, if the container is present and still valid.

removeContainer

public AMWebARSContainer removeContainer(java.lang.String container_type_id,
                                         Subject subject)
Removes a container specified by container_type_id and subject from the AMWebARSStorage.
Parameters:
container_type_id - String id of the container
subject - the Subject the container was requested for.
Returns:
the removed container. If the container isn't found or not valid anymore the method returns null.

checkTimeout

public boolean checkTimeout(java.lang.String container_type_id,
                            Subject subject)
Checks whether a container specified by container_type_id and subject is still valid. If the container is found, but not valid anymore it's removed.
Parameters:
container_type_id - String id of the container
subject - the Subject the container was requested for.
Returns:
true, if the container is present and valid.

isEmpty

public boolean isEmpty()
Tests whether the AMWebARSStorage is empty. The method calls cleanStorage to be sure that all containers within the storage are valid.
Returns:
true, if the AMWebARSStorage contains valid containers.

size

public int size()
Returns the current number of valid elements. The method calls cleanStorage to be sure that all containers within the storage are valid.
Returns:
number of valid containers.

clear

public void clear()
Removes all containers from the AMWebARSStorage.

cleanStorage

public void cleanStorage()
Removes all containers from the AMWebARSStorage that are invalid at the current time.

cleanStorage

public void cleanStorage(long date)
Removes all containers from the AMWebARSStorage that are invalid at a given date.
Parameters:
date - long value of the date.

toString

public java.lang.String toString()
Returns a string description of the AMWebARSStorage. Please note that the description will contain personal information about the subjects.
Overrides:
toString in class java.lang.Object

equals

public boolean equals(java.lang.Object other_object)
Tests whether this AMWebARSStorage is equal to another.
Overrides:
equals in class java.lang.Object
Returns:
boolean true if both obj are the same.