de.jstacs.parameters
Class ParameterSetTagger

java.lang.Object
  extended by de.jstacs.parameters.ParameterSetTagger

public class ParameterSetTagger
extends Object

This class implements a tagger for Parameter of ParameterSet. This enable a parameter usage in command line tool. Argument can be parsed from the specific syntax tag<delimiter>value.

This class accesses the ParameterSet via ParameterSet.getParameterAt(int) only once during creation of a new instance (in the constructor). If the number of parameters changes after the creation of a specific instance, this instance will not detect this.

Author:
Jens Keilwagen

Nested Class Summary
static class ParameterSetTagger.KeyEntryComparator<K extends Comparable<K>,V>
          This class implements a comparator on Map.Entry that sorts by the key of the Map.Entry.
 class ParameterSetTagger.RankEntryComparator<K,V>
          This class implements a comparator on Map.Entry where value is a ComparableElement with weight Integer.
 
Constructor Summary
ParameterSetTagger(String[] tags, ParameterSet... sets)
          The constructor creates an new instance by collecting and tagging all parameters of the ParameterSets.
 
Method Summary
 void fillParameters(String delimiter, String... args)
           
 Parameter getParameterFromTag(String tag)
          This method returns the Parameter specified by the tag
 Object getValueFromTag(String tag)
          This method returns the value of the Parameter specified by the tag.
<T> T
getValueFromTag(String tag, Class<T> c)
          This method returns the casted value of the Parameter specified by the tag.
 boolean hasDefaultOrIsSet()
          This method allows to check whether all tagged parameters that require a value also have some value.
 boolean isSet(String tag)
           
 void setValueFromTag(String tag, Object value)
          This method allows to easily set the value of a parameter defined by the tag.
 String toString()
           
 String toString(Comparator<Map.Entry<String,ComparableElement<Parameter,Integer>>> ec)
          This method allows to get a String representation where the tagged parameters are sorted in some specific way.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ParameterSetTagger

public ParameterSetTagger(String[] tags,
                          ParameterSet... sets)
The constructor creates an new instance by collecting and tagging all parameters of the ParameterSets.

Parameters:
tags - the unambiguous tags for all parameters
sets - the sets of Parameters
See Also:
ParameterSet.getNumberOfParameters(), ParameterSet.getParameterAt(int)
Method Detail

fillParameters

public void fillParameters(String delimiter,
                           String... args)
                    throws IllegalArgumentException,
                           SimpleParameter.IllegalValueException
Parameters:
delimiter - the delimiter between each tag and value
args - the arguments, each argument has the form tag<delimiter>value
Throws:
IllegalArgumentException - if any argument could not be assigned to a parameter
SimpleParameter.IllegalValueException - if any argument could not be parsed

getParameterFromTag

public Parameter getParameterFromTag(String tag)
This method returns the Parameter specified by the tag

Parameters:
tag - the tag of the Parameter
Returns:
the Parameter specified by the tag
See Also:
ParameterSet.getParameterAt(int)

isSet

public boolean isSet(String tag)
Parameters:
tag - the tag of the Parameter
Returns:
true if the the parameter is set
See Also:
getParameterFromTag(String), Parameter.isSet()

getValueFromTag

public Object getValueFromTag(String tag)
This method returns the value of the Parameter specified by the tag.

Parameters:
tag - the tag of the Parameter
Returns:
the value of the Parameter specified by the tag
See Also:
getParameterFromTag(String), Parameter.getValue()

getValueFromTag

public <T> T getValueFromTag(String tag,
                             Class<T> c)
This method returns the casted value of the Parameter specified by the tag.

Type Parameters:
T - the type of the class
Parameters:
tag - the tag of the Parameter
c - the class that is used for casting
Returns:
the value of the Parameter specified by the tag
See Also:
getValueFromTag(String)

setValueFromTag

public void setValueFromTag(String tag,
                            Object value)
                     throws SimpleParameter.IllegalValueException
This method allows to easily set the value of a parameter defined by the tag.

Parameters:
tag - the tag of the Parameter
value - the value to be set
Throws:
SimpleParameter.IllegalValueException - if the value could not be set
See Also:
getParameterFromTag(String), Parameter.setValue(Object)

hasDefaultOrIsSet

public boolean hasDefaultOrIsSet()
This method allows to check whether all tagged parameters that require a value also have some value.

Returns:
true if each Parameter that requires a value also has a default value or has been set
See Also:
Parameter.hasDefaultOrIsSet()

toString

public String toString(Comparator<Map.Entry<String,ComparableElement<Parameter,Integer>>> ec)
This method allows to get a String representation where the tagged parameters are sorted in some specific way.

Parameters:
ec - the comparator for sorting
Returns:
a String representation of this instance
See Also:
ParameterSetTagger.KeyEntryComparator, ParameterSetTagger.RankEntryComparator

toString

public String toString()
Overrides:
toString in class Object