softparsmap
Class StringTemplate

java.lang.Object
  extended bysoftparsmap.StringTemplate

public class StringTemplate
extends java.lang.Object

This class can extract string information from a string template or create a string given a template and data. To clarify see following example.

   StringTemplate st = new StringTemplate("family{number}.tree", "{", "}");
   st.setMarker("{number}", "100");
   System.out.println(st.getPaintedTemplate());
   st.paintTemplate("family200.tree");
   System.out.println(st.getFirstValue("{number}"));
 

This will print

   family100.tree
   200
 


Constructor Summary
StringTemplate(java.lang.String template, java.lang.String startMarker, java.lang.String stopMarker)
          Construct a string template from a template and what markers start and stop with.
 
Method Summary
 java.lang.String getFirstValue(java.lang.String marker)
          Returns the value of the first marker named as given.
 java.lang.String getPaintedTemplate()
          After markers have been set, calling this method will return the template with its markers painted accordingly.
 boolean hasMarker(java.lang.String marker)
          Returns true if the marker exists in the template.
 void paintTemplate(java.lang.String value)
          If the value matches the template the markers will be set to corresponding values.
 void paintTemplateWithMarkerNames()
          Sets the markers with their own names.
 void setMarker(java.lang.String marker, java.lang.String newValue)
          Sets a marker to a new value.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTemplate

public StringTemplate(java.lang.String template,
                      java.lang.String startMarker,
                      java.lang.String stopMarker)
Construct a string template from a template and what markers start and stop with.

Parameters:
template - is the template
startMarker - defines how markers begin
stopMarker - defines how markers end
Method Detail

setMarker

public void setMarker(java.lang.String marker,
                      java.lang.String newValue)
Sets a marker to a new value.

Parameters:
marker - is the marker
newValue - is the new value

paintTemplateWithMarkerNames

public void paintTemplateWithMarkerNames()
Sets the markers with their own names.


getPaintedTemplate

public java.lang.String getPaintedTemplate()
After markers have been set, calling this method will return the template with its markers painted accordingly.

Returns:
the painted marker

paintTemplate

public void paintTemplate(java.lang.String value)
If the value matches the template the markers will be set to corresponding values.

Parameters:
value - is string matching the template

hasMarker

public boolean hasMarker(java.lang.String marker)
Returns true if the marker exists in the template.

Returns:
true if the marker exists in the template

getFirstValue

public java.lang.String getFirstValue(java.lang.String marker)
Returns the value of the first marker named as given.

Parameters:
marker - is the marker
Returns:
the value of the marker