Package org.biojavax.ontology
Class SimpleComparableTriple
- java.lang.Object
-
- org.biojava.utils.AbstractChangeable
-
- org.biojavax.ontology.SimpleComparableTriple
-
- All Implemented Interfaces:
Comparable
,Annotatable
,Term
,Triple
,Changeable
,ComparableTriple
public class SimpleComparableTriple extends AbstractChangeable implements ComparableTriple
Basic comparable triple, BioSQL style.- Since:
- 1.5
- Author:
- Richard Holland
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.biojava.bio.Annotatable
Annotatable.AnnotationForwarder
-
Nested classes/interfaces inherited from interface org.biojava.ontology.Triple
Triple.Impl
-
-
Field Summary
-
Fields inherited from interface org.biojava.bio.Annotatable
ANNOTATION
-
Fields inherited from interface org.biojavax.ontology.ComparableTriple
DESCRIPTOR
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
SimpleComparableTriple()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addDescriptor(ComparableTerm desc)
Adds a descriptor.void
addSynonym(Object synonym)
Add a synonym for this term.int
compareTo(Object o)
Triples are sorted in order of ontology, subject, object, and finally predicate.boolean
equals(Object o)
Check to see if an object is an equivalent Triple.Annotation
getAnnotation()
Should return the associated annotation object.String
getDescription()
Return a human-readable description of this term, or the empty string if none is available.Set
getDescriptors()
Returns all descriptors.Integer
getId()
Gets the Hibernate ID.String
getName()
Return the name of this term.Term
getObject()
Return the object term of this triple.Ontology
getOntology()
Return the ontology in which this term exists.Term
getPredicate()
Return a Term which defines the type of relationship between the subject and object terms.Term
getSubject()
Return the subject term of this tripleObject[]
getSynonyms()
Return the synonyms for this term.int
hashCode()
The hashcode for a Triple.boolean
removeDescriptor(ComparableTerm desc)
Removes a descriptor.void
removeSynonym(Object synonym)
Remove a synonym for this term.void
setDescription(String desc)
set the description of the term;void
setDescriptors(Set descriptors)
Clears the current set of descriptors and replaces it with the content of the set passed.void
setId(Integer id)
Sets the Hibernate ID.String
toString()
Form: "ontology:predicate(subject,object)"-
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, 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
-
SimpleComparableTriple
protected SimpleComparableTriple()
-
-
Method Detail
-
compareTo
public int compareTo(Object o)
Triples are sorted in order of ontology, subject, object, and finally predicate.- Specified by:
compareTo
in interfaceComparable
-
equals
public boolean equals(Object o)
Check to see if an object is an equivalent Triple.Two triples are equivalent if they have the same subject, object and predicate fields.
if (! (o instanceof Triple)) { return false; } Triple to = (Triple) o; return to.getSubject() == getSubject() && to.getObject() == getObject() && to.getPredicate() == getPredicate();
If you do not implement equals in this way then you have no guarantee that your Triple objects will be found in an ontology and that they will not be duplicated. Triples are equal only if they are from the same ontology and share the same subject, object and predicate.
-
hashCode
public int hashCode()
The hashcode for a Triple.This must be implemented as:
return getSubject().hashCode() + 31 * getObject().hashCode() + 31 * 31 * getPredicate().hashCode();
If you do not implement hashcode in this way then you have no guarantee that your Triple objects will be found in an ontology and that they will not be duplicated.
-
getSubject
public Term getSubject()
Return the subject term of this triple- Specified by:
getSubject
in interfaceTriple
- Returns:
- the subject term
-
getPredicate
public Term getPredicate()
Return a Term which defines the type of relationship between the subject and object terms.- Specified by:
getPredicate
in interfaceTriple
- Returns:
- the predicate
-
addDescriptor
public void addDescriptor(ComparableTerm desc) throws IllegalArgumentException, ChangeVetoException
Adds a descriptor. Must not be null.- Specified by:
addDescriptor
in interfaceComparableTriple
- Parameters:
desc
- the descriptor to add.- Throws:
IllegalArgumentException
- if the descriptor is missing.ChangeVetoException
- in case of objections.
-
removeDescriptor
public boolean removeDescriptor(ComparableTerm desc) throws IllegalArgumentException, ChangeVetoException
Removes a descriptor. Must not be null.- Specified by:
removeDescriptor
in interfaceComparableTriple
- Parameters:
desc
- the descriptor to remove.- Returns:
- True if it did it, false if the descriptor did not exist.
- Throws:
IllegalArgumentException
- if the descriptor is missing.ChangeVetoException
- in case of objections.
-
getDescriptors
public Set getDescriptors()
Returns all descriptors. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.- Specified by:
getDescriptors
in interfaceComparableTriple
- Returns:
- a set of all ComparableTerm descriptors, possibly empty.
- See Also:
ComparableTerm
-
setDescriptors
public void setDescriptors(Set descriptors) throws ChangeVetoException
Clears the current set of descriptors and replaces it with the content of the set passed. Warning this method gives access to the original Collection not a copy. This is required by Hibernate. If you modify the object directly the behaviour may be unpredictable.- Specified by:
setDescriptors
in interfaceComparableTriple
- Parameters:
descriptors
- the set of ComparableTerm descriptors to add.- Throws:
ChangeVetoException
- in case of objections.- See Also:
ComparableTerm
-
removeSynonym
public void removeSynonym(Object synonym)
Remove a synonym for this term. NOT IMPLEMENTED- Specified by:
removeSynonym
in interfaceTerm
-
addSynonym
public void addSynonym(Object synonym)
Add a synonym for this term. NOT IMPLEMENTED- Specified by:
addSynonym
in interfaceTerm
- Parameters:
synonym
- the synonym
-
getSynonyms
public Object[] getSynonyms()
Return the synonyms for this term. ALWAYS RETURNS AN EMPTY LIST- Specified by:
getSynonyms
in interfaceTerm
- Returns:
- the synonyms
-
getOntology
public Ontology getOntology()
Return the ontology in which this term exists.- Specified by:
getOntology
in interfaceTerm
- Returns:
- the ontology
-
getDescription
public String getDescription()
Return a human-readable description of this term, or the empty string if none is available. ALWAYS RETURNS THE EMPTY STRING- Specified by:
getDescription
in interfaceTerm
- Returns:
- the description of the term
-
setDescription
public void setDescription(String desc)
set the description of the term; does not do anything- Specified by:
setDescription
in interfaceTerm
-
getAnnotation
public Annotation getAnnotation()
Should return the associated annotation object. ALWAYS RETURNS THE EMPTY ANNOTATION- Specified by:
getAnnotation
in interfaceAnnotatable
- Returns:
- an Annotation object, never null
-
getId
public Integer getId()
Gets the Hibernate ID. Should be used with caution.- Returns:
- the Hibernate ID, if using Hibernate.
-
-