Package org.biojava.bio.program.tagvalue
Class ValueChanger
- java.lang.Object
-
- org.biojava.bio.program.tagvalue.SimpleTagValueWrapper
-
- org.biojava.bio.program.tagvalue.ValueChanger
-
- All Implemented Interfaces:
TagValueListener,TagValueWrapper
public class ValueChanger extends SimpleTagValueWrapper
Intercept the values associated with some tags and change them systematically.
The two forms of changes that can be made are:
- replace a single value with a new single value (e.g. changing the string "1.87" into a Double object)
- split a single value into multiple values and pass each one individualy on to the delegate e.g. "a, b, c" becomes three values "a", "b", "c".
For a given tag, changers take precendence over splitters, and explicitly registered changers or splitters take precendence over the default handlers. If there is not a specific handler for a tag and there is no default set, then the value is passed on unchanged.
- Since:
- 1.2
- Author:
- Matthew Pocock
-
-
Constructor Summary
Constructors Constructor Description ValueChanger(TagValueListener delegate)ValueChanger(TagValueListener delegate, ChangeTable changeTable)Create a new changer that will pass the modified event stream to a delegate.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ChangeTablegetChangeTable()ChangeTable.ChangergetDefaultChanger()Get the changer that will be applied to values of tags with no specific handler registered.ChangeTable.SplittergetDefaultSplitter()Get the splitter that will be applied to values of tags with no specific handler registered.voidsetChangeTable(ChangeTable changeTable)voidsetDefaultChanger(ChangeTable.Changer c)The changer that will be applied to the values of tags not registered explicitly to any changer or splitter instance.voidsetDefaultSplitter(ChangeTable.Splitter s)The splitter that will be applied to the values of tags not registered explicitly to any changer or splitter instance.voidstartTag(Object tag)Start a new tag.voidvalue(TagValueContext ctxt, Object value)A value has been seen.-
Methods inherited from class org.biojava.bio.program.tagvalue.SimpleTagValueWrapper
endRecord, endTag, getDelegate, setDelegate, startRecord
-
-
-
-
Constructor Detail
-
ValueChanger
public ValueChanger(TagValueListener delegate)
-
ValueChanger
public ValueChanger(TagValueListener delegate, ChangeTable changeTable)
Create a new changer that will pass the modified event stream to a delegate.- Parameters:
delegate- the TagValueListener that will receive the events
-
-
Method Detail
-
setDefaultChanger
public void setDefaultChanger(ChangeTable.Changer c)
The changer that will be applied to the values of tags not registered explicitly to any changer or splitter instance.- Parameters:
c- the default ChangeTable.Changer
-
getDefaultChanger
public ChangeTable.Changer getDefaultChanger()
Get the changer that will be applied to values of tags with no specific handler registered.- Returns:
- the default ChangeTable.Changer, or null
-
setDefaultSplitter
public void setDefaultSplitter(ChangeTable.Splitter s)
The splitter that will be applied to the values of tags not registered explicitly to any changer or splitter instance.- Parameters:
s- the default ChangeTable.Splitter
-
getDefaultSplitter
public ChangeTable.Splitter getDefaultSplitter()
Get the splitter that will be applied to values of tags with no specific handler registered.- Returns:
- the default ChangeTable.Splitter, or null
-
getChangeTable
public ChangeTable getChangeTable()
-
setChangeTable
public void setChangeTable(ChangeTable changeTable)
-
startTag
public void startTag(Object tag) throws ParserException
Description copied from interface:TagValueListenerStart a new tag.- Specified by:
startTagin interfaceTagValueListener- Overrides:
startTagin classSimpleTagValueWrapper- Parameters:
tag- the Object representing the new tag- Throws:
ParserException- if the tag could not be started
-
value
public void value(TagValueContext ctxt, Object value) throws ParserException
Description copied from interface:TagValueListenerA value has been seen.- Specified by:
valuein interfaceTagValueListener- Overrides:
valuein classSimpleTagValueWrapper- Parameters:
ctxt- a TagValueContext that could be used to push a sub-documentvalue- the value Object observed- Throws:
ParserException- if the value could not be processed
-
-