Class MergeAnnotation
- All Implemented Interfaces:
Serializable
,Annotation
,Changeable
- Since:
- 1.2 Use these when you have a list of Annotation instances that need to be viewed as one. For example, if you have annotation for a feature from a local database, in-memory objects and a web-page, you could build three Annotation instances and merge them using a MergeAnnotation.
- Author:
- Thomas Down, Matthew Pocock, Greg Cox, Francois Pepin
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
Listener used to forward changes for any of the underlying annotations to listeners on this annotation. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ChangeType
ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation.static final ChangeType
ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation.static final ChangeType
ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation.Fields inherited from interface org.biojava.bio.Annotation
EMPTY_ANNOTATION, PROPERTY
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAnnotation
(Annotation ann) Add a new Annotation to to the end of the list to be merged.asMap()
Return a map that contains the same key/values as this Annotation.boolean
containsProperty
(Object key) Returns whether there the property is defined.Gets an unmodifiable view of the list of Annotations that are part of the MergeAnnotation.protected ChangeSupport
getChangeSupport
(ChangeType changeType) Called to retrieve the ChangeSupport for this object.getProperty
(Object key) Retrieve the value of a property by key.keys()
Get a set of key objects.void
Remove an Annotation from the list.void
removeProperty
(Object key) Delete a property.void
setProperty
(Object key, Object value) Set the value of a property.Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.biojava.utils.Changeable
addChangeListener, addChangeListener, isUnchanging, removeChangeListener, removeChangeListener
-
Field Details
-
ANNOTATION_CHANGED
ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation. -
ANNOTATION_ADD
ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation. -
ANNOTATION_REMOVE
ChangeType of ChangeEvent fired before and after an annotation is added to MergeAnnotation.
-
-
Constructor Details
-
MergeAnnotation
public MergeAnnotation()
-
-
Method Details
-
addAnnotation
Add a new Annotation to to the end of the list to be merged. Use this to alter the Annotations being merged- Parameters:
ann
- the Annotation to add- Throws:
ChangeVetoException
- if the annotation could not be added
-
getAnnotations
Gets an unmodifiable view of the list of Annotations that are part of the MergeAnnotation. Lower indices Annotation have precedence if 2 Annotations share the same property.- Returns:
- an unmodifiable
List
of the Annotations that form this MergeAnnotation.
-
removeAnnotation
Remove an Annotation from the list. This can be used to change the ordering of the Annotations by re-adding it later.- Parameters:
ann
- anAnnotation
to be removed.- Throws:
ChangeVetoException
- if an error occurs
-
getChangeSupport
Description copied from class:AbstractChangeable
Called to retrieve the ChangeSupport for this object.Your implementation of this method should have the following structure:
It is usual for the forwarding listeners (someForwarder in this example) to be transient and lazily instantiated. Be sure to register invalid input: '&' unregister the forwarder in the code that does the ChangeEvent handling in setter methods.ChangeSupport cs = super.getChangeSupport(ct); if(someForwarder == null invalid input: '&'invalid input: '&' ct.isMatching(SomeInterface.SomeChangeType)) { someForwarder = new ChangeForwarder(... this.stateVariable.addChangeListener(someForwarder, VariableInterface.AChange); } return cs;
- Overrides:
getChangeSupport
in classAbstractChangeable
-
setProperty
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.
Normal raw access to the property. For cleverer access, use methods in AnnotationType.- Specified by:
setProperty
in interfaceAnnotation
- Parameters:
key
- the key objectvalue
- the new value for this key- Throws:
ChangeVetoException
- if this annotation object can't be changed, or if the change was vetoed.
-
removeProperty
Description copied from interface:Annotation
Delete a property. Normal raw access to the property. For cleverer access, use methods in AnnotationType.- Specified by:
removeProperty
in interfaceAnnotation
- Parameters:
key
- the key object- Throws:
ChangeVetoException
- if the change is vetoed
-
getProperty
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.
Normal raw access to the property. For cleverer access, use methods in AnnotationType.- Specified by:
getProperty
in interfaceAnnotation
- Parameters:
key
- the key of the property to retrieve- Returns:
- the object associated with that key
-
containsProperty
Description copied from interface:Annotation
Returns whether there the property is defined. Normal raw access to the property. For cleverer access, use methods in AnnotationType.- Specified by:
containsProperty
in interfaceAnnotation
- Parameters:
key
- the key Object to search for- Returns:
- true if this Annotation knows about the key, false otherwise
-
keys
Description copied from interface:Annotation
Get a set of key objects.- Specified by:
keys
in interfaceAnnotation
- Returns:
- a Set of key objects
-
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 interfaceAnnotation
- Returns:
- a Map
-