Package net.sf.okapi.common.annotation
Class GenericAnnotation
- java.lang.Object
-
- net.sf.okapi.common.resource.InlineAnnotation
-
- net.sf.okapi.common.annotation.GenericAnnotation
-
- All Implemented Interfaces:
Cloneable,IAnnotation,IPersistentAnnotation
- Direct Known Subclasses:
Issue,IssueAnnotation
public class GenericAnnotation extends InlineAnnotation
Generic annotation allowing access with field names and multiple instance on the same object.
-
-
Field Summary
-
Fields inherited from class net.sf.okapi.common.resource.InlineAnnotation
CLASSNAME_SEPARATOR, data
-
-
Constructor Summary
Constructors Constructor Description GenericAnnotation()GenericAnnotation(String type)Creates a new annotation for a given type.GenericAnnotation(String type, Object... list)Creates a new annotation for a given type.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddAnnotation(Code code, GenericAnnotation ann)Adds an annotation to an inline code.static voidaddAnnotation(ITextUnit tu, GenericAnnotation ann)Adds an annotation to a text unit.static voidaddAnnotation(TextContainer tc, GenericAnnotation ann)Adds an annotation to a text container.GenericAnnotationclone()Clones this annotation.static GenericAnnotationcreateFromString(String storage)Creates a new GenericAnnotation object from a storage string.voidfromString(String storage)Initializes this annotation from a storage string originally obtained fromInlineAnnotation.toString().BooleangetBoolean(String name)DoublegetDouble(String name)intgetFieldCount()IntegergetInteger(String name)Set<String>getNames()StringgetString(String name)Gets the string value for a given field.StringgetType()Gets the type of annotation.ObjectgetValue(String name)voidremove(String name)voidsetBoolean(String name, Boolean value)sets a boolean field.voidsetDouble(String name, Double value)voidsetFields(Object... list)Sets a list of key+values pairs for this annotation.voidsetInteger(String name, Integer value)voidsetString(String name, String value)Sets a string field.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
-
-
-
-
Constructor Detail
-
GenericAnnotation
public GenericAnnotation()
-
GenericAnnotation
public GenericAnnotation(String type)
Creates a new annotation for a given type.Note that it is technically to have two annotations with the same type but different fields. This is a side effect of the capability to access the annotation in a generic way. The user is responsible for keeping consistent types of annotations.
- Parameters:
type- the identifier of the type (cannot be null or empty).
-
GenericAnnotation
public GenericAnnotation(String type, Object... list)
Creates a new annotation for a given type. With a list of fields. This method simply call thesetFields(Object...)method after creating the annotation.- Parameters:
type- the identifier of the type (cannot be null or empty).list- the list of key+value pairs to set.
-
-
Method Detail
-
createFromString
public static GenericAnnotation createFromString(String storage)
Creates a new GenericAnnotation object from a storage string.- Parameters:
storage- the serialized representation of the object.- Returns:
- a new GenericAnnotation object.
-
addAnnotation
public static void addAnnotation(ITextUnit tu, GenericAnnotation ann)
Adds an annotation to a text unit. If the text unit has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.- Parameters:
tu- the text unit where to attach the annotation.ann- the annotation to attach (if null, nothing is attached).
-
addAnnotation
public static void addAnnotation(TextContainer tc, GenericAnnotation ann)
Adds an annotation to a text container. If the text container has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.- Parameters:
tc- the text container where to attach the annotation.ann- the annotation to attach (if null, nothing is attached).
-
addAnnotation
public static void addAnnotation(Code code, GenericAnnotation ann)
Adds an annotation to an inline code. If the inline code has no annotation set attached yet one is created and attached, otherwise the annotation to add is added to the existing set.- Parameters:
code- the code where to add the annotation.ann- the annotation to add (if null, nothing is attached).
-
setFields
public void setFields(Object... list)
Sets a list of key+values pairs for this annotation. Each pair must be made of a string that is the name of the field, and an object that is the value to set. The object can be null in that case: the key is not set or deleted. Only supported types must be used.- Parameters:
list- the list of key+value pairs to set.
-
clone
public GenericAnnotation clone()
Description copied from class:InlineAnnotationClones this annotation.- Specified by:
clonein interfaceIPersistentAnnotation- Overrides:
clonein classInlineAnnotation- Returns:
- A new InlineAnnotation object that is a copy of this one.
-
getType
public String getType()
Gets the type of annotation.- Returns:
- the type identifier for the annotation.
-
getString
public String getString(String name)
Gets the string value for a given field.- Parameters:
name- the name of the field.- Returns:
- the field's value as a string.
-
setString
public void setString(String name, String value)
Sets a string field.- Parameters:
name- the name of the field to set.value- the value to set, use null to remove the field.
-
setBoolean
public void setBoolean(String name, Boolean value)
sets a boolean field.- Parameters:
name- the name of the field to set.value- the value to set, use null to remove the field.
-
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.
-
getFieldCount
public int getFieldCount()
-
remove
public void remove(String name)
-
-