org.biojava.bio
Class OverlayAnnotation

java.lang.Object
  |
  +--org.biojava.bio.OverlayAnnotation

public class OverlayAnnotation
extends java.lang.Object
implements Annotation

Annotation implementation which allows new key-value pairs to be layered on top of an underlying Annotation. When getProperty is called, we first check for a value stored in the overlay. If this fails, the underlying Annotation is checked. Values passed to setProperty are always stored within the overlay.

Author:
Thomas Down

Inner classes inherited from class org.biojava.bio.Annotation
Annotation.EmptyAnnotation
 
Fields inherited from interface org.biojava.bio.Annotation
EMPTY_ANNOTATION
 
Constructor Summary
OverlayAnnotation(Annotation par)
          Construct an annotation which can overlay new key-value pairs onto an underlying annotation.
 
Method Summary
 java.util.Map asMap()
          Return a Map view onto this annotation.
 java.lang.Object getProperty(java.lang.Object key)
          Retrieve the value of a property by key.
 java.util.Set keys()
          Return a Set containing all key objects visible in this annotation.
 void setProperty(java.lang.Object key, java.lang.Object value)
          Set the value of a property.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

OverlayAnnotation

public OverlayAnnotation(Annotation par)
Construct an annotation which can overlay new key-value pairs onto an underlying annotation.
Parameters:
par - The `parent' annotation, on which new key-value pairs can be layered.
Method Detail

setProperty

public void setProperty(java.lang.Object key,
                        java.lang.Object value)
Description copied from interface: Annotation
Set the value of a property.

This method throws an exception if either properties can not be added to this object, or that this particular property is immutable or illegal within the implementation.

Specified by:
setProperty in interface Annotation
Tags copied from interface: Annotation
Parameters:
key - the key object
value - the new value for this key
Throws:
java.lang.IllegalArgumentException - if the property key cannot be changed.
java.lang.UnsupportedOperationException - if this annotation object is immutable.

getProperty

public java.lang.Object getProperty(java.lang.Object key)
Description copied from interface: Annotation
Retrieve the value of a property by key.

Unlike the Map collections, it will complain if the key does not exist. It will only return null if the key is defined and has value null.

Specified by:
getProperty in interface Annotation
Tags copied from interface: Annotation
Parameters:
key - the key of the property to retrieve
Returns:
the object associated with that key
Throws:
java.util.NoSuchElementException - if there is no property with the key

keys

public java.util.Set keys()
Return a Set containing all key objects visible in this annotation. The Set is unmodifiable, but will dynamically reflect changes made to the annotation.
Specified by:
keys in interface Annotation
Tags copied from interface: Annotation
Returns:
a Set of key objects

asMap

public java.util.Map asMap()
Return a Map view onto this annotation. The returned Map is unmodifiable, but will dynamically reflect any changes made to this annotation.
Specified by:
asMap in interface Annotation
Tags copied from interface: Annotation
Returns:
a Map