prettify.parser
Class Util

java.lang.Object
  extended by prettify.parser.Util

public class Util
extends java.lang.Object

Common Utilities. Some of the functions are port from JavaScript.

Author:
Chan Wai Shing

Constructor Summary
protected Util()
           
 
Method Summary
static java.lang.Boolean getVariableValueAsBoolean(java.lang.Object var)
          Treat a variable as an boolean in JavaScript style.
static java.lang.Integer getVariableValueAsInteger(java.lang.Object var)
          Treat a variable as an integer in JavaScript style.
static java.lang.String join(java.util.List<java.lang.String> strings)
          Join the strings into one string.
static java.lang.String join(java.util.List<java.lang.String> strings, java.lang.String delimiter)
          Join the strings into one string with delimiter in between.
static java.lang.String join(java.lang.String[] strings)
          Join the strings into one string.
static java.lang.String join(java.lang.String[] strings, java.lang.String delimiter)
          Join the strings into one string with delimiter in between.
static java.lang.String[] match(java.util.regex.Pattern pattern, java.lang.String string, boolean isGlobal)
          Get all the matches for string compiled by pattern.
static java.util.List<java.lang.Object> removeDuplicates(java.util.List<java.lang.Object> decorations, java.lang.String source)
          Remove identical adjacent tags from decorations.
static boolean test(java.util.regex.Pattern pattern, java.lang.String string)
          Test whether the string has at least one match by pattern.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Util

protected Util()
Method Detail

getVariableValueAsBoolean

public static java.lang.Boolean getVariableValueAsBoolean(java.lang.Object var)
Treat a variable as an boolean in JavaScript style. Note this function can only handle string, integer and boolean currently. All other data type, if null, return false, not null return true.

Parameters:
var - the variable to get value from
Returns:
the boolean value

getVariableValueAsInteger

public static java.lang.Integer getVariableValueAsInteger(java.lang.Object var)
Treat a variable as an integer in JavaScript style. Note this function can only handle integer and boolean currently.

Parameters:
var - the variable to get value from
Returns:
the integer value
Throws:
java.lang.IllegalArgumentException - the data type of var is neither integer nor boolean.

match

public static java.lang.String[] match(java.util.regex.Pattern pattern,
                                       java.lang.String string,
                                       boolean isGlobal)
Get all the matches for string compiled by pattern. If isGlobal is true, the return results will only include the group 0 matches. It is similar to string.match(regexp) in JavaScript.

Parameters:
pattern - the regexp
string - the string
isGlobal - similar to JavaScript /g flag
Returns:
all matches

test

public static boolean test(java.util.regex.Pattern pattern,
                           java.lang.String string)
Test whether the string has at least one match by pattern.

Parameters:
pattern - the regexp
string - the string to test
Returns:
true if at least one match, false if no match

join

public static java.lang.String join(java.util.List<java.lang.String> strings)
Join the strings into one string.

Parameters:
strings - the string list to join
Returns:
the joined string

join

public static java.lang.String join(java.util.List<java.lang.String> strings,
                                    java.lang.String delimiter)
Join the strings into one string with delimiter in between.

Parameters:
strings - the string list to join
delimiter - the delimiter
Returns:
the joined string

join

public static java.lang.String join(java.lang.String[] strings)
Join the strings into one string.

Parameters:
strings - the string list to join
Returns:
the joined string

join

public static java.lang.String join(java.lang.String[] strings,
                                    java.lang.String delimiter)
Join the strings into one string with delimiter in between. It is similar to RegExpObject.test(string) in JavaScript.

Parameters:
strings - the string list to join
delimiter - the delimiter
Returns:
the joined string

removeDuplicates

public static java.util.List<java.lang.Object> removeDuplicates(java.util.List<java.lang.Object> decorations,
                                                                java.lang.String source)
Remove identical adjacent tags from decorations.

Parameters:
decorations - see Job.decorations
source - the source code
Returns:
the decorations after treatment
Throws:
java.lang.IllegalArgumentException - the size of decoration is not a multiple of 2