org.biojava.bio
Class AbstractAnnotation

java.lang.Object
  extended byorg.biojava.utils.AbstractChangeable
      extended byorg.biojava.bio.AbstractAnnotation
All Implemented Interfaces:
Annotation, Changeable, java.io.Serializable
Direct Known Subclasses:
AnnotationChanger, AnnotationRenamer, BeanAsAnnotation, SimpleAnnotation, SmallAnnotation

public abstract class AbstractAnnotation
extends AbstractChangeable
implements Annotation, java.io.Serializable

A utility class to ease the problem of implementing an Annotation to that of providing an apropreate implementation of Map.

Author:
Matthew Pocock, Greg Cox
See Also:
Serialized Form
For developers:
This class is only intended as a way to implement Annotation. If you are not trying to do that, then don't read on. If you are reading the documentation for an Annotation implementation that extends this, then don't read on. There is nothing to see here.

If you are still reading this, then you must be trying to implement Annotation. To do that, extend this class and implement getProperties() and propertiesAllocated().

Field Summary
 
Fields inherited from interface org.biojava.bio.Annotation
EMPTY_ANNOTATION, PROPERTY
 
Constructor Summary
protected AbstractAnnotation()
           
protected AbstractAnnotation(Annotation ann)
           
  AbstractAnnotation(java.util.Map annMap)
           
 
Method Summary
 java.util.Map asMap()
          Return a map that contains the same key/values as this Annotation.
 boolean containsProperty(java.lang.Object key)
          Returns whether there the property is defined.
 boolean equals(java.lang.Object o)
           
protected abstract  java.util.Map getProperties()
          Implement this to return the Map delegate.
 java.lang.Object getProperty(java.lang.Object key)
           Retrieve the value of a property by key.
 int hashCode()
           
 java.util.Set keys()
          Get a set of key objects.
protected abstract  boolean propertiesAllocated()
          A convenience method to see if we have allocated the properties Map.
 void removeProperty(java.lang.Object key)
          Delete a property
 void setProperty(java.lang.Object key, java.lang.Object value)
           Set the value of a property.
 java.lang.String toString()
           
 
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
 

Constructor Detail

AbstractAnnotation

protected AbstractAnnotation()

AbstractAnnotation

protected AbstractAnnotation(Annotation ann)
                      throws java.lang.IllegalArgumentException

AbstractAnnotation

public AbstractAnnotation(java.util.Map annMap)
Method Detail

getProperties

protected abstract java.util.Map getProperties()
Implement this to return the Map delegate. From code in the 1.2 version of AbstractAnnotation

For developers:
This is required for the implementation of an Annotation that extends AbstractAnnotation

propertiesAllocated

protected abstract boolean propertiesAllocated()
A convenience method to see if we have allocated the properties Map.

Returns:
true if the properties have been allocated, false otherwise
For developers:
This is required for the implementation of an Annotation that extends AbstractAnnotation

getProperty

public java.lang.Object getProperty(java.lang.Object key)
                             throws java.util.NoSuchElementException
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
Parameters:
key - The key whose property to retrieve.
Returns:
the object associated with that key
Throws:
java.util.NoSuchElementException - if the property 'key' does not exist

setProperty

public void setProperty(java.lang.Object key,
                        java.lang.Object value)
                 throws ChangeVetoException
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
Parameters:
key - the key object
value - the new value for this key
Throws:
ChangeVetoException - if this annotation object can't be changed, or if the change was vetoed

removeProperty

public void removeProperty(java.lang.Object key)
                    throws ChangeVetoException,
                           java.util.NoSuchElementException
Description copied from interface: Annotation
Delete a property

Specified by:
removeProperty in interface Annotation
Parameters:
key - the key object
Throws:
ChangeVetoException - if the change is vetoed
java.util.NoSuchElementException - if the property doesn't exist

containsProperty

public boolean containsProperty(java.lang.Object key)
Description copied from interface: Annotation
Returns whether there the property is defined.

Specified by:
containsProperty in interface Annotation
Parameters:
key - the key Object to search for
Returns:
true if this Annotation knows about the key, false otherwise

keys

public java.util.Set keys()
Description copied from interface: Annotation
Get a set of key objects.

Specified by:
keys in interface Annotation
Returns:
a Set of key objects

toString

public java.lang.String toString()

asMap

public java.util.Map asMap()
Description copied from interface: Annotation
Return a map that contains the same key/values as this Annotation.

If the annotation changes, the map may not reflect this. The Map may be unmodifiable.

Specified by:
asMap in interface Annotation
Returns:
a Map

hashCode

public int hashCode()

equals

public boolean equals(java.lang.Object o)