org.teatrove.tea.runtime
Interface UtilityContext

All Superinterfaces:
Context, OutputReceiver
All Known Implementing Classes:
DefaultContext, TestCompiler.Context

public interface UtilityContext
extends Context

Extends the basic context to provide generic utility functions that most templates will need to use for formatting.

Author:
Brian S O'Neill

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.
 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.
 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 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
 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.
<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.
 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(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.
 
Methods inherited from interface org.teatrove.tea.runtime.Context
dateFormat, dateFormat, getAvailableLocales, getAvailableTimeZones, getDateFormat, getDateFormatTimeZone, getLocale, getNullFormat, getNumberFormat, getNumberFormatInfinity, getNumberFormatNaN, nullFormat, numberFormat, numberFormat, print, print, print, print, print, print, print, print, setLocale, setLocale, setLocale, toString, toString, toString, toString, toString, toString, toString, toString, toString
 
Methods inherited from interface org.teatrove.tea.runtime.OutputReceiver
write, write, write, write, write
 

Method Detail

currentDate

Date currentDate()
Returns a standard Java Date object with the current date and time.


currentDateTime

org.joda.time.DateTime currentDateTime()
Returns a Joda DateTime object with the current date and time.


startsWith

boolean startsWith(String str,
                   String prefix)
Tests if the given string starts with the given prefix. Returns true if the given string starts with the given prefix.

Parameters:
str - the source string
prefix - the prefix to test for
Returns:
true if the given string starts with the given prefix

endsWith

boolean endsWith(String str,
                 String suffix)
Tests if the given string ends with the given suffix. Returns true if the given string ends with the given suffix.

Parameters:
str - the source string
suffix - the suffix to test for
Returns:
true if the given string ends with the given suffix

find

int[] find(String str,
           String search)
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

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

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.

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

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.

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

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.

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

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.

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

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.

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

String substring(String str,
                 int startIndex)
Returns the trailing end of the given string, starting from the given index.

Parameters:
str - the source string
startIndex - the start index, inclusive
Returns:
the specified substring.

substring

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.

Parameters:
str - the source string
startIndex - the start index, inclusive
endIndex - the ending index, exclusive
Returns:
the specified substring.

toLowerCase

String toLowerCase(String str)
Converts all the characters in the given string to lowercase.

Parameters:
str - the string to convert
Returns:
the string converted to lowercase

toUpperCase

String toUpperCase(String str)
Converts all the characters in the given string to uppercase.

Parameters:
str - the string to convert
Returns:
the string converted to uppercase

trim

String trim(String str)
Trims all leading and trailing whitespace characters from the given string.

Parameters:
str - the string to trim
Returns:
the trimmed string

trimLeading

String trimLeading(String str)
Trims all leading whitespace characters from the given string.

Parameters:
str - the string to trim
Returns:
the trimmed string

trimTrailing

String trimTrailing(String str)
Trims all trailing whitespace characters from the given string.

Parameters:
str - the string to trim
Returns:
the trimmed string

replace

String replace(String source,
               String pattern,
               String replacement)
Replaces all exact matches of the given pattern in the source string with the provided replacement.

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

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.

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

<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). The longest matching pattern is used for selecting an appropriate replacement.

Parameters:
source - the source string
patternReplacements - pattern-replacement pairs

replaceFirst

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.

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

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.

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

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.

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

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.

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

shortOrdinal

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

Parameters:
n - the number to convert
Returns:
a String containing the short ordinal value of the specified number

shortOrdinal

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

Parameters:
n - the number to convert
Returns:
a String containing the short ordinal value of the specified number

ordinal

String ordinal(Long n)
A function that converts an integer to an ordinal value. i.e. first, second, third etc.

Parameters:
n - the number to convert
Returns:
a String containing the ordinal value of the specified number

ordinal

String ordinal(long n)
A function that converts an integer to an ordinal value. i.e. first, second, third etc.

Parameters:
n - the number to convert
Returns:
a String containing the ordinal value of the specified number

cardinal

String cardinal(Long n)
A function that converts an integer to a cardinal value. i.e. one, two, three etc.

Parameters:
n - the number to convert
Returns:
a String containing the cardinal value of the specified number

cardinal

String cardinal(long n)
A function that converts an integer to a cardinal value. i.e. one, two, three etc.

Parameters:
n - the number to convert
Returns:
a String containing the cardinal value of the specified number

isArray

boolean isArray(Object o)
A function that checks if an object is an Array

Parameters:
o - the Object to check
Returns:
true if the object is an Array, false otherwise

sort

void sort(Object[] array,
          String onColumn,
          boolean reverse)

sort

void sort(Object[] array,
          String[] onColumns,
          boolean[] reverse)

sort

void sort(String[] array,
          boolean reverse,
          boolean ignoreCase)

sort

void sort(Object[] array,
          boolean sortAscending)

sortAscending

void sortAscending(Object[] array)

sortAscending

void sortAscending(int[] array)

sortAscending

void sortAscending(double[] array)

sortAscending

void sortAscending(float[] array)

sortAscending

void sortAscending(byte[] array)

sortAscending

void sortAscending(short[] array)

sortAscending

void sortAscending(long[] array)

split

String[] split(String str,
               String regex)

createStringBuilder

StringBuilder createStringBuilder()
A function that creates a string builder to allow programs to perform concatenation and pass around strings.

Returns:
the created string builder

createStringBuilder

StringBuilder createStringBuilder(int size)
A function that creates a string builder to allow programs to perform concatenation and pass around strings.

Parameters:
size - the initial size of the buffer
Returns:
the created string builder

append

void append(StringBuilder buffer,
            Object value)
A function to append a value to an existing buffer.

Parameters:
buffer - the buffer to append to
value - the value to append

prepend

void prepend(StringBuilder buffer,
             Object value)
A function to prepend a value to an existing buffer.

Parameters:
buffer - the buffer to prepend to
value - the value to prepend

insert

void insert(StringBuilder buffer,
            Object value,
            int index)
A function to insert a value into an existing buffer.

Parameters:
buffer - the buffer to insert into
value - the value to insert
index - the index of the position to insert at

toString

String toString(StringBuilder buffer)
A function to convert the buffer into a standard string.

Parameters:
buffer - the buffer to convert
Returns:
the converted buffer as a string


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