Package nl.rrd.wool.model
Class WoolVariableString
- java.lang.Object
-
- nl.rrd.wool.model.WoolVariableString
-
public class WoolVariableString extends Object
This class represents a text with possible variables. It is modelled as a list of segments, where each segment is plain text or a variable.The segments are always normalized so that subsequent plain text segments are automatically merged into one.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classWoolVariableString.Segmentstatic classWoolVariableString.TextSegmentstatic classWoolVariableString.VariableSegment
-
Constructor Summary
Constructors Constructor Description WoolVariableString()WoolVariableString(String text)WoolVariableString(WoolVariableString other)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSegment(WoolVariableString.Segment segment)voidaddSegments(Iterable<WoolVariableString.Segment> segments)Stringevaluate(Map<String,Object> variables)Evaluates this variable string with respect to the specified variables.WoolVariableStringexecute(Map<String,Object> variables)Executes this variable string with respect to the specified variables.voidgetReadVariableNames(Set<String> varNames)Retrieves all variable names that are read in this variable string and adds them to the specified set.List<WoolVariableString.Segment>getSegments()Returns the segments as an unmodifiable list.booleanisPlainText()booleanisWhitespace()voidremoveLeadingWhitespace()voidremoveTrailingWhitespace()StringtoString()StringtoString(char[] escapes)Returns the code string for this instance.voidtrimWhitespace()
-
-
-
Constructor Detail
-
WoolVariableString
public WoolVariableString()
-
WoolVariableString
public WoolVariableString(String text)
-
WoolVariableString
public WoolVariableString(WoolVariableString other)
-
-
Method Detail
-
getSegments
public List<WoolVariableString.Segment> getSegments()
Returns the segments as an unmodifiable list.- Returns:
- the segments as an unmodifiable list
-
addSegment
public void addSegment(WoolVariableString.Segment segment)
-
addSegments
public void addSegments(Iterable<WoolVariableString.Segment> segments)
-
execute
public WoolVariableString execute(Map<String,Object> variables)
Executes this variable string with respect to the specified variables. The result will be a string with 0 or 1 text segments. Undefined variables will be evaluated as string "null".- Parameters:
variables- the variable map (can be null)- Returns:
- the processed variable string
-
evaluate
public String evaluate(Map<String,Object> variables)
Evaluates this variable string with respect to the specified variables. Undefined variables will be evaluated as string "null".- Parameters:
variables- the variable map (can be null)- Returns:
- the evaluated string
-
getReadVariableNames
public void getReadVariableNames(Set<String> varNames)
Retrieves all variable names that are read in this variable string and adds them to the specified set.- Parameters:
varNames- the set to which the variable names are added
-
isWhitespace
public boolean isWhitespace()
-
isPlainText
public boolean isPlainText()
-
trimWhitespace
public void trimWhitespace()
-
removeLeadingWhitespace
public void removeLeadingWhitespace()
-
removeTrailingWhitespace
public void removeTrailingWhitespace()
-
toString
public String toString(char[] escapes)
Returns the code string for this instance. It will escape \ and $ with a backslash. You may specify additional characters to escape.- Parameters:
escapes- the characters to escape- Returns:
- the code string
-
-