org.teatrove.tea.runtime
Class DefaultContext

java.lang.Object
  extended by java.io.Writer
      extended by org.teatrove.tea.runtime.DefaultContext
All Implemented Interfaces:
Closeable, Flushable, Appendable, Context, OutputReceiver, UtilityContext
Direct Known Subclasses:
TestCompiler.Context

public abstract class DefaultContext
extends Writer
implements UtilityContext

The default runtime context class that Tea templates get compiled to use. All functions callable from a template are defined in the context. To add more or override existing ones, do so when extending this class.

Author:
Brian S O'Neill

Nested Class Summary
static class DefaultContext.GenericComparator
           
static class DefaultContext.StringComparator
           
 
Field Summary
 
Fields inherited from class java.io.Writer
lock
 
Constructor Summary
DefaultContext()
           
 
Method Summary
 void append(StringBuilder buffer, Object value)
          A function to append a value to an existing buffer.
 String cardinal(long n)
          A function that converts an integer to a cardinal value.
 String cardinal(Long n)
          A function that converts an integer to a cardinal value.
 void close()
           
 StringBuilder createStringBuilder()
          A function that creates a string builder to allow programs to perform concatenation and pass around strings.
 StringBuilder createStringBuilder(int size)
          A function that creates a string builder to allow programs to perform concatenation and pass around strings.
 Date currentDate()
          Returns a standard Java Date object with the current date and time.
 org.joda.time.DateTime currentDateTime()
          Returns a Joda DateTime object with the current date and time.
 void dateFormat(String format)
          Defines a format to use when printing dates from templates.
 void dateFormat(String format, String timeZoneID)
          A function that sets the formatted value of dates.
 boolean endsWith(String str, String suffix)
          Tests if the given string ends with the given suffix.
 int[] find(String str, String search)
          Finds the indices for each occurrence of the given search string in the source string.
 int[] find(String str, String search, int fromIndex)
          Finds the indices for each occurrence of the given search string in the source string, starting from the given index.
 int findFirst(String str, String search)
          Finds the index of the first occurrence of the given search string in the source string, or -1 if not found.
 int findFirst(String str, String search, int fromIndex)
          Finds the index of the first occurrence of the given search string in the source string, starting from the given index, or -1 if not found.
 int findLast(String str, String search)
          Finds the index of the last occurrence of the given search string in the source string, or -1 if not found.
 int findLast(String str, String search, int fromIndex)
          Finds the index of the last occurrence of the given search string in the source string, starting from the given index, or -1 if not found.
 void flush()
           
 Locale[] getAvailableLocales()
          Returns a list of all the available locales.
 TimeZone[] getAvailableTimeZones()
          Returns a list of all the available time zones.
 String getDateFormat()
          Returns the current date format specification.
 String getDateFormatTimeZone()
          Returns the current date format time zone.
 Locale getLocale()
          Returns the current locale setting.
 String getNullFormat()
          Returns the current null format specification.
 String getNumberFormat()
          Returns the current number format specification.
 String getNumberFormatInfinity()
          Returns the current number format for infinity.
 String getNumberFormatNaN()
          Returns the current number format for NaN.
 void insert(StringBuilder buffer, Object value, int index)
          A function to insert a value into an existing buffer.
 boolean isArray(Object o)
          A function that checks if an object is an Array
 void nullFormat(String format)
          A function that sets the formatted value of null object references.
 void numberFormat(String format)
          A function that sets the formatted value of numbers.
 void numberFormat(String format, String infinity, String NaN)
          A function that sets the formatted value of numbers.
 String ordinal(long n)
          A function that converts an integer to an ordinal value.
 String ordinal(Long n)
          A function that converts an integer to an ordinal value.
 void prepend(StringBuilder buffer, Object value)
          A function to prepend a value to an existing buffer.
 void print(Date date)
           
 void print(double n)
           
 void print(float n)
           
 void print(int n)
           
 void print(long n)
           
 void print(Number n)
           
