|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.lucidviews.util.text.Strings
public class Strings
A collection of utility methods for performing operations on
String
s.
Nested Class Summary | |
---|---|
protected static class |
Strings.ClassMustBeValid
Helper class required for exported constant CLASS_MUST_BE_VALID, which must be unique/different to avoid confusion with any other value a client may use. |
protected static class |
Strings.EnumValueMustBeValid
Helper class required for exported constant ENUM_VALUE_MUST_BE_VALID, which must be unique/different to avoid confusion with any other value a client may use. |
Field Summary | |
---|---|
static Boolean |
BOOLEAN_MUST_BE_VALID
Special default value that ensures a valid Boolean value is parsed (i.e. |
static Class |
CLASS_MUST_BE_VALID
Special default value that ensures a valid Class is parsed (i.e. |
static long |
COLOR_ALPHA_MASK
Bitmask for extracting the alpha component from a argb value. |
static char |
COLOR_HEX_LENGTH_WITHOUT_ALPHA
The maximum length of a hex colour string (exlucing '#' prefix) without an alpha component. |
static char |
COLOR_HEX_PREFIX
The character used to prefix hex colour codes. |
static Color |
COLOR_MUST_BE_VALID
Special default value that ensures a valid Color is parsed (i.e. |
static Double |
DOUBLE_MUST_BE_VALID
Special default value that ensures a valid floating-point value is parsed (i.e. |
static File |
ENSURE_FILE_EXISTS
Special default value that ensures a valid File is parsed and references an existing file or a location where a new file can be created. |
static File |
ENSURE_FOLDER_EXISTS
Special default value that ensures a valid File is parsed and references an existing folder or a location where a new folder can be created. |
static File |
ENSURE_PARENT_FOLDER_EXISTS
Special default value that ensures a valid File is parsed and references a location within an existing folder or in a folder that can be created. |
static EnumValue |
ENUM_VALUE_MUST_BE_VALID
Special default value that ensures a valid Enumeration value is parsed (i.e. |
static File |
FILE_MUST_EXIST
Special default value that ensures a valid File is parsed and references a file that already exists on the file system. |
static File |
FOLDER_MUST_EXIST
Special default value that ensures a valid File is parsed and references a folder that already exists on the file system. |
static Long |
LONG_MUST_BE_VALID
Special default value that ensures a valid Integer value is parsed (i.e. |
static Object |
OBJECT_MUST_BE_VALID
Special default value that ensures a valid Object is parsed (i.e. |
static File |
PARENT_FOLDER_MUST_EXIST
Special default value that ensures a valid File is parsed and references a location within an existing folder on the file system. |
static String |
WHITESPACE_CHARS
A string containing all the characters Java treats as whitespace. |
Constructor Summary | |
---|---|
protected |
Strings()
The default constructor is protected to prevent instantiation. |
Method Summary | |
---|---|
static boolean |
containsAll(String string,
String chars)
Check if a string contains all of a given set of characters. |
static boolean |
containsAny(String string,
String chars)
Check if a string contains any of a given set of characters. |
static String |
firstLine(String text)
Extract the first line from a text string. |
static String |
nextLine(String text,
int fromIndex)
Extract a line from a text string. |
static Boolean |
parseBoolean(Boolean defaultValue,
String string)
Parse a Boolean value from a String , returning
the default value if the string was invalid. |
static Boolean |
parseBoolean(String string)
Parse a Boolean value from a String . |
static boolean |
parseBoolean(String string,
boolean defaultValue)
Parse a boolean value from a String , returning
the default value if the string was invalid. |
static Boolean |
parseBoolean(String string,
Boolean defaultValue)
Parse a Boolean value from a String , returning
the default value if the string was invalid. |
static Class |
parseClass(Class defaultValue,
String string)
Parse a Java Class from a String , returning
the default value if the string was invalid. |
static Class |
parseClass(Class defaultValue,
String string,
String relativeToPackage)
Parse a Java Class from a String , returning
the default value if the string was invalid. |
static Class |
parseClass(String string)
Parse a Java Class from a String . |
static Class |
parseClass(String string,
Class defaultValue)
Parse a Java Class from a String , returning
the default value if the string was invalid. |
static Class |
parseClass(String string,
String relativeToPackage,
Class defaultValue)
Parse a Java Class from a String , returning
the default value if the string was invalid. |
static Color |
parseColor(Color defaultValue,
String string)
Parse a Color from a String , returning
the default value if the string was invalid. |
static Color |
parseColor(String string)
Parse a Color from a String , returning
the default value if the string was invalid. |
static Color |
parseColor(String string,
Color defaultValue)
Parse a Color from a String , returning
the default value if the string was invalid. |
static Double |
parseDouble(Double defaultValue,
String string)
Parse a Double value from a String , returning
the default value if the string was invalid. |
static Double |
parseDouble(String string)
Parse a Double value from a String . |
static double |
parseDouble(String string,
double defaultValue)
Parse a Double value from a String , returning
the default value if the string was invalid. |
static Double |
parseDouble(String string,
Double defaultValue)
Parse a Double value from a String , returning
the default value if the string was invalid. |
static EnumValue |
parseEnumValue(EnumValue defaultValue,
String string,
Enumeration enumeration)
Parse an enumeration value of the given Enumeration type
from a String , returning the default value if the string was
invalid. |
static EnumValue |
parseEnumValue(String string,
Enumeration enumeration)
Parse an enumeration value of the given Enumeration type
from a String . |
static EnumValue |
parseEnumValue(String string,
Enumeration enumeration,
EnumValue defaultValue)
Parse an enumeration value of the given Enumeration type
from a String , returning the default value if the string was
invalid. |
static File |
parseFile(File defaultValue,
String string)
Parse a File value from a String , returning
the default value if the string was invalid. |
static File |
parseFile(File defaultValue,
String string,
File relativeToFolder)
Parse a File value from a String , returning
the default value if the string was invalid. |
static File |
parseFile(String string)
Parse a File value from a String . |
static File |
parseFile(String string,
File defaultValue)
Parse a File value from a String , returning
the default value if the string was invalid. |
static File |
parseFile(String string,
File relativeToFolder,
File defaultValue)
Parse a File value from a String , returning
the default value if the string was invalid. |
static File |
parseFolder(File defaultValue,
String string)
Parse a File value from a String , returning
the default value if the string was invalid. |
static File |
parseFolder(File defaultValue,
String string,
File relativeToFolder)
Parse a File value from a String , returning
the default value if the string was invalid. |
static File |
parseFolder(String string)
Parse a File value from a String . |
static File |
parseFolder(String string,
File defaultValue)
Parse a File value from a String , returning
the default value if the string was invalid. |
static File |
parseFolder(String string,
File relativeToFolder,
File defaultValue)
Parse a File value from a String , returning
the default value if the string was invalid. |
static int[] |
parseInts(String string)
Parse a list of integer values from a given string. |
static int[] |
parseInts(String string,
int minValue,
int maxValue)
Parse a list of integer values from a given string. |
static int[] |
parseInts(String string,
String delimiters)
Parse a list of integer values from a given string. |
static int[] |
parseInts(String string,
String delimiters,
int minValue,
int maxValue)
Parse a list of integer values from a given string. |
static Long |
parseLong(Long defaultValue,
String string)
Parse a Long value from a String , returning
the default value if the string was invalid. |
static Long |
parseLong(String string)
Parse a Long value from a String . |
static long |
parseLong(String string,
long defaultValue)
Parse a Long value from a String , returning
the default value if the string was invalid. |
static Long |
parseLong(String string,
Long defaultValue)
Parse a Long value from a String , returning
the default value if the string was invalid. |
static Object |
parseObject(Object defaultValue,
String string,
Collection validObjects)
Parse an object from a String , returning the default value
if the string was invalid. |
static Object |
parseObject(String string,
Collection validObjects)
Parse an object from a String . |
static Object |
parseObject(String string,
Collection validObjects,
Object defaultValue)
Parse an object from a String , returning the default value
if the string was invalid. |
static String |
rightAlign(String string,
int length)
Right-align a text string, padding the left portion of the string with spaces and truncating the string if necessary. |
static String |
rightAlign(String string,
int length,
boolean truncate)
Right-align a text string, padding the left portion of the string with spaces. |
static String |
rightAlign(String string,
int length,
char pad)
Right-align a text string, padding the left portion of the string with the specified padding character and truncating the string if necessary. |
static String |
rightAlign(String string,
int length,
char pad,
boolean truncate)
Right-align a text string, padding the left portion of the string with the specified padding character. |
static String |
serializeColor(Color value)
Serialize a Color as a String . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final Boolean BOOLEAN_MUST_BE_VALID
parseBoolean(Boolean,String)
public static final Long LONG_MUST_BE_VALID
parseLong(Long, String)
public static final Double DOUBLE_MUST_BE_VALID
parseDouble(Double, String)
public static final File FILE_MUST_EXIST
parseFile(File, String)
public static final File ENSURE_FILE_EXISTS
parseFile(File, String)
public static final File FOLDER_MUST_EXIST
parseFolder(File, String)
public static final File ENSURE_FOLDER_EXISTS
parseFolder(File, String)
public static final File PARENT_FOLDER_MUST_EXIST
parseFile(File, String)
,
parseFolder(File, String)
public static final File ENSURE_PARENT_FOLDER_EXISTS
parseFile(File, String)
,
parseFolder(File, String)
public static final Class CLASS_MUST_BE_VALID
parseClass(Class, String)
public static final EnumValue ENUM_VALUE_MUST_BE_VALID
parseEnumValue(EnumValue, String, Enumeration)
public static final Object OBJECT_MUST_BE_VALID
parseObject(Object, String, Collection)
public static final Color COLOR_MUST_BE_VALID
parseColor(Color, String)
public static final long COLOR_ALPHA_MASK
public static final char COLOR_HEX_PREFIX
public static final char COLOR_HEX_LENGTH_WITHOUT_ALPHA
public static final String WHITESPACE_CHARS
Constructor Detail |
---|
protected Strings()
Method Detail |
---|
public static Boolean parseBoolean(String string) throws ParseValueException
Boolean
value from a String
.
string
is invalid then an exception will be thrown.
null
. Thus, the
following line of code will never cause a
NullPointerException
:
boolean value = Strings.parseBoolean( string ).booleanValue();
ParseValueException
if the
string
is invalid.
string
- the String
containing the Boolean value
Boolean
value represented by the
string
ParseValueException
- if the String
value could not be
parsed as a valid Boolean
valuepublic static Boolean parseBoolean(Boolean defaultValue, String string) throws ParseValueException
Boolean
value from a String
, returning
the default value if the string was invalid.
string
is invalid and the defaultValue
is set to the constant Strings.BOOLEAN_MUST_BE_VALID
, an
exception will be thrown.
null
, provided the
defaultValue
is not null
. Thus, none of the
following lines of code will cause a NullPointerException
:
Boolean value = Strings.parseBoolean( default, string );
boolean value = Strings.parseBoolean( default, string ).booleanValue();
boolean value = Strings.parseBoolean( Strings.BOOLEAN_MUST_BE_VALID, string ).booleanValue();
ParseValueException
if
the string
is invalid.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
containing the Boolean value
Boolean
value represented by the
string
, or the default value if the
string
is invalid
ParseValueException
- if the String
value must be
valid but could not be parsed as a valid
Boolean
valuepublic static Boolean parseBoolean(String string, Boolean defaultValue)
Boolean
value from a String
, returning
the default value if the string was invalid.
null
, provided the
defaultValue
is not null
. Thus, none of the
following lines of code will cause a NullPointerException
:
Boolean value = Strings.parseBoolean( string, default );
boolean value = Strings.parseBoolean( string, default ).booleanValue();
- Parameters:
string
- the String
containing the Boolean valuedefaultValue
- the default value to be used if the
string
is not valid
- Returns:
- the
Boolean
value represented by the
string
, or the default value if the
string
is invalid
public static boolean parseBoolean(String string, boolean defaultValue)
boolean
value from a String
, returning
the default value if the string was invalid.
string
- the String
containing the Boolean valuedefaultValue
- the default value to be used if the
string
is not valid
boolean
value represented by the
string
, or the default value if the
string
is invalidpublic static Long parseLong(String string) throws ParseValueException
Long
value from a String
.
string
is invalid then an exception will be thrown.
null
. Thus, the
following line of code will never cause a
NullPointerException
:
long value = Strings.parseLong( string ).longValue();
int value = Strings.parseLong( string ).intValue();
ParseValueException
if the
string
is invalid.
string
- the String
containing the numeric, integer
value
Long
value represented by the
string
ParseValueException
- if the String
could not be
parsed as a valid Long
valuepublic static Long parseLong(Long defaultValue, String string) throws ParseValueException
Long
value from a String
, returning
the default value if the string was invalid.
string
is invalid and the defaultValue
is set to the constant Strings.LONG_MUST_BE_VALID
, an
exception will be thrown.
null
, provided the
defaultValue
is not null
. Thus, none of the
following lines of code will cause a NullPointerException
:
Long value = Strings.parseLong( default, string );
long value = Strings.parseLong( default, string ).longValue();
int value = Strings.parseLong( default, string ).intValue();
int value = Strings.parseLong( Strings.LONG_MUST_BE_VALID, string ).intValue();
ParseValueException
if
the string
is invalid.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
containing the numeric, integer
value
Long
value represented by the
string
, or the default value if the
string
is invalid
ParseValueException
- if the String
value must be
valid but could not be parsed as a valid
Long
valuepublic static Long parseLong(String string, Long defaultValue)
Long
value from a String
, returning
the default value if the string was invalid.
string
is invalid and the defaultValue
is set to the constant Strings.LONG_MUST_BE_VALID
, an
exception will be thrown.
null
, provided the
defaultValue
is not null
. Thus, none of the
following lines of code will cause a NullPointerException
:
Long value = Strings.parseLong( string, default );
long value = Strings.parseLong( string, default ).longValue();
int value = Strings.parseLong( string, default ).intValue();
string
- the String
containing the numeric, integer
valuedefaultValue
- the default value to be used if the
string
is not valid
Long
value represented by the
string
, or the default value if the
string
is invalidpublic static long parseLong(String string, long defaultValue)
Long
value from a String
, returning
the default value if the string was invalid.
string
- the String
containing the numeric integer
valuedefaultValue
- the default value to be used if the
string
is not valid
long
value represented by the
string
, or the default value if the
string
is invalidpublic static Double parseDouble(String string) throws ParseValueException
Double
value from a String
.
string
is invalid then an exception will be thrown.
null
. Thus, the
following line of code will never cause a
NullPointerException
:
double value = Strings.parseDouble( string ).doubleValue();
float value = Strings.parseDouble( string ).floatValue();
ParseValueException
if the
string
is invalid.
string
- the String
containing the numeric,
floating-point value
Double
value represented by the
string
ParseValueException
- if the String
could not be
parsed as a valid Double
valuepublic static Double parseDouble(Double defaultValue, String string) throws ParseValueException
Double
value from a String
, returning
the default value if the string was invalid.
string
is invalid and the defaultValue
is set to the constant Strings.DOUBLE_MUST_BE_VALID
, an
exception will be thrown.
null
, provided the
defaultValue
is not null
. Thus, none of the
following lines of code will cause a NullPointerException
:
Double value = Strings.parseDouble( default, string );
double value = Strings.parseDouble( default, string, ).doubleValue();
float value = Strings.parseDouble( default, string ).floatValue();
float value = Strings.parseDouble( Strings.DOUBLE_MUST_BE_VALID, string ).floatValue();
ParseValueException
if
the string
is invalid.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
containing the numeric,
floating-point value
Double
value represented by the
string
, or the default value if the
string
is invalid
ParseValueException
- if the String
value must be
valid but could not be parsed as a valid
Double
valuepublic static Double parseDouble(String string, Double defaultValue)
Double
value from a String
, returning
the default value if the string was invalid.
null
, provided the
defaultValue
is not null
. Thus, none of the
following lines of code will cause a NullPointerException
:
Double value = Strings.parseDouble( string, default );
double value = Strings.parseDouble( string, default ).doubleValue();
float value = Strings.parseDouble( string, default ).floatValue();
string
- the String
containing the numeric,
floating-point valuedefaultValue
- the default value to be used if the
string
is not valid
Double
value represented by the
string
, or the default value if the
string
is invalidpublic static double parseDouble(String string, double defaultValue)
Double
value from a String
, returning
the default value if the string was invalid.
string
- the String
containing the numeric,
floating-point valuedefaultValue
- the default value to be used if the
string
is not valid
Double
value represented by the
string
, or the default value if the
string
is invalidpublic static File parseFile(String string) throws ParseValueException
File
value from a String
.
null
.
string
- the String
value containing the file path
File
at the system path specified by the
string
ParseValueException
- if a File
could not be found at
the location specified in the
String
public static File parseFile(File defaultValue, String string, File relativeToFolder) throws ParseValueException
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a file, either
absolute or relative to the given folder.
defaultValue
is set to the constant Strings.FILE_MUST_EXIST
, an exception
will be thrown.
defaultValue
is set to the constant Strings.ENSURE_FILE_EXISTS
, a new,
empty file will be created and a reference to that new file returned.
defaultValue
is set to the constant
Strings.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant file (in a existant folder)
will be returned.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the file pathrelativeToFolder
- the base location to use if the file path
defined by the string
is relative,
rather than an absolute path
File
referenced by the path in the
string
, or the default value if the
string
is invalid
ParseValueException
- if the path specified by the
string
value must be valid but
could not be parsed as a valid
File
public static File parseFile(File defaultValue, String string) throws ParseValueException
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a file, either
absolute or relative to the current working folder.
defaultValue
is set to the constant Strings.FILE_MUST_EXIST
, an exception
will be thrown.
defaultValue
is set to the constant Strings.ENSURE_FILE_EXISTS
, a new,
empty file will be created and a reference to that new file returned.
defaultValue
is set to the constant
Strings.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant file (in a existant folder)
will be returned.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the file path
File
referenced by the path in the
string
, or the default value if the
string
is invalid
ParseValueException
- if the path specified by the
string
value must be valid but
could not be parsed as a valid
File
public static File parseFile(String string, File relativeToFolder, File defaultValue)
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a file, either
absolute or relative to the given folder.
defaultValue
is set to the constant Strings.ENSURE_FILE_EXISTS
, a new,
empty file will be created and a reference to that new file returned.
Otherwise, if the path does not reference a file, the default value will
be returned.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant file (in a existant folder)
will be returned. Otherwise, if the path references a file in a folder
that does not exist, the default value will be returned.
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the file pathrelativeToFolder
- the base location to use if the file path
defined by the string
is relative,
rather than an absolute pathdefaultValue
- the default value to be used if the
string
is not valid
File
referenced by the path in the
string
, or the default value if the
string
is invalidpublic static File parseFile(String string, File defaultValue)
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a file, either
absolute or relative to the current working folder.
defaultValue
is set to the constant Strings.ENSURE_FILE_EXISTS
, a new,
empty file will be created and a reference to that new file returned.
Otherwise, if the path does not reference a file, the default value will
be returned.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant file (in a existant folder)
will be returned. Otherwise, if the path references a file in a folder
that does not exist, the default value will be returned.
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the file pathdefaultValue
- the default value to be used if the
string
is not valid
File
referencing the location of the path in the
string
, or the default value if the
string
is invalidpublic static File parseFolder(String string) throws ParseValueException
File
value from a String
.
null
.
string
- the String
value containing the folder path
File
at the system path specified by the
string
ParseValueException
- if a File
could not be found at
the location specified in the
String
public static File parseFolder(File defaultValue, String string, File relativeToFolder) throws ParseValueException
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a folder, either
absolute or relative to the given folder.
defaultValue
is set to the constant Strings.FOLDER_MUST_EXIST
, an
exception will be thrown.
defaultValue
is set to the constant Strings.ENSURE_FOLDER_EXISTS
, the
folder will be created and a reference to that new folder returned.
defaultValue
is set to the constant
Strings.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant folder (in a existant folder)
will be returned.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the folder pathrelativeToFolder
- the base location to use if the folder path
defined by the string
is relative,
rather than an absolute path
File
referencing the location of the path in the
string
, or the default value if the
string
is invalid
ParseValueException
- if the path specified by the
string
value must be valid but
could not be parsed as a valid
File
public static File parseFolder(File defaultValue, String string) throws ParseValueException
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a folder, either
absolute or relative to the current working folder.
defaultValue
is set to the constant Strings.FOLDER_MUST_EXIST
, an
exception will be thrown.
defaultValue
is set to the constant Strings.ENSURE_FOLDER_EXISTS
, the
folder will be created and a reference to that new folder returned.
defaultValue
is set to the constant
Strings.PARENT_FOLDER_MUST_EXIST
, an exception will be
thrown.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant folder (in a existant folder)
will be returned.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the folder path
File
referencing the location of the path in the
string
, or the default value if the
string
is invalid
ParseValueException
- if the path specified by the
string
value must be valid but
could not be parsed as a valid
File
public static File parseFolder(String string, File relativeToFolder, File defaultValue)
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a folder, either
absolute or relative to the given folder.
defaultValue
is set to the constant Strings.ENSURE_FOLDER_EXISTS
, the
folder will be created and a reference to that new folder returned.
Otherwise, if the path does not reference a folder, the default value
will be returned.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant folder (in a existant folder)
will be returned. Otherwise, if the path references a sub-folder of a
folder that does not exist, the default value will be returned.
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the folder pathrelativeToFolder
- the base location to use if the folder path
defined by the string
is relative,
rather than an absolute pathdefaultValue
- the default value to be used if the
string
is not valid
File
referencing the location of the path in the
string
, or the default value if the
string
is invalidpublic static File parseFolder(String string, File defaultValue)
File
value from a String
, returning
the default value if the string was invalid.
string
should specify the path to a folder, either
absolute or relative to the current working folder.
defaultValue
is set to the constant Strings.ENSURE_FOLDER_EXISTS
, the
folder will be created and a reference to that new folder returned.
Otherwise, if the path does not reference a folder, then the default
value will be returned.
defaultValue
is set to the constant
Strings.ENSURE_PARENT_FOLDER_EXISTS
, the parent folder will
be created and a reference to an inexistant folder (in a existant folder)
will be returned. Otherwise, if the path references a sub-folder of a
folder that does not exist, the default value will be returned.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the folder path
File
referencing the location of the path in the
string
, or the default value if the
string
is invalidpublic static Class parseClass(String string) throws ParseValueException
Class
from a String
.
string
should specify the full, absolute name of a
class.
null
.
string
- the String
value containing the class name
Class
found at the given location defined in
the string
ParseValueException
- if the path specified by the
string
value could not be parsed
as a valid Class
public static Class parseClass(Class defaultValue, String string, String relativeToPackage) throws ParseValueException
Class
from a String
, returning
the default value if the string was invalid.
string
should specify the name of a class, with
the package path, either absolute or relative to the given package.
defaultValue
is set to the constant
Strings.CLASS_MUST_BE_VALID
, an exception will be thrown.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the class namerelativeToPackage
- the base location to use if the class name
defined by the string
is not an
absolute path
Class
found at the given location defined in
the string
, or the default value if the
string
is invalid
ParseValueException
- if the path specified by the
string
value must be valid but
could not be parsed as a valid
Class
public static Class parseClass(Class defaultValue, String string) throws ParseValueException
Class
from a String
, returning
the default value if the string was invalid.
string
should specify the full, absolute name of
a class.
defaultValue
is set to the constant
Strings.CLASS_MUST_BE_VALID
, an exception will be thrown.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the class name
Class
found at the given location defined in
the string
, or the default value if the
string
is invalid
ParseValueException
- if the path specified by the
string
value must be valid but
could not be parsed as a valid
Class
public static Class parseClass(String string, String relativeToPackage, Class defaultValue)
Class
from a String
, returning
the default value if the string was invalid.
string
should specify the name of a class, with
the package path, either absolute or relative to the given package.
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the class namerelativeToPackage
- the base location to use if the class name
defined by the string
is not an
absolute pathdefaultValue
- the default value to be used if the
string
is not valid
Class
found at the given location defined in
the string
, or the default value if the
string
is invalidpublic static Class parseClass(String string, Class defaultValue)
Class
from a String
, returning
the default value if the string was invalid.
string
should specify the full, absolute name of
a class.
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the class namedefaultValue
- the default value to be used if the
string
is not valid
Class
found at the given location defined in
the string
, or the default value if the
string
is invalidpublic static EnumValue parseEnumValue(String string, Enumeration enumeration) throws ParseValueException
Enumeration
type
from a String
.
string
should specify one of the values in the
enumeration
.
null
.
string
- the String
value containing the enum valueenumeration
- the enumeration type
EnumValue
referenced by the string
ParseValueException
- if the string
could not be
parsed as a valid EnumValue
public static EnumValue parseEnumValue(EnumValue defaultValue, String string, Enumeration enumeration) throws ParseValueException
Enumeration
type
from a String
, returning the default value if the string was
invalid.
string
should specify one of the values in the
enumeration
.
defaultValue
is set to
the constant Strings.ENUM_VALUE_MUST_BE_VALID
, an exception
will be thrown.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
value containing the enum valueenumeration
- the enumeration type
EnumValue
referenced by the string
,
or the default value if the string
is invalid
ParseValueException
- if the string
must reference an
enumeration value but could not be parsed as
a valid EnumValue
public static EnumValue parseEnumValue(String string, Enumeration enumeration, EnumValue defaultValue)
Enumeration
type
from a String
, returning the default value if the string was
invalid.
string
should specify one of the values in the
enumeration
.
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the enum valueenumeration
- the enumeration typedefaultValue
- the default value to be used if the
string
is not valid
EnumValue
referenced by the string
,
or the default value if the string
is invalidpublic static Object parseObject(String string, Collection validObjects) throws ParseValueException
String
.
string
should relate to one of the objects in the
a collection of accepted values.
null
.
string
- the String
valuevalidObjects
- a collection of acceptable objects
Object
s from the validValues
collection, referenced by the string
ParseValueException
- if the string
could not be
parsed as a valid Object
public static Object parseObject(Object defaultValue, String string, Collection validObjects) throws ParseValueException
String
, returning the default value
if the string was invalid.
string
should relate to one of the objects in the
a collection of accepted values.
defaultValue
is set to
the constant Strings.OBJECT_MUST_BE_VALID
, an exception will
be thrown.
null
, provided the
defaultValue
is not null
.
defaultValue
- the default value to be used if the
string
is not validstring
- the String
valuevalidObjects
- a collection of acceptable objects
Object
s from the validValues
collection, referenced by the string
,
or the default value if the string
is invalid
ParseValueException
- if the string
must reference one
of the valid values but could not be parsed
as a valid Object
public static Object parseObject(String string, Collection validObjects, Object defaultValue)
String
, returning the default value
if the string was invalid.
string
should relate to one of the objects in the
a collection of accepted values.
null
, provided the
defaultValue
is not null
.
string
- the String
valuevalidObjects
- a collection of acceptable objectsdefaultValue
- the default value to be used if the
string
is not valid
Object
s from the validValues
collection, referenced by the string
,
or the default value if the string
is invalidpublic static Color parseColor(String string) throws ParseValueException
Color
from a String
, returning
the default value if the string was invalid.
string
should specify a colour in either:
"[AAA] RRR GGG BBB"
where
AAA
, RRR
, GGG
and BBB
are 16-bit decimal values (0-255) for the alpha, red, green and blue
components of the colour (alpha optional) each separated by one or more
whitespace characters
"#[AA]RRGGBB"
where
AA
, RR
, GG
and BB
are
16-bit hex values for the alpha, red, green and blue components of the
colour (alpha optional)
"#[AA]RRGGBB"
format
null
.
string
- the String
value containing the color
specification
Color
object for the color specified by the
string
ParseValueException
- if the string does not conform to the
required formatpublic static Color parseColor(Color defaultValue, String string) throws ParseValueException
Color
from a String
, returning
the default value if the string was invalid.
string
should specify a colour in either:
"[AAA] RRR GGG BBB"
where
AAA
, RRR
, GGG
and BBB
are 16-bit decimal values (0-255) for the alpha, red, green and blue
components of the colour (alpha optional) each separated by one or more
whitespace characters
"#[AA]RRGGBB"
where
AA
, RR
, GG
and BB
are
16-bit hex values for the alpha, red, green and blue components of the
colour (alpha optional)
"#[AA]RRGGBB"
format
defaultValue
is set to the constant
Strings.COLOR_MUST_BE_VALID
, an exception will be thrown.
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the color
specificationdefaultValue
- the default value to be used if the
string
does not specify a color
Color
object for the color specified by the
string
, or the default value if the
string
is invalid
ParseValueException
- if the color specified by the
string
value must be valid but
the string does not conform to the required
formatpublic static Color parseColor(String string, Color defaultValue)
Color
from a String
, returning
the default value if the string was invalid.
string
should specify a colour in either:
"[AAA] RRR GGG BBB"
where
AAA
, RRR
, GGG
and BBB
are 16-bit decimal values (0-255) for the alpha, red, green and blue
components of the colour (alpha optional) each separated by one or more
whitespace characters
"#[AA]RRGGBB"
where
AA
, RR
, GG
and BB
are
16-bit hex values for the alpha, red, green and blue components of the
colour (alpha optional)
"#[AA]RRGGBB"
format
null
, provided the
defaultValue
is not null
.
string
- the String
value containing the color
specificationdefaultValue
- the default value to be used if the
string
does not specify a color
Color
object for the color specified by the
string
, or the default value if the
string
is invalidpublic static String serializeColor(Color value)
Color
as a String
.
#[AA]RRGGBB
(alpha, red, green, blue).
value
- the Color
value
String
representing the given colourpublic static final int[] parseInts(String string) throws ParseValueException
string
- the string to be parsed
ParseValueException
- if any value is outside the specified range
or the string contains any non-numeric textpublic static final int[] parseInts(String string, String delimiters) throws ParseValueException
string
- the string to be parseddelimiters
- a list of characters, any of which may separate the
integer values in the input string
ParseValueException
- if any value is outside the specified range
or the string contains any non-numeric textpublic static final int[] parseInts(String string, int minValue, int maxValue) throws ParseValueException
string
- the string to be parsedminValue
- the minimum value for each individual numbermaxValue
- the maximum value for each individual number
ParseValueException
- if any value is outside the specified range
or the string contains any non-numeric textpublic static final int[] parseInts(String string, String delimiters, int minValue, int maxValue) throws ParseValueException
string
- the string to be parseddelimiters
- a list of characters, any of which may separate the
integer values in the input stringminValue
- the minimum value for each individual numbermaxValue
- the maximum value for each individual number
ParseValueException
- if any value is outside the specified range
or the string contains any non-numeric textpublic static String rightAlign(String string, int length, char pad, boolean truncate)
string
- the original piece of textlength
- the length of the resultant stringpad
- the character to be used to pad the string to the desired
lengthtruncate
- set to true
if the original string should be
truncated to the desired length
public static String rightAlign(String string, int length, boolean truncate)
string
- the original piece of textlength
- the length of the resultant stringtruncate
- set to true
if the original string should be
truncated to the desired length
public static String rightAlign(String string, int length, char pad)
string
- the original piece of textlength
- the length of the resultant stringpad
- the character to be used to pad the string to the desired
length
public static String rightAlign(String string, int length)
string
- the original piece of textlength
- the length of the resultant string
public static boolean containsAny(String string, String chars)
chars
string such that the characters more likely to match
appear towards the start.
string
- the string to testchars
- the characters to look for
true
if the string contains any of the characterspublic static boolean containsAll(String string, String chars)
chars
string such that the characters least likely to match
appear towards the start.
string
- the string to testchars
- the characters to look for
true
if the string contains all of the characterspublic static String firstLine(String text)
text
- the text to be sampled
public static String nextLine(String text, int fromIndex)
text
- the text to be sampledfromIndex
- the index of the start of the line within the text string
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |