laser.util
Class AnnotationTable

java.lang.Object
  extended by laser.util.AnnotationTable
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Annotatable

public class AnnotationTable
extends java.lang.Object
implements Annotatable, java.lang.Cloneable, java.io.Serializable

The AnnotationTable class allows user-defined annotations to be associated with a given object. They are indexed by class.

Author:
Heather M. Conboy (laser-software@cs.umass.edu)
See Also:
Annotation, Annotatable, Serialized Form

Constructor Summary
AnnotationTable()
          Constructs a new empty AnnotationTable.
 
Method Summary
 boolean addAnnotation(Annotation annotation)
          Adds the given annotation to this AnnotationTable.
 boolean addAnnotations(java.util.Collection<? extends Annotation> annotations)
          Adds the given annotations to this AnnotationTable.
 java.lang.Object clone()
          Returns a clone of this AnnotationTable.
 boolean copyAnnotations(Annotatable container)
          Copies the annotations within this Annotatable object that pass the filters into the given Annotatable object.
 java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses()
          Gets all of the annotation classes from this AnnotationTable.
 java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses(java.lang.Class<? extends Annotation> query)
          Gets all of the annotation classes from this AnnotationTable that are subclasses of the given one.
 java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationFilters()
          Gets the filters that specify which annotations should be excluded when copying.
 java.util.Collection<Annotation> getAnnotations()
          Gets all of the annotations within this AnnotationTable.
 java.util.Collection<Annotation> getAnnotations(java.lang.Class<? extends Annotation> query)
          Gets all of the annotations of the given annotation class from this AnnotationTable.
 boolean isEmpty()
          Tests whether this AnnotationTable is empty or not.
 boolean removeAnnotation(Annotation annotation)
          Removes the given annotation from this AnnotationTable.
 void removeAnnotations()
          Removes all of the annotations from this AnnotationTable.
 boolean removeAnnotations(java.lang.Class<? extends Annotation> query)
          Removes all of the annotations of the given annotation class from this AnnotationTable.
 boolean removeAnnotations(java.util.Collection<? extends Annotation> annotations)
          Removes the given annotations from this AnnotationTable.
 void setAnnotationFilters(java.util.Set<java.lang.Class<? extends Annotation>> filters)
          Sets the filters that specify which annotations should be excluded when copying.
 int size()
          Returns the number of annotations within this AnnotationTable.
 java.lang.String toString()
          Returns a string representation of this AnnotationTable.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AnnotationTable

public AnnotationTable()
Constructs a new empty AnnotationTable.

Method Detail

addAnnotation

public boolean addAnnotation(Annotation annotation)
Adds the given annotation to this AnnotationTable.

Specified by:
addAnnotation in interface Annotatable
Parameters:
annotation - The Annotation to be added
Returns:
True if it was added and false otherwise
Throws:
java.lang.IllegalArgumentException - if the annotation is null

addAnnotations

public boolean addAnnotations(java.util.Collection<? extends Annotation> annotations)
Adds the given annotations to this AnnotationTable.

Specified by:
addAnnotations in interface Annotatable
Parameters:
annotations - The Set of Annotations to be added
Returns:
True if any annotation was added and false otherwise
Throws:
java.lang.IllegalArgumentException - if annotations is null or any annotation is null

copyAnnotations

public boolean copyAnnotations(Annotatable container)
Copies the annotations within this Annotatable object that pass the filters into the given Annotatable object.

Specified by:
copyAnnotations in interface Annotatable
Parameters:
container - The Annotatable that the copied Annotations will be associated with
Returns:
True if any annotation was copied and false otherwise
See Also:
Annotatable.getAnnotationFilters()

getAnnotationClasses

public java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses(java.lang.Class<? extends Annotation> query)
Gets all of the annotation classes from this AnnotationTable that are subclasses of the given one.

Specified by:
getAnnotationClasses in interface Annotatable
Parameters:
query - The Annotation Class to obtain the subclasses of
Returns:
A Set of all of the Annotation Classes that are subclasses of the given class
Throws:
java.lang.IllegalArgumentException - if query is null

getAnnotationClasses

public java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationClasses()
Gets all of the annotation classes from this AnnotationTable.

Specified by:
getAnnotationClasses in interface Annotatable
Returns:
A Set of all of the Annotation Classes

getAnnotations

public java.util.Collection<Annotation> getAnnotations(java.lang.Class<? extends Annotation> query)
Gets all of the annotations of the given annotation class from this AnnotationTable.

Specified by:
getAnnotations in interface Annotatable
Parameters:
query - The Annotation Class of interest
Returns:
A Collection of all of the Annotations of the specified Annotation Class
Throws:
java.lang.IllegalArgumentException - if query is null

getAnnotations

public java.util.Collection<Annotation> getAnnotations()
Gets all of the annotations within this AnnotationTable.

Specified by:
getAnnotations in interface Annotatable
Returns:
A Collection of all of the Annotations

getAnnotationFilters

public java.util.Set<java.lang.Class<? extends Annotation>> getAnnotationFilters()
Gets the filters that specify which annotations should be excluded when copying.

Specified by:
getAnnotationFilters in interface Annotatable
Returns:
A Set of all the filters
See Also:
#copy, copyAnnotations(laser.util.Annotatable)

setAnnotationFilters

public void setAnnotationFilters(java.util.Set<java.lang.Class<? extends Annotation>> filters)
Sets the filters that specify which annotations should be excluded when copying.

Specified by:
setAnnotationFilters in interface Annotatable
Parameters:
filters - The Set of all the filters
See Also:
#copy, copyAnnotations(laser.util.Annotatable)

removeAnnotation

public boolean removeAnnotation(Annotation annotation)
Removes the given annotation from this AnnotationTable.

Specified by:
removeAnnotation in interface Annotatable
Parameters:
annotation - The Annotation to remove
Returns:
True if it was removed and false otherwise
Throws:
java.lang.IllegalArgumentException - if annotation is null

removeAnnotations

public boolean removeAnnotations(java.util.Collection<? extends Annotation> annotations)
Removes the given annotations from this AnnotationTable.

Specified by:
removeAnnotations in interface Annotatable
Parameters:
annotations - The Set of Annotations to be removed
Returns:
True if any annotation was removed and false otherwise
Throws:
java.lang.IllegalArgumentException - if annotations is null or any annotation is null

removeAnnotations

public boolean removeAnnotations(java.lang.Class<? extends Annotation> query)
Removes all of the annotations of the given annotation class from this AnnotationTable.

Specified by:
removeAnnotations in interface Annotatable
Parameters:
query - The Annotation Class to be removed
Returns:
True if any annotation was removed and false otherwise
Throws:
java.lang.IllegalArgumentException - if query is null

removeAnnotations

public void removeAnnotations()
Removes all of the annotations from this AnnotationTable.

Specified by:
removeAnnotations in interface Annotatable

isEmpty

public boolean isEmpty()
Tests whether this AnnotationTable is empty or not.

Returns:
True if there are no annotations and false otherwise

size

public int size()
Returns the number of annotations within this AnnotationTable.

Returns:
The number of Annotations

clone

public java.lang.Object clone()
Returns a clone of this AnnotationTable.

Overrides:
clone in class java.lang.Object
Returns:
A Clone of this Object

toString

public java.lang.String toString()
Returns a string representation of this AnnotationTable.

Overrides:
toString in class java.lang.Object
Returns:
A String representations of this Object