abstract  void print(Object obj)
          Method that is the runtime receiver.
 void print(org.joda.time.ReadableInstant instant)
           
<K,V> String
replace(String source, Map<K,V> patternReplacements)
          Applies string replacements using the pattern-replacement pairs provided by the given map (associative array).
 String replace(String source, String pattern, String replacement)
          Replaces all exact matches of the given pattern in the source string with the provided replacement.
 String replace(String source, String pattern, String replacement, int fromIndex)
          Replaces all exact matches of the given pattern in the source string with the provided replacement, starting from the given index.
 String replaceFirst(String source, String pattern, String replacement)
          Replaces the first exact match of the given pattern in the source string with the provided replacement.
 String replaceFirst(String source, String pattern, String replacement, int fromIndex)
          Replaces the first exact match of the given pattern in the source string with the provided replacement, starting from the given index.
 String replaceLast(String source, String pattern, String replacement)
          Replaces the last exact match of the given pattern in the source string with the provided replacement.
 String replaceLast(String source, String pattern, String replacement, int fromIndex)
          Replaces the last exact match of the given pattern in the source string with the provided replacement, starting from the given index.
 void setLocale(Locale locale)
          Setting the locale resets date and number formats to the default for that locale.
 void setLocale(String language, String country)
          Setting the locale resets date and number formats to the default for that locale.
 void setLocale(String language, String country, String variant)
          Setting the locale resets date and number formats to the default for that locale.
 String shortOrdinal(long n)
          A function that converts an integer to a short ordinal value.
 String shortOrdinal(Long n)
          A function that converts an integer to a short ordinal value.
 void sort(Object[] array, boolean sortAscending)
           
 void sort(Object[] array, String[] onColumns, boolean[] reverse)
           
 void sort(Object[] array, String onColumn, boolean reverse)
           
 void sort(String[] array, boolean reverse, boolean ignoreCase)
           
 void sortAscending(byte[] array)
           
 void sortAscending(double[] array)
           
 void sortAscending(float[] array)
           
 void sortAscending(int[] array)
           
 void sortAscending(long[] array)
           
 void sortAscending(Object[] array)
           
 void sortAscending(short[] array)
           
 String[] split(String str, String regex)
           
 boolean startsWith(String str, String prefix)
          Tests if the given string starts with the given prefix.
 String substring(String str, int startIndex)
          Returns the trailing end of the given string, starting from the given index.
 String substring(String str, int startIndex, int endIndex)
          Returns a sub-portion of the given string for the characters that are at or after the starting index, and are before the end index.
 String toLowerCase(String str)
          Converts all the characters in the given string to lowercase.
 String toString(Date date)
          A function that converts a date to a string, using the current datetime format.
 String toString(double n)
          A function that converts a number to a string, using the current number format.
 String toString(float n)
          A function that converts a number to a string, using the current number format.
 String toString(int n)
          A function that converts a number to a string, using the current number format.
 String toString(long n)
          A function that converts a number to a string, using the current number format.
 String toString(Number n)
          A function that converts a number to a string, using the current number format.
 String toString(Object obj)
          A function that converts an object to a string, applying any applicable formatting settings.
 String toString(org.joda.time.ReadableInstant instant)
          A function that converts an instant in time to a string, using the current datetime format.
 String toString(String str)
          A function that converts a string to the null format string if it is null.
 String toString(StringBuilder buffer)
          A function to convert the buffer into a standard string.
 String toUpperCase(String str)
          Converts all the characters in the given string to uppercase.
 String trim(String str)
          Trims all leading and trailing whitespace characters from the given string.
 String trimLeading(String str)
          Trims all leading whitespace characters from the given string.
 String trimTrailing(String str)
          Trims all trailing whitespace characters from the given string.
 void write(char[] cbuf, int off, int len)
           
 void write(int c)
           
 
Methods inherited from class java.io.Writer
append, append, append, write, write, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.teatrove.tea.runtime.OutputReceiver
write, write, write
 

Constructor Detail

DefaultContext

public DefaultContext()
Method Detail

write

public void write(int c)
           throws IOException
Specified by:
write in interface OutputReceiver
Overrides:
write in class Writer
Throws:
IOException

write

public void write(char[] cbuf,
                  int off,
                  int len)
           throws IOException
Specified by:
write in interface OutputReceiver
Specified by:
write in class Writer
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Specified by:
flush in class Writer
Throws:
IOException

close

public void close()
           throws IOException
Specified by:
close in interface Closeable
Specified by:
close in class Writer
Throws:
IOException

print

public abstract void print(Object obj)
                    throws Exception
Method that is the runtime receiver. Implementations should call one of the toString methods when converting this object to a string.

NOTE: This method should not be called directly within a template.

Specified by:
print in interface Context
Specified by:
print in interface OutputReceiver
Throws:
Exception
See Also:
Compiler.getRuntimeReceiver()

print

public void print(Date date)
           throws Exception
Specified by:
print in interface Context
Throws:
Exception

print

public void print(org.joda.time.ReadableInstant instant)
           throws Exception
Specified by:
print in interface Context
Throws:
Exception

print

public void print(Number n)
           throws Exception
Specified by:
print in interface Context
Throws:
Exception

print

public void print(int n)
           throws Exception
Specified by:
print in interface Context
Throws:
Exception

print

public void print(float n)
           throws Exception
Specified by:
print in interface Context
Throws:
Exception

print

public void print(long n)
           throws Exception
Specified by:
print in interface Context
Throws:
Exception

print

public void print(double n)
           throws Exception
Specified by:
print in interface Context
Throws:
Exception

toString

public String toString(Object obj)
Description copied from interface: Context
A function that converts an object to a string, applying any applicable formatting settings. The returned String is never null.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(String str)
Description copied from interface: Context
A function that converts a string to the null format string if it is null. Otherwise, it is returned unchanged.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(Date date)
Description copied from interface: Context
A function that converts a date to a string, using the current datetime format.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(org.joda.time.ReadableInstant instant)
Description copied from interface: Context
A function that converts an instant in time to a string, using the current datetime format.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(Number n)
Description copied from interface: Context
A function that converts a number to a string, using the current number format.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(int n)
Description copied from interface: Context
A function that converts a number to a string, using the current number format.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(float n)
Description copied from interface: Context
A function that converts a number to a string, using the current number format.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(long n)
Description copied from interface: Context
A function that converts a number to a string, using the current number format.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

toString

public String toString(double n)
Description copied from interface: Context
A function that converts a number to a string, using the current number format.

Specified by:
toString in interface Context
See Also:
Compiler.getRuntimeStringConverter()

setLocale

public void setLocale(Locale locale)
Description copied from interface: Context
Setting the locale resets date and number formats to the default for that locale. Setting a locale of null resets date and number formats to the system defaults.

See getAvailableLocales to get all the available language, country and variant codes.

Specified by:
setLocale in interface Context
Parameters:
locale - pre-constructed locale object

setLocale

public void setLocale(String language,
                      String country)
Description copied from interface: Context
Setting the locale resets date and number formats to the default for that locale.

Specified by:
setLocale in interface Context
Parameters:
language - language code
country - country code

setLocale

public void setLocale(String language,
                      String country,
                      String variant)
Description copied from interface: Context
Setting the locale resets date and number formats to the default for that locale.

Specified by:
setLocale in interface Context
Parameters:
language - language code
country - country code
variant - optional variant code

getLocale

public Locale getLocale()
Description copied from interface: Context
Returns the current locale setting.

Specified by:
getLocale in interface Context

getAvailableLocales

public Locale[] getAvailableLocales()
Description copied from interface: Context
Returns a list of all the available locales.

Specified by:
getAvailableLocales in interface Context

nullFormat

public void nullFormat(String format)
Description copied from interface: Context
A function that sets the formatted value of null object references.

