org.josql.functions
Class StringFunctions

java.lang.Object
  extended by org.josql.functions.AbstractFunctionHandler
      extended by org.josql.functions.StringFunctions
All Implemented Interfaces:
FunctionHandler

public class StringFunctions
extends AbstractFunctionHandler

This class holds functions that operate on strings in some way.


Field Summary
static String HANDLER_ID
           
 
Fields inherited from class org.josql.functions.AbstractFunctionHandler
q
 
Constructor Summary
StringFunctions()
           
 
Method Summary
 List grep(File f, String s)
          grep through a file, line by line, and determine what matches there are to the nominated String.
 List grep(File f, String s, boolean ignoreCase)
          grep through a file, line by line, and determine what matches there are to the nominated String.
 double lastIndexOf(Object o, Object i)
          A thinly veiled wrapper around the String.lastIndexOf(String) method.
 double length(Object o)
           
 boolean regexp(Object o, String re)
          Match a regular expression against the object passed in.
 boolean regexp(Object o, String re, String instName)
          Match a regular expression against the object passed in using the specified regular expression library, pre-defined library names can be found in: RegExpFactory.
 List rgrep(File f, String regexp)
          grep through a file, line by line, and determine what matches there are to the nominated regular expression.
 List rgrep(File f, String regexp, String instName)
          grep through a file, line by line, and determine what matches there are to the nominated regular expression using the specified regular expression implementation.
 String subStr(Object o, double f)
          Return a substring of the passed in object (in a string form).
 String subStr(Object o, double f, double t)
          A function to return a substring of a String.
 String trim(Object o, Object v)
          Given a string trim the passed in string from the front and end, set v to null to have just whitespace trimmed.
 
Methods inherited from class org.josql.functions.AbstractFunctionHandler
setQuery
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HANDLER_ID

public static final String HANDLER_ID
See Also:
Constant Field Values
Constructor Detail

StringFunctions

public StringFunctions()
Method Detail

regexp

public boolean regexp(Object o,
                      String re)
               throws QueryExecutionException
Match a regular expression against the object passed in.

Parameters:
o - The object to match against, toString is called on the object.
re - The regular expression to match.
Returns:
true if the expression matches.
Throws:
QueryExecutionException - If the match cannot be performed, or if there is no suitable regular expression library available to the RegExpFactory.

regexp

public boolean regexp(Object o,
                      String re,
                      String instName)
               throws QueryExecutionException
Match a regular expression against the object passed in using the specified regular expression library, pre-defined library names can be found in: RegExpFactory.

Parameters:
o - The object to match against, toString is called on the object.
re - The regular expression to match.
instName - The name of the regular expression library to use.
Returns:
true if the expression matches.
Throws:
QueryExecutionException - If the match cannot be performed, or if the instName regular expression library is not available to the RegExpFactory.

grep

public List grep(File f,
                 String s,
                 boolean ignoreCase)
          throws QueryExecutionException
grep through a file, line by line, and determine what matches there are to the nominated String. Return a List of FileMatch objects.

Parameters:
f - The File to match against.
s - The string to match.
ignoreCase - If set to true then the case of the line and string to match are ignored.
Returns:
The List of FileMatch objects.
Throws:
QueryExecutionException

rgrep

public List rgrep(File f,
                  String regexp,
                  String instName)
           throws QueryExecutionException
grep through a file, line by line, and determine what matches there are to the nominated regular expression using the specified regular expression implementation. Return a List of FileMatch objects.

Parameters:
f - The File to match against.
regexp - The regular expression to match against each line. This will use the default regular expression library. In this case the location of the match (i.e. FileMatch.getColumn()) will be -1 since the regular expression handling does not support location matching. Also, FileMatch.getString() will contain the regular expression used.
instName - The instance name to use.
Returns:
The List of FileMatch objects.
Throws:
QueryExecutionException - If the default regular expression implementation is not available or if the file cannot be read.

rgrep

public List rgrep(File f,
                  String regexp)
           throws QueryExecutionException
grep through a file, line by line, and determine what matches there are to the nominated regular expression. Return a List of FileMatch objects.

Parameters:
f - The File to match against.
regexp - The regular expression to match against each line. This will use the default regular expression library. In this case the location of the match (i.e. FileMatch.getColumn()) will be -1 since the regular expression handling does not support location matching. Also, FileMatch.getString() will contain the regular expression used.
Returns:
The List of FileMatch objects.
Throws:
QueryExecutionException - If the default regular expression implementation is not available or if the file cannot be read.

grep

public List grep(File f,
                 String s)
          throws QueryExecutionException
grep through a file, line by line, and determine what matches there are to the nominated String. Return a List of FileMatch objects.

Parameters:
f - The File to match against.
s - The string to match.
Returns:
The List of FileMatch objects.
Throws:
QueryExecutionException

trim

public String trim(Object o,
                   Object v)
Given a string trim the passed in string from the front and end, set v to null to have just whitespace trimmed. Both are converted to strings first.

Parameters:
o - The string to trim.
v - The string to trim from the front and end. Set to null to just trim whitespace.
Returns:
The trimmed string.

lastIndexOf

public double lastIndexOf(Object o,
                          Object i)
A thinly veiled wrapper around the String.lastIndexOf(String) method. Both o and i are converted to Strings and then the "lastIndexoOf" method is called on o with i as the argument.

Parameters:
o - The string to search.
i - The string to match.
Returns:
The last index of i within o. If o is null then -1 is returned. If i is null then -1 is returned.

subStr

public String subStr(Object o,
                     double f)
Return a substring of the passed in object (in a string form). See subStr(Object,double,double) for the full details since this is just a thin-wrapper around that method with the t parameter set to -1.

Parameters:
o - The object to convert to a string and return the substring.
f - The start index. If this is set to 0 then the entire string is returned.
Returns:
The substring.

subStr

public String subStr(Object o,
                     double f,
                     double t)
A function to return a substring of a String. If the passed in object isn't a string then it is converted to a string before processing.

Parameters:
o - The object to convert to a string and return the substring.
f - The start index. If it's < 0 then "" is returned. If the start is out of range of the string then "" is returned.
t - The end index. If it's > f then it is reset to -1. If it's -1 then it's ignored and the substring from the start is used. If the end is greater than the length of the string then it is ignored.
Returns:
The substring.

length

public double length(Object o)


  Copyright © 2008 Gary Bentley. All Rights Reserved.