de.marcelsauer.tokenreplacer
Interface TokenReplacer

All Known Implementing Classes:
FiniteStateMachineTokenReplacer, Toky

public interface TokenReplacer

Author:
msauer
See Also:
Toky

Method Summary
 TokenReplacer disableGeneratorCaching()
          turns generator caching OFF.
 TokenReplacer doNotIgnoreMissingValues()
          tells the TokenReplacer to report any tokens that can not be replaced.
 TokenReplacer enableGeneratorCaching()
          turns generator caching ON.
 TokenReplacer ignoreMissingValues()
          tells the TokenReplacer to IGNORE any tokens that can not be replaced.
 TokenReplacer register(java.lang.String[] replacements)
          registers an array of replacements for a string based in indexed tokens.
 TokenReplacer register(java.lang.String token, Generator Generator)
          registers a Token that will be replaced by the given Generator.
 TokenReplacer register(java.lang.String token, java.lang.String value)
          registers a static value for a given token.
 TokenReplacer register(Token token)
          registers a Token that needs to be replaced.
 java.lang.String substitute(java.lang.String toSubstitute)
          replaces all Token with one of the following: the provided static values set via register(String, String) the token registered via register(Token) the generator registered via register(String, Generator)
 TokenReplacer withArgumentDelimiter(java.lang.String argsSep)
           
 TokenReplacer withArgumentEnd(java.lang.String argsEnd)
           
 TokenReplacer withArgumentStart(java.lang.String argsStart)
           
 TokenReplacer withTokenEnd(java.lang.String tokenEnd)
           
 TokenReplacer withTokenStart(java.lang.String tokenStart)
           
 

Method Detail

substitute

java.lang.String substitute(java.lang.String toSubstitute)
replaces all Token with one of the following:

register

TokenReplacer register(java.lang.String token,
                       java.lang.String value)
registers a static value for a given token. if you need dynamic behaviour then use #register(Generator). same as registering a token via register(Token) and supplying a replacement value via Token.replacedBy(String).

Parameters:
token - the name of the token to be replaced e.g. for ${date} -> "date" would be the token, must not be null or empty
value - the static value that will be used when replacing the token, must not be null or empty
Returns:
the TokenReplacer to allow method chaining

register

TokenReplacer register(Token token)
registers a Token that needs to be replaced.

Parameters:
token - the Token, must not be null, the token must have a valid value or generator associated with it which was set via Token.replacedBy(String) or Token.replacedBy(String)
Returns:
the #TokenReplacer to allow method chaining

register

TokenReplacer register(java.lang.String token,
                       Generator Generator)
registers a Token that will be replaced by the given Generator. same as registering a token via register(Token) and supplying a generator via Token.replacedBy(Generator)

Parameters:
token - the name of the token to be replaced e.g. for ${date} -> "date" would be the token, must not be null or empty
generator - the #Generator to use when replacing the value, must not be null or empty
Returns:
the #TokenReplacer to allow method chaining

register

TokenReplacer register(java.lang.String[] replacements)
registers an array of replacements for a string based in indexed tokens. the tokens will be replaced in the order they were added to the array. e.g.
 toky.register(new String[] { "one", "two", "three" });
 toky.substitute("{0} {1} {2}")); // will result in "one two three"
 

Parameters:
replacements - the array of replacements that will be used when replacing an indexed strings, must not be null but can be empty
Returns:
the #TokenReplacer to allow method chaining

withTokenStart

TokenReplacer withTokenStart(java.lang.String tokenStart)
Parameters:
tokenStart - sets the token start identifier to the given value e.g. [dynamic] -> '[' would be the start identifier, e.g. '[', must not be null or empty
Returns:
the #TokenReplacer to allow method chaining

withTokenEnd

TokenReplacer withTokenEnd(java.lang.String tokenEnd)
Parameters:
tokenEnd - sets the token end identifier to the given value e.g. [dynamic] -> ']' would be the end identifier, e.g. '[', must not be null or empty
Returns:
the #TokenReplacer to allow method chaining

withArgumentDelimiter

TokenReplacer withArgumentDelimiter(java.lang.String argsSep)
Parameters:
argsSep - changes the delimiter of the arguments to the given value e.g. {dynamic(1;2;3)} -> ';' would be the delimiter, must not be null or empty
Returns:
the #TokenReplacer to allow method chaining

withArgumentStart

TokenReplacer withArgumentStart(java.lang.String argsStart)
Parameters:
argsStart - sets the argument start identifier to the given value e.g. {dynamic[1;2;3]} -> '[' would be the delimiter e.g. '[', must not be null or empty
Returns:
the #TokenReplacer to allow method chaining

withArgumentEnd

TokenReplacer withArgumentEnd(java.lang.String argsEnd)
Parameters:
argsEnd - sets the argument end identifier to the given value e.g. {dynamic[1;2;3]} -> ']' would be the delimiter e.g. ']', must not be null or empty
Returns:
the #TokenReplacer to allow method chaining

doNotIgnoreMissingValues

TokenReplacer doNotIgnoreMissingValues()
tells the TokenReplacer to report any tokens that can not be replaced. if turned on an IllegalStateException will be thrown during token replacement. reporting errors is turned ON by DEFAULT.

Returns:
the #TokenReplacer to allow method chaining

ignoreMissingValues

TokenReplacer ignoreMissingValues()
tells the TokenReplacer to IGNORE any tokens that can not be replaced. if turned OFF no Exceptions will be thrown during token replacement. reporting errors is turned ON by DEFAULT.

Returns:
the #TokenReplacer to allow method chaining

enableGeneratorCaching

TokenReplacer enableGeneratorCaching()
turns generator caching ON. once a value is determined through a Generator all remaining values with the same token name will be replaced by the cached version. use disableGeneratorCaching() to turn caching off.

Returns:
the #TokenReplacer to allow method chaining

disableGeneratorCaching

TokenReplacer disableGeneratorCaching()
turns generator caching OFF. use enableGeneratorCaching() to turn caching on.

Returns:
the #TokenReplacer to allow method chaining


Copyright © 2011. All Rights Reserved.