|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.knime.core.util.tokenizer.TokenizerSettings
public class TokenizerSettings
Defines the object holding the configuration for the FileTokenizer.
Use an instance of this class to set all parameters and pass it to a
FileTokenizer
. This object is used as a transport vehicle to
first try setting new user configurations and, if everything went fine (i.e.
without any exception), transporting them into the file tokenizer. This class
is used in both directions - to get current tokenizer settings, and to set a
new configuration in the tokenizer. The methods with default permissions are
only used by the file tokenizer to set its current settings in this object -
any object user outside the package will retrieve them then through the
get-methods. While new user settings will be implanted from the
out-of-package world with the set-methods.
Tokenizer
Constructor Summary | |
---|---|
TokenizerSettings()
Creates a new Settings for FileTokenizer object with default settings. |
|
TokenizerSettings(NodeSettingsRO settings)
Creates a new FileTokenizerSettings object and sets its
parameters from the config object. |
|
TokenizerSettings(TokenizerSettings clonee)
Creates a clone of the passed object. |
Method Summary | |
---|---|
void |
addBlockCommentPattern(String commentBegin,
String commentEnd,
boolean returnAsSeparateToken,
boolean includeInToken)
Adds support for block comment to the tokenizer. |
protected void |
addDelimiterPattern(Delimiter delimiter)
Adds a new delimiter pattern expecting a Delimiter object. |
void |
addDelimiterPattern(String delimiter,
boolean combineConsecutiveDelims,
boolean returnAsSeparateToken,
boolean includeInToken)
Adds a delimiter to the tokenizer. |
boolean |
addOrReplaceDelimiterPattern(String delimiter,
boolean combineConsecutiveDelims,
boolean returnAsSeparateToken,
boolean includeInToken)
Replaces the delimiter with the same delimiter pattern overriding the values for combineConsecutiveDelims ,
returnAsSeparateToken , and includeInToken . |
void |
addQuotePattern(String leftQuote,
String rightQuote)
|
void |
addQuotePattern(String leftQuote,
String rightQuote,
boolean dontRemoveQuotes)
|
void |
addQuotePattern(String leftQuote,
String rightQuote,
char escapeChar)
Adds support for the specified quote patterns and escape character. |
void |
addQuotePattern(String leftQuote,
String rightQuote,
char escapeChar,
boolean dontRemoveQuotes)
|
void |
addSingleLineCommentPattern(String commentBegin,
boolean returnAsSeparateToken,
boolean includeInToken)
Adds support for single line comment to the tokenizer. |
protected void |
addStatusOfSettings(SettingsStatus status)
Checks the completeness and consistency of all settings and adds informational messages, warnings, and errors, if something is suspicious. |
void |
addWhiteSpaceCharacter(char w)
This is a convenience method. |
void |
addWhiteSpaceCharacter(String ws)
Defines a new character to be handled as a whitespace character. |
Vector<Comment> |
getAllComments()
|
Vector<Delimiter> |
getAllDelimiters()
|
Vector<Quote> |
getAllQuotes()
|
Vector<String> |
getAllWhiteSpaces()
|
boolean |
getCombineMultipleDelimiters()
|
Delimiter |
getDelimiterPattern(String delimPattern)
Returns the Delimiter object stored for the delimiter with the pattern specified. |
String |
getLineContinuationCharacter()
Returns a string with one character containing the line continuation character that is currently set - or null if none is set. |
SettingsStatus |
getStatusOfSettings()
Method to check consistency and completeness of the current settings. |
static String |
printableStr(String str)
|
void |
removeAllComments()
Removes all (!) comments from the tokenier settings. |
void |
removeAllDelimiters()
Removes all (!) delimiters from the file reader settings. |
void |
removeAllQuotes()
Removes all (!) quotes from the file reader settings. |
void |
removeAllWhiteSpaces()
removes all user defined whitespaces. |
Delimiter |
removeDelimiterPattern(String pattern)
Removes the Delimiter object with the specified pattern from the list of defined delimiters. |
Quote |
removeQuotePattern(String begin,
String end)
Removes the Quote object with the specified patterns from the list of defined quotes. |
void |
saveToConfiguration(NodeSettingsWO cfg)
Saves all settings into a NodeSettings object. |
void |
setCombineMultipleDelimiters(boolean value)
if set true multiple different (but consecutive) delimiters are combined, that is ignored (unless they are supposed to be returned). |
(package private) void |
setComments(Vector<Comment> comments)
sets comment objects to the settings structure. |
(package private) void |
setDelimiters(Vector<Delimiter> delimiters)
sets delimiter objects to the settings structure. |
void |
setLineContinuationCharacter(char c)
Adds support for line continuation in tokens and quoted strings. |
(package private) void |
setQuotes(Vector<Quote> quotes)
sets quote objects to the settings structure. |
(package private) void |
setWhiteSpaces(Vector<String> whites)
sets whitespaces to the settings structure. |
String |
toString()
|
static String |
unescapeString(String str)
takes a string that could contain "\t", or "\n", or "\\", and returns a corresponding string with these patterns replaced by the characters '\t', '\n', '\'. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public TokenizerSettings()
for description of default settings.
public TokenizerSettings(TokenizerSettings clonee)
clonee
- the object to read the settings from.public TokenizerSettings(NodeSettingsRO settings) throws InvalidSettingsException
FileTokenizerSettings
object and sets its
parameters from the config
object. If config doesn't
contain all necessary parameters or contains inconsistent settings it
will throw an InvalidArguments exception
settings
- an object the parameters are read from, if null default
settings will be created.
InvalidSettingsException
- if the config is not validMethod Detail |
---|
public void saveToConfiguration(NodeSettingsWO cfg)
NodeSettings
object. Using the
cfg object to construct a new FileTokenizerSettings object should lead to
an object identical to this.
cfg
- the config object the settings are stored into.public void addQuotePattern(String leftQuote, String rightQuote, char escapeChar)
leftQuote
and rightQuote
as quoted string,
i.e. any token delimiter will not end the token but will be included in
the string and no comment will be recognized inside a quoted string. With
the escape character it is possible to include special characters (like
new line e.g.) or even the right quote pattern in the string. The esc
character and the immediate next char will be translated into one new
character: %EscChar%+'t' becomes '\t' (Tab), +'n' translates int '\n'
(Newline), EscChar+any other char becomes this other character. The
escape character cannot be part of the end pattern. A typical call to
this function adding support for single quotes would be
addQuotePattern("'", "'", "\\"); - support for double quotes
addQuotePattern("\"", "\"", "\\"); - both calls also add support for the
escape character '\'. If you don't want an escape character, use the next
function. The Quote patterns get removed from the token by default. There
are methods that take a flag, if you want them to remain in the token.
leftQuote
- A string containing the left quote pattern.rightQuote
- A string containing the right quote pattern.escapeChar
- The escape character.public void addQuotePattern(String leftQuote, String rightQuote, char escapeChar, boolean dontRemoveQuotes)
leftQuote
- the left quote patternrightQuote
- the right quote patternescapeChar
- the escape character inside a quoted textdontRemoveQuotes
- true if quote patterns should stay in the token,
false, if they should be removed from the returned token.public void addQuotePattern(String leftQuote, String rightQuote)
leftQuote
- The left quot char.rightQuote
- The right quot char.addQuotePattern(String, String, char)
public void addQuotePattern(String leftQuote, String rightQuote, boolean dontRemoveQuotes)
leftQuote
- the left quote patternrightQuote
- the right quote patterndontRemoveQuotes
- true if quote patterns should stay in the token,
false, if they should be removed from the returned token.public Quote removeQuotePattern(String begin, String end)
begin
- the quote begin pattern to matchend
- the quote end pattern to match
public void removeAllQuotes()
public void addDelimiterPattern(String delimiter, boolean combineConsecutiveDelims, boolean returnAsSeparateToken, boolean includeInToken)
includeInToken
set true
), returned in a
separate token ( returnAsSeparateToken
set true
)
or discarded (both set false
). If you set both parameters
true
, it will throw an
IllegalArgumentException
.
Another parameter (
combineConsecutiveDelimis
) will
determine whether delimiters of the same kind immediately following will
be ignored (set to true
) or will cause empty tokens to be
returned (set false
). The delimiter specified must not
prefix any existing delimiter, left quote or comment begin pattern.
delimiter
- A string containing the delimiter.combineConsecutiveDelims
- Pass in true
, if you want
multiple consecutive delimiters to be treated as one, or
false
if empty tokens should be returned
between them.returnAsSeparateToken
- Set to true
to get delimiters
returned as tokens, or false
if they should be
discarded (or included in the tokens - see next parameter).
Mutually exclusive with includeInToken
.includeInToken
- Set to true
if you want the
delimiter returned at the end of the token. Otherwise it will
be discarded (or returned as separate token, see parameter
above). Mutually exclusive with returnAsSeparateToken
.protected void addDelimiterPattern(Delimiter delimiter)
delimiter
- the delimiter to add.public boolean addOrReplaceDelimiterPattern(String delimiter, boolean combineConsecutiveDelims, boolean returnAsSeparateToken, boolean includeInToken)
combineConsecutiveDelims
,
returnAsSeparateToken
, and includeInToken
.
It will return true
, if everything works fine -
false
, if it couldn't find a matching delimiter to
replace.
delimiter
- The pattern matching the delimiter to replace.combineConsecutiveDelims
- New value for this parameter.returnAsSeparateToken
- New value for this parameter.includeInToken
- New value for this parameter.
true
if it replaced the delimiter or false if it
was added.public Delimiter getDelimiterPattern(String delimPattern)
delimPattern
- the string pattern of the delimiter to look for.
public Delimiter removeDelimiterPattern(String pattern)
pattern
- the delimiter to remove
public void removeAllDelimiters()
public void addBlockCommentPattern(String commentBegin, String commentEnd, boolean returnAsSeparateToken, boolean includeInToken)
returnAsSeparateToken
is set true
), included in the token (if
includeInToken
is true
), or discarded (if
both parameters are set false
). (If you specify both
parameters true
it will throw an
IllegalArgumentException
.)
commentBegin
- The string containing a pattern that starts a
comment.commentEnd
- The string containing the end pattern of the comment.
(Must not be a LF ("\n"). Use the next function for line
comment.)returnAsSeparateToken
- Set to true
if the comment
should be returned in a separate token, or false
if it should be discarded, or included in the token (see the
following parameter).includeInToken
- Set true
if a comment should be
returned within the token (at the place where it occured in
the stream), of false, if it should be discarded or returned
as separate token (depending on the parameter above).public void addSingleLineCommentPattern(String commentBegin, boolean returnAsSeparateToken, boolean includeInToken)
returnAsSeparateToken
is set true
), included in the token (if
includeInToken
is true
), or discarded (if
both parameters are set false
). (If you specify both
parameters true
it will throw an
IllegalArgumentException
.)
commentBegin
- The string containing a pattern that starts a single
line comment.returnAsSeparateToken
- Set to true
if the comment
should be returned in a separate token, or false
if it should be discarded, or included in the token (see the
following parameter).includeInToken
- Set true
if a comment should be
returned within the token (at the place where it occured in
the stream), of false, if it should be discarded or returned
as separate token (depending on the parameter above).public void removeAllComments()
public void addWhiteSpaceCharacter(String ws)
ws
- a one character string containing the new whitespace characterpublic void addWhiteSpaceCharacter(char w)
w
- character containing the new whitespace characteraddWhiteSpaceCharacter(String)
public void removeAllWhiteSpaces()
public void setLineContinuationCharacter(char c)
The following two quoted strings are equivalent if '\' is set as line
cont. char: "this is \
considered one line" and "this is considered one line".
c
- The new line continuation character.public String getLineContinuationCharacter()
null
if none is set.public void setCombineMultipleDelimiters(boolean value)
value
- set true to combine multiple different consecutive
delimiters, of false to handle each as seperate delimiter.public boolean getCombineMultipleDelimiters()
public Vector<Comment> getAllComments()
Comment
,
containing all currently defined comment patterns. Could be
emtpy, but never null. The vector is your's if you want it to
change.Comment
public Vector<Quote> getAllQuotes()
Quote
,
containing all currently defined quote patterns. Could be emtpy,
but never null. The vector is your's if you want it to change.Quote
public Vector<Delimiter> getAllDelimiters()
Delimiter
,
containing all currently defined delimiter patterns. Could be
emtpy, but never null. The vector is your's if you want it to
change.Delimiter
public Vector<String> getAllWhiteSpaces()
void setComments(Vector<Comment> comments)
comments
- a Vector of Comment objects to add. Must not be null.void setQuotes(Vector<Quote> quotes)
quotes
- a vector of Quote objects to add. Must not be null.void setDelimiters(Vector<Delimiter> delimiters)
delimiters
- a Vector of delimiter objects to add. Must not be null.void setWhiteSpaces(Vector<String> whites)
whites
- a Vector of one-character strings to set. Must not be null.public String toString()
toString
in class Object
protected void addStatusOfSettings(SettingsStatus status)
status
- an object this methods adds its messages to.public SettingsStatus getStatusOfSettings()
SettingsStatus
object which contains info,
warning and error messages, if something is fishy with the settings.
public static String unescapeString(String str)
str
- a string with escape sequences in
public static String printableStr(String str)
str
- a string. Could be null.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |