public final class Functions extends Object
Modifier and Type | Method and Description |
---|---|
static String[] |
array(String... values)
Create an array of String based on the strings given as parameters.
|
static Boolean |
bool(String value)
|
static boolean |
contains(Object object,
Object value)
Returns
true if the object contains the value. |
static String |
decodeBase64(String value)
Decode the given Base64 String input.
|
static String |
encodeBase64(String value)
Encode the given String input into Base 64.
|
static String |
fileToUrl(File file)
Returns the String representation of the URL denoting the given file.
|
static int |
indexOf(String value,
String substring)
Returns the index within a string of the first occurrence of a specified
substring.
|
static Integer |
integer(String value)
|
static Integer |
integerWithRadix(String value,
int radix)
|
static String |
join(String[] values,
String separator)
Joins an array of strings into a single string value, with a specified separator.
|
static String |
keyMatch(Object map,
String pattern)
Returns the first key found in a map that matches the specified regular
expression pattern, or
null if no such match is found. |
static int |
length(Object value)
Returns the number of items in a collection, or the number of characters
in a string.
|
static boolean |
matches(String value,
String pattern)
Returns
true if the string contains the specified regular
expression pattern. |
static String[] |
matchingGroups(String value,
String pattern)
Returns an array containing the matches of a regular expression pattern
against a string, or
null if no match is found. |
static String |
pathToUrl(String path)
Returns the String representation of the URL denoting the given path.
|
static String |
read(String filename)
Returns the content of the given file as a plain String.
|
static Properties |
readProperties(String filename)
Returns the content of the given file as a
Properties . |
static String |
readWithCharset(String filename,
Charset charset)
Returns the content of the given file as a plain String using a specific
Charset . |
static String[] |
split(String value,
String regex)
Splits a string into an array of substrings around matches of the given
regular expression.
|
static Object |
toJson(String value)
Parse/Un-marshal the input String into a JSON structure.
|
static String |
toLowerCase(String value)
Converts all of the characters in a string to lower case.
|
static String |
toString(Object value)
Returns the string value of an arbitrary object.
|
static String |
toUpperCase(String value)
Converts all of the characters in a string to upper case.
|
static String |
trim(String value)
Returns a copy of a string with leading and trailing whitespace omitted.
|
static String |
urlDecode(String value)
Returns the URL decoding of the provided string.
|
static String |
urlEncode(String value)
Returns the URL encoding of the provided string.
|
public static String[] array(String... values)
values
- the strings to put in the array.public static Integer integer(String value)
String
to an Integer
. If the parameter is not a valid integer (in radix 10) then
it returns null.value
- the String
containing the integer representation to be parsedpublic static Integer integerWithRadix(String value, int radix)
value
- the String
containing the integer representation to be parsedradix
- the radix to be used while parsing s
.public static Boolean bool(String value)
String
to an Boolean
. The rules for the transformation are the same as the ones
described on Boolean.valueOf(String)
.value
- the String
containing the boolean representation to be parsedpublic static boolean contains(Object object, Object value)
true
if the object contains the value.object
- the object to be searched.value
- the value to find.0
if length could not be
determined.public static int indexOf(String value, String substring)
value
- the string to be searched.substring
- the value to search for within the string-1
if
not found.public static String join(String[] values, String separator)
separator
- the separator to place between joined elements.values
- the array of strings to be joined. You can use the array() function to construct this argument.public static String keyMatch(Object map, String pattern)
null
if no such match is found.map
- the map whose keys are to be searched.pattern
- a string containing the regular expression pattern to match.null
if no match found.public static int length(Object value)
value
- the object whose length is to be determined.0
if length could not be
determined.public static boolean matches(String value, String pattern)
true
if the string contains the specified regular
expression pattern.value
- the string to be searched.pattern
- a string containing the regular expression pattern to find.true
if the string contains the specified regular
expression pattern.public static String[] matchingGroups(String value, String pattern)
null
if no match is found. The first element
of the array is the entire match, and each subsequent element correlates
to any capture group specified within the regular expression.value
- the string to be searched.pattern
- a string containing the regular expression pattern to match.null
if no match found.public static String[] split(String value, String regex)
value
- the string to be split.regex
- the regular expression to split substrings around.public static Object toJson(String value)
value
- The stringified-JSON.public static String toLowerCase(String value)
value
- the string whose characters are to be converted.public static String toString(Object value)
value
- the object whose string value is to be returned.public static String toUpperCase(String value)
value
- the string whose characters are to be converted.public static String trim(String value)
value
- the string whose white space is to be omitted.public static String urlEncode(String value)
value
- the string to be URL encoded, which may be null
.null
if
string
was null
.public static String urlDecode(String value)
value
- the string to be URL decoded, which may be null
.null
if
string
was null
.public static String encodeBase64(String value)
value
- the string to be Base64 encoded, which may be null
.null
if
string
was null
.public static String decodeBase64(String value)
value
- the string to be Base64 decoded, which may be null
.null
if
string
was null
or if the input was not a Base64 valid input.public static String read(String filename)
filename
- file to be readpublic static String readWithCharset(String filename, Charset charset)
Charset
.public static Properties readProperties(String filename)
Properties
.filename
- file to be readProperties
or null if here was an error (missing file, ...)public static String pathToUrl(String path)
path
- the path to build the URL from.Copyright 2011-2017 ForgeRock AS.