Package net.sf.okapi.common.annotation
Class GenericAnnotations
- java.lang.Object
-
- net.sf.okapi.common.resource.InlineAnnotation
-
- net.sf.okapi.common.annotation.GenericAnnotations
-
- All Implemented Interfaces:
Cloneable,Iterable<GenericAnnotation>,IAnnotation,IPersistentAnnotation
- Direct Known Subclasses:
ITSLQIAnnotations,ITSProvenanceAnnotations
public class GenericAnnotations extends InlineAnnotation implements Iterable<GenericAnnotation>
Provides access to a list ofGenericAnnotation. This annotation set assumes its data field is used to store a unique ID for the set.This annotation can be used inline as well as on structural objects.
-
-
Field Summary
-
Fields inherited from class net.sf.okapi.common.resource.InlineAnnotation
CLASSNAME_SEPARATOR, data
-
-
Constructor Summary
Constructors Constructor Description GenericAnnotations()Creates an empty annotation set.GenericAnnotations(String storage)Creates an annotation set initialized with a storage string created withtoString().GenericAnnotations(GenericAnnotation annotation)Creates an annotation set and add a given one.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description GenericAnnotationadd(String type)Creates an new annotation and add it to this object.voidadd(GenericAnnotation annotation)Adds an existing annotation to this object.voidaddAll(List<GenericAnnotation> newItems)Adds all the annotations from a given list to this object.voidaddAll(GenericAnnotations annotations)Adds all annotations of a given set of annotations to this object.static voidaddAnnotations(Code code, GenericAnnotations newSet)Adds a set of annotations to a given inline code.static voidaddAnnotations(IWithAnnotations nameable, GenericAnnotations newSet)Adds a set of annotations to a given INameable object (e.g.voidclear()Removes all annotations from this list.GenericAnnotationsclone()Clones this annotation and make sure its still has a unique ID.static GenericAnnotationscreateFromString(String storage)Creates a new GenericAnnotations object from a storage string.voidfromString(String storage)Initializes this annotation from a storage string originally obtained fromInlineAnnotation.toString().List<GenericAnnotation>getAllAnnotations()Gets the unmodifiable list of all the annotation in this annotation set.List<GenericAnnotation>getAnnotations(String type)Gets a list of all the annotations of a given type.GenericAnnotationgetFirstAnnotation(String type)Gets the first occurrence of an annotation for a given type.booleanhasAnnotation(String type)Indicates if there is at least one annotation of a given type.booleanisEmpty()Returns true if there are terms in this annotation.Iterator<GenericAnnotation>iterator()voidremove(GenericAnnotation annotation)Removes a given annotation from this list.intsize()Gets the number of annotations in this annotation set.StringtoString()Gets a storage string representation of the whole annotation that can be used for serialization.-
Methods inherited from class net.sf.okapi.common.resource.InlineAnnotation
getData, setData
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Constructor Detail
-
GenericAnnotations
public GenericAnnotations()
Creates an empty annotation set.
-
GenericAnnotations
public GenericAnnotations(String storage)
Creates an annotation set initialized with a storage string created withtoString().- Parameters:
storage- the storage string to use.
-
GenericAnnotations
public GenericAnnotations(GenericAnnotation annotation)
Creates an annotation set and add a given one.- Parameters:
annotation- the annotation to add.
-
-
Method Detail
-
createFromString
public static GenericAnnotations createFromString(String storage)
Creates a new GenericAnnotations object from a storage string.- Parameters:
storage- the serialized representation of the object.- Returns:
- a new GenericAnnotations object.
-
addAnnotations
public static void addAnnotations(IWithAnnotations nameable, GenericAnnotations newSet)
Adds a set of annotations to a given INameable object (e.g. TextUnit, TextContainer, etc.). If the object has no annotation set already attached, one is created and attached, otherwise all the annotations of the set passed as argument are added to the existing set.- Parameters:
nameable- the object where to attached the new set.newSet- the new set to add (can be null: then nothing is attached).
-
addAnnotations
public static void addAnnotations(Code code, GenericAnnotations newSet)
Adds a set of annotations to a given inline code. If the inline code has no annotation set attached yet one is created and attached, otherwise all the annotations of the set passed as argument are added to the existing set.- Parameters:
code- the code where to add the annotation.newSet- the new set to add (can be null: then nothing is attached).
-
clone
public GenericAnnotations clone()
Clones this annotation and make sure its still has a unique ID.- Specified by:
clonein interfaceIPersistentAnnotation- Overrides:
clonein classInlineAnnotation- Returns:
- A new InlineAnnotation object that is a copy of this one.
-
size
public int size()
Gets the number of annotations in this annotation set.- Returns:
- the number of annotations in this annotation set.
-
isEmpty
public boolean isEmpty()
Returns true if there are terms in this annotation.- Returns:
- true if terms exist in this annotation.
-
getAnnotations
public List<GenericAnnotation> getAnnotations(String type)
Gets a list of all the annotations of a given type.The returned list is a new list but its items are the same as the items in the original list.
- Parameters:
type- the type of annotation to look for.- Returns:
- the list of all annotations of the given type, the list may be empty but is never null.
-
getFirstAnnotation
public GenericAnnotation getFirstAnnotation(String type)
Gets the first occurrence of an annotation for a given type.- Parameters:
type- the type of annotation to retrieve.- Returns:
- the first annotation of the given type, or null if none exists.
-
getAllAnnotations
public List<GenericAnnotation> getAllAnnotations()
Gets the unmodifiable list of all the annotation in this annotation set.- Returns:
- the live list, or an empty one if there are no annotations.
-
hasAnnotation
public boolean hasAnnotation(String type)
Indicates if there is at least one annotation of a given type.- Parameters:
type- the type of annotation to look for.- Returns:
- true if there is at least one annotation of a given type, false otherwise.
-
clear
public void clear()
Removes all annotations from this list.
-
remove
public void remove(GenericAnnotation annotation)
Removes a given annotation from this list.- Parameters:
annotation- the annotation to remove.
-
add
public GenericAnnotation add(String type)
Creates an new annotation and add it to this object.- Parameters:
type- the type of annotation to create.- Returns:
- the new annotation.
-
add
public void add(GenericAnnotation annotation)
Adds an existing annotation to this object.- Parameters:
annotation- the annotation to add.
-
addAll
public void addAll(GenericAnnotations annotations)
Adds all annotations of a given set of annotations to this object.- Parameters:
annotations- the set of annotations to add.
-
addAll
public void addAll(List<GenericAnnotation> newItems)
Adds all the annotations from a given list to this object.- Parameters:
newItems- the list of annotations to add.
-
toString
public String toString()
Description copied from class:InlineAnnotationGets a storage string representation of the whole annotation that can be used for serialization.- Specified by:
toStringin interfaceIAnnotation- Overrides:
toStringin classInlineAnnotation- Returns:
- The storage string representation of this annotation.
-
fromString
public void fromString(String storage)
Description copied from class:InlineAnnotationInitializes this annotation from a storage string originally obtained fromInlineAnnotation.toString().- Specified by:
fromStringin interfaceIPersistentAnnotation- Overrides:
fromStringin classInlineAnnotation- Parameters:
storage- The storage string to use for the initialization.
-
iterator
public Iterator<GenericAnnotation> iterator()
- Specified by:
iteratorin interfaceIterable<GenericAnnotation>
-
-