Specified by:
nullFormat in interface Context
Parameters:
format - string to print in place of "null".

getNullFormat

public String getNullFormat()
Description copied from interface: Context
Returns the current null format specification.

Specified by:
getNullFormat in interface Context

dateFormat

public void dateFormat(String format)
Description copied from interface: Context
Defines a format to use when printing dates from templates. Passing null sets the format back to the default.

Time Format Syntax:

To specify the time format use a time pattern string. In this pattern, all ASCII letters are reserved as pattern letters, which are defined as the following:

 
 Symbol   Meaning                 Presentation        Example 
 ------   -------                 ------------        ------- 
 G        era designator          (Text)              AD 
 y        year                    (Number)            1996 
 M        month in year           (Text & Number)     July & 07 
 d        day in month            (Number)            10 
 h        hour in am/pm (1~12)    (Number)            12 
 H        hour in day (0~23)      (Number)            0 
 m        minute in hour          (Number)            30 
 s        second in minute        (Number)            55 
 S        millisecond             (Number)            978 
 E        day in week             (Text)              Tuesday 
 D        day in year             (Number)            189 
 F        day of week in month    (Number)            2 (2nd Wed in July)
 w        week in year            (Number)            27 
 W        week in month           (Number)            2 
 a        am/pm marker            (Text)              PM 
 k        hour in day (1~24)      (Number)            24 
 K        hour in am/pm (0~11)    (Number)            0 
 z        time zone               (Text)              Pacific Standard Time 
 '        escape for text         (Delimiter) 
 ''       single quote            (Literal)           ' 
 
The count of pattern letters determine the format.

(Text): 4 or more pattern letters--use full form, less than 4--use short or abbreviated form if one exists.

(Number): the minimum number of digits. Shorter numbers are zero-padded to this amount. Year is handled specially; that is, if the count of 'y' is 2, the Year will be truncated to 2 digits.

(Text & Number): 3 or over, use text, otherwise use number.

Any characters in the pattern that are not in the ranges of ['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance, characters like ':', '.', ' ', '#' and '@' will appear in the resulting time text even they are not embraced within single quotes.

A pattern containing any invalid pattern letter will result in a thrown exception during formatting or parsing.

Examples:

 
 Format Pattern                         Result 
 --------------                         ------- 
 "yyyy.MM.dd G 'at' hh:mm:ss z"    ->>  1996.07.10 AD at 15:08:56 PDT 
 "EEE, MMM d, ''yy"                ->>  Wed, July 10, '96 
 "h:mm a"                          ->>  12:08 PM 
 "hh 'o''clock' a, zzzz"           ->>  12 o'clock PM, Pacific Daylight Time 
 "K:mm a, z"                       ->>  0:00 PM, PST 
 "yyyyy.MMMMM.dd GGG hh:mm aaa"    ->>  1996.July.10 AD 12:08 PM 
 

Specified by:
dateFormat in interface Context
Parameters:
format - date format specification string

dateFormat

public void dateFormat(String format,
                       String timeZoneID)
Description copied from interface: Context
A function that sets the formatted value of dates.

Specified by:
dateFormat in interface Context
Parameters:
format - date format specification string
timeZoneID - time zone ID, i.e. "PST"

getDateFormat

public String getDateFormat()
Description copied from interface: Context
Returns the current date format specification.

Specified by:
getDateFormat in interface Context

getDateFormatTimeZone

public String getDateFormatTimeZone()
Description copied from interface: Context
Returns the current date format time zone.

Specified by:
getDateFormatTimeZone in interface Context

getAvailableTimeZones

public TimeZone[] getAvailableTimeZones()
Description copied from interface: Context
Returns a list of all the available time zones.

Specified by:
getAvailableTimeZones in interface Context

numberFormat

public void numberFormat(String format)
Description copied from interface: Context
A function that sets the formatted value of numbers. Defines a format to use when printing numbers from templates. Passing null sets the format back to the default. The format string is of the form "#.#".

Here are the special characters used in the parts of the format string, with notes on their usage.

 
 Symbol   Meaning 
 ------   ------- 
 0        a digit 
 #        a digit, zero shows as absent 
 .        placeholder for decimal separator. 
 ,        placeholder for grouping separator. 
 ;        separates formats. 
 -        default negative prefix. 
 %        multiply by 100 and show as percentage 
 ?        multiply by 1000 and show as per mille 
 ¤        currency sign; replaced by currency symbol;
          if doubled, replaced by international currency 
          symbol. If present in a pattern, the monetary
          decimal separator is used instead of the decimal 
          separator. (Unicode escape is \\u00a4) 
 X        any other characters can be used in the prefix or suffix 
 '        used to quote special characters in a prefix or suffix. 
 

Specified by:
numberFormat in interface Context
Parameters:
format - number format specification string

numberFormat

public void numberFormat(String format,
                         String infinity,
                         String NaN)
Description copied from interface: Context
A function that sets the formatted value of numbers. Defines a format to use when printing numbers from templates. Passing null sets the format back to the default. The format string is of the form "#.#".

Here are the special characters used in the parts of the format string, with notes on their usage.

 
 Symbol   Meaning 
 ------   ------- 
 0        a digit 
 #        a digit, zero shows as absent 
 .        placeholder for decimal separator. 
 ,        placeholder for grouping separator. 
 ;        separates formats. 
 -        default negative prefix. 
 %        multiply by 100 and show as percentage 
 ?        multiply by 1000 and show as per mille 
 ¤        currency sign; replaced by currency symbol;
          if doubled, replaced by international currency 
          symbol. If present in a pattern, the monetary
          decimal separator is used instead of the decimal 
          separator. (Unicode escape is \\u00a4) 
 X        any other characters can be used in the prefix or suffix 
 '        used to quote special characters in a prefix or suffix. 
 

Specified by:
numberFormat in interface Context
Parameters:
format - number format specification string
infinity - display string for infinity
NaN - display string for not-a-number, resulting from zero divided by zero.

getNumberFormat

public String getNumberFormat()
Description copied from interface: Context
Returns the current number format specification.

Specified by:
getNumberFormat in interface Context

getNumberFormatInfinity

public String getNumberFormatInfinity()
Description copied from interface: Context
Returns the current number format for infinity.

Specified by:
getNumberFormatInfinity in interface Context

getNumberFormatNaN

public String getNumberFormatNaN()
Description copied from interface: Context
Returns the current number format for NaN.

Specified by:
getNumberFormatNaN in interface Context

currentDate

public Date currentDate()
Description copied from interface: UtilityContext
Returns a standard Java Date object with the current date and time.

Specified by:
currentDate in interface UtilityContext

currentDateTime

public org.joda.time.DateTime currentDateTime()
Description copied from interface: UtilityContext
Returns a Joda DateTime object with the current date and time.

Specified by:
currentDateTime in interface UtilityContext

startsWith

public boolean startsWith(String str,
                          String prefix)
Description copied from interface: UtilityContext
Tests if the given string starts with the given prefix. Returns true if the given string starts with the given prefix.

Specified by:
startsWith in interface UtilityContext
Parameters:
str - the source string
prefix - the prefix to test for
Returns:
true if the given string starts with the given prefix

endsWith

public boolean endsWith(String str,
                        String suffix)
Description copied from interface: UtilityContext
Tests if the given string ends with the given suffix. Returns true if the given string ends with the given suffix.

Specified by:
endsWith in interface UtilityContext
Parameters:
str - the source string
suffix - the suffix to test for
Returns:
true if the given string ends with the given suffix

find

public int[] find(String str,
                  String search)
Description copied from interface: UtilityContext
Finds the indices for each occurrence of the given search string in the source string. Returns an array of indices, which is empty if the search string wasn't found

Specified by:
find in interface UtilityContext
Parameters:
str - the source string
search - the string to search for
Returns:
an array of indices, which is empty if the search string wasn't found

find

public int[] find(String str,
                  String search,
                  int fromIndex)
Description copied from interface: UtilityContext
Finds the indices for each occurrence of the given search string in the source string, starting from the given index.

Specified by:
find in interface UtilityContext
Parameters:
str - the source string
search - the string to search for
fromIndex - index to start the find
Returns:
an array of indices, which is empty if the search string wasn't found

findFirst

public int findFirst(String str,
                     String search)
Description copied from interface: UtilityContext
Finds the index of the first occurrence of the given search string in the source string, or -1 if not found.

Specified by:
findFirst in interface UtilityContext
Parameters:
str - the source string
search - the string to search for
Returns:
the start index of the found string or -1 if not found

findFirst

public int findFirst(String str,
                     String search,
                     int fromIndex)
Description copied from interface: UtilityContext
Finds the index of the first occurrence of the given search string in the source string, starting from the given index, or -1 if not found.

Specified by:
findFirst in interface UtilityContext
Parameters:
str - the source string
search - the string to search for
fromIndex - index to start the find
Returns:
the start index of the found string or -1 if not found

findLast

public int findLast(String str,
                    String search)
Description copied from interface: UtilityContext
Finds the index of the last occurrence of the given search string in the source string, or -1 if not found.

Specified by:
findLast in interface UtilityContext
Parameters:
str - the source string
search - the string to search for
Returns:
the start index of the found string or -1 if not found

findLast

public int findLast(String str,
                    String search,
                    int fromIndex)
Description copied from interface: UtilityContext
Finds the index of the last occurrence of the given search string in the source string, starting from the given index, or -1 if not found.

Specified by:
findLast in interface UtilityContext
Parameters:
str - the source string
search - the string to search for
fromIndex - optional index to start the find
Returns:
the start index of the found string or -1 if not found

substring

public String substring(String str,
                        int startIndex)
Description copied from interface: UtilityContext
Returns the trailing end of the given string, starting from the given index.

Specified by:
substring in interface UtilityContext
Parameters:
str - the source string
startIndex - the start index, inclusive
Returns:
the specified substring.

substring

public String substring(String str,
                        int startIndex,
                        int endIndex)
Description copied from interface: UtilityContext
Returns a sub-portion of the given string for the characters that are at or after the starting index, and are before the end index.

Specified by:
substring in interface UtilityContext
Parameters:
str - the source string
startIndex - the start index, inclusive
endIndex - the ending index, exclusive
Returns:
the specified substring.

toLowerCase

public String toLowerCase(String str)
Description copied from interface: UtilityContext
Converts all the characters in the given string to lowercase.

Specified by:
toLowerCase in interface UtilityContext
Parameters:
str - the string to convert
Returns:
the string converted to lowercase

toUpperCase

public String toUpperCase(String str)
Description copied from interface: UtilityContext
Converts all the characters in the given string to uppercase.

Specified by:
toUpperCase in interface UtilityContext
Parameters:
str - the string to convert
Returns:
the string converted to uppercase

trim

public String trim(String str)
Description copied from interface: UtilityContext
Trims all leading and trailing whitespace characters from the given string.

Specified by:
trim in interface UtilityContext
Parameters:
str - the string to trim
Returns:
the trimmed string

trimLeading

public String trimLeading(String str)
Description copied from interface: UtilityContext
Trims all leading whitespace characters from the given string.

Specified by:
trimLeading in interface UtilityContext
Parameters:
str - the string to trim
Returns:
the trimmed string

trimTrailing

public String trimTrailing(String str)
Description copied from interface: UtilityContext
Trims all trailing whitespace characters from the given string.

Specified by:
trimTrailing in interface UtilityContext
Parameters:
str - the string to trim
Returns:
the trimmed string

shortOrdinal

public String shortOrdinal(Long n)
Description copied from interface: UtilityContext
A function that converts an integer to a short ordinal value. i.e. 1st, 2nd, 3rd etc.

Specified by:
shortOrdinal in interface UtilityContext
Parameters:
n - the number to convert
Returns:
a String containing the short ordinal value of the specified number

shortOrdinal

public String shortOrdinal(long n)
Description copied from interface: UtilityContext
A function that converts an integer to a short ordinal value. i.e. 1st, 2nd, 3rd etc.

Specified by:
shortOrdinal in interface UtilityContext
Parameters:
n - the number to convert
Returns:
a String containing the short ordinal value of the specified number

ordinal

public String ordinal(Long n)
Description copied from interface: UtilityContext
A function that converts an integer to an ordinal value. i.e. first, second, third etc.

Specified by:
ordinal in interface UtilityContext
Parameters:
n - the number to convert
Returns:
a String containing the ordinal value of the specified number

ordinal

public String ordinal(long n)
Description copied from interface: UtilityContext
A function that converts an integer to an ordinal value. i.e. first, second, third etc.

Specified by:
ordinal in interface UtilityContext
Parameters:
n - the number to convert
Returns:
a String containing the ordinal value of the specified number

cardinal

public String cardinal(Long n)
Description copied from interface: UtilityContext
A function that converts an integer to a cardinal value. i.e. one, two, three etc.

Specified by:
cardinal in interface UtilityContext
Parameters:
n - the number to convert
Returns:
a String containing the cardinal value of the specified number

cardinal

public String cardinal(long n)
Description copied from interface: UtilityContext
A function that converts an integer to a cardinal value. i.e. one, two, three etc.

Specified by:
cardinal in interface UtilityContext
Parameters:
n - the number to convert
Returns:
a String containing the cardinal value of the specified number

replace

public String replace(String source,
                      String pattern,
                      String replacement)
Description copied from interface: UtilityContext
Replaces all exact matches of the given pattern in the source string with the provided replacement.

Specified by:
replace in interface UtilityContext
Parameters:
source - the source string
pattern - the simple string pattern to search for
replacement - the string to use for replacing matched patterns.
Returns:
the string with any replacements applied.

replace

public String replace(String source,
                      String pattern,
                      String replacement,
                      int fromIndex)
Description copied from interface: UtilityContext
Replaces all exact matches of the given pattern in the source string with the provided replacement, starting from the given index.

Specified by:
replace in interface UtilityContext
Parameters:
source - the source string
pattern - the simple string pattern to search for
replacement - the string to use for replacing matched patterns.
fromIndex - index to start the replace
Returns:
the string with any replacements applied.

replace

public <K,V> String replace(String source,
                            Map<K,V> patternReplacements)
Description copied from interface: UtilityContext
Applies string replacements using the pattern-replacement pairs provided by the given map (associative array). The longest matching pattern is used for selecting an appropriate replacement.

Specified by:
replace in interface UtilityContext
Parameters:
source - the source string
patternReplacements - pattern-replacement pairs

replaceFirst

public String replaceFirst(String source,
                           String pattern,
                           String replacement)
Description copied from interface: UtilityContext
Replaces the first exact match of the given pattern in the source string with the provided replacement.

Specified by:
replaceFirst in interface UtilityContext
Parameters:
source - the source string
pattern - the simple string pattern to search for
replacement - the string to use for replacing matched patterns
Returns:
the string with any replacements applied

replaceFirst

public String replaceFirst(String source,
                           String pattern,
                           String replacement,
                           int fromIndex)
Description copied from interface: UtilityContext
Replaces the first exact match of the given pattern in the source string with the provided replacement, starting from the given index.

Specified by:
replaceFirst in interface UtilityContext
Parameters:
source - the source string
pattern - the simple string pattern to search for
replacement - the string to use for replacing matched patterns
fromIndex - index to start the replace
Returns:
the string with any replacements applied

replaceLast

public String replaceLast(String source,
                          String pattern,
                          String replacement)
Description copied from interface: UtilityContext
Replaces the last exact match of the given pattern in the source string with the provided replacement.

Specified by:
replaceLast in interface UtilityContext
Parameters:
source - the source string
pattern - the simple string pattern to search for
replacement - the string to use for replacing matched patterns
Returns:
the string with any replacements applied

replaceLast

public String replaceLast(String source,
                          String pattern,
                          String replacement,
                          int fromIndex)
Description copied from interface: UtilityContext
Replaces the last exact match of the given pattern in the source string with the provided replacement, starting from the given index.

Specified by:
replaceLast in interface UtilityContext
Parameters:
source - the source string
pattern - the simple string pattern to search for
replacement - the string to use for replacing matched patterns
fromIndex - index to start the replace
Returns:
the string with any replacements applied

isArray

public boolean isArray(Object o)
Description copied from interface: UtilityContext
A function that checks if an object is an Array

Specified by:
isArray in interface UtilityContext
Parameters:
o - the Object to check
Returns:
true if the object is an Array, false otherwise

sort

public void sort(Object[] array,
                 String onColumn,
                 boolean reverse)
Specified by:
sort in interface UtilityContext

sort

public void sort(Object[] array,
                 String[] onColumns,
                 boolean[] reverse)
Specified by:
sort in interface UtilityContext

sort

public void sort(String[] array,
                 boolean reverse,
                 boolean ignoreCase)
Specified by:
sort in interface UtilityContext

sort

public void sort(Object[] array,
                 boolean sortAscending)
Specified by:
sort in interface UtilityContext

sortAscending

public void sortAscending(Object[] array)
Specified by:
sortAscending in interface UtilityContext

sortAscending

public void sortAscending(int[] array)
Specified by:
sortAscending in interface UtilityContext

sortAscending

public void sortAscending(double[] array)
Specified by:
sortAscending in interface UtilityContext

sortAscending

public void sortAscending(float[] array)
Specified by:
sortAscending in interface UtilityContext

sortAscending

public void sortAscending(byte[] array)
Specified by:
sortAscending in interface UtilityContext

sortAscending

public void sortAscending(short[] array)
Specified by:
sortAscending in interface UtilityContext

sortAscending

public void sortAscending(long[] array)
Specified by:
sortAscending in interface UtilityContext

split

public String[] split(String str,
                      String regex)
Specified by:
split in interface UtilityContext

createStringBuilder

public StringBuilder createStringBuilder()
Description copied from interface: UtilityContext
A function that creates a string builder to allow programs to perform concatenation and pass around strings.

Specified by:
createStringBuilder in interface UtilityContext
Returns:
the created string builder

createStringBuilder

public StringBuilder createStringBuilder(int size)
Description copied from interface: UtilityContext
A function that creates a string builder to allow programs to perform concatenation and pass around strings.

Specified by:
createStringBuilder in interface UtilityContext
Parameters:
size - the initial size of the buffer
Returns:
the created string builder

append

public void append(StringBuilder buffer,
                   Object value)
Description copied from interface: UtilityContext
A function to append a value to an existing buffer.

Specified by:
append in interface UtilityContext
Parameters:
buffer - the buffer to append to
value - the value to append

prepend

public void prepend(StringBuilder buffer,
                    Object value)
Description copied from interface: UtilityContext
A function to prepend a value to an existing buffer.

Specified by:
prepend in interface UtilityContext
Parameters:
buffer - the buffer to prepend to
value - the value to prepend

insert

public void insert(StringBuilder buffer,
                   Object value,
                   int index)
Description copied from interface: UtilityContext
A function to insert a value into an existing buffer.

Specified by:
insert in interface UtilityContext
Parameters:
buffer - the buffer to insert into
value - the value to insert
index - the index of the position to insert at

toString

public String toString(StringBuilder buffer)
Description copied from interface: UtilityContext
A function to convert the buffer into a standard string.

Specified by:
toString in interface UtilityContext
Parameters:
buffer - the buffer to convert
Returns:
the converted buffer as a string


Copyright © 1997-2012 TeaTrove.org. All Rights Reserved.