|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.easetech.easytest.util.CommonUtils
public class CommonUtils
This class contains common utils
| Field Summary | |
|---|---|
static String |
URL_PROTOCOL_FILE
URL protocol for a file in the file system: "file" |
| Constructor Summary | |
|---|---|
CommonUtils()
|
|
| Method Summary | |
|---|---|
static String |
cleanPath(String path)
Normalize the path by suppressing sequences like "path/.." and inner simple dots. |
static String |
collectionToDelimitedString(Collection coll,
String delim)
Convenience method to return a Collection as a delimited (e.g. |
static String |
collectionToDelimitedString(Collection coll,
String delim,
String prefix,
String suffix)
Convenience method to return a Collection as a delimited (e.g. |
static String |
createDefaultOutputFolder(String destinationFolder)
Create directory |
static String |
createFolder(String absoluteLocation)
Creates directory. |
static String |
deleteAny(String inString,
String charsToDelete)
Delete any character in a given String. |
static String[] |
delimitedListToStringArray(String str,
String delimiter)
Take a String which is a delimited list and convert it to a String array. |
static String[] |
delimitedListToStringArray(String str,
String delimiter,
String charsToDelete)
Take a String which is a delimited list and convert it to a String array. |
static String |
getAbsoluteLocation(String location)
Returns the absolute path of either the classpath or file location |
static String |
getCurrentFolder()
|
static File |
getFile(URI resourceUri)
Resolve the given resource URI to a java.io.File,
i.e. to a file in the file system. |
static File |
getFile(URI resourceUri,
String description)
Resolve the given resource URI to a java.io.File,
i.e. to a file in the file system. |
static File |
getFile(URL resourceUrl)
Resolve the given resource URL to a java.io.File,
i.e. to a file in the file system. |
static File |
getFile(URL resourceUrl,
String description)
Resolve the given resource URL to a java.io.File,
i.e. to a file in the file system. |
static String |
getFormattedDate(Date date)
Format date with pattern ddMMyyyyHHmmss |
static Double |
getRounded(double valueToRound,
int numberOfDecimalPlaces)
Rounds a value with number of decimals |
static boolean |
hasLength(String str)
Check that the given String is neither null nor of length 0. |
static String |
replace(String inString,
String oldPattern,
String newPattern)
Replace all occurences of a substring within a string with another string. |
static String[] |
toStringArray(Collection collection)
Copy the given Collection into a String array. |
static URI |
toURI(String location)
Create a URI instance for the given location String, replacing spaces with "%20" quotes first. |
static URI |
toURI(URL url)
Create a URI instance for the given URL, replacing spaces with "%20" quotes first. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String URL_PROTOCOL_FILE
| Constructor Detail |
|---|
public CommonUtils()
| Method Detail |
|---|
public static Double getRounded(double valueToRound,
int numberOfDecimalPlaces)
valueToRound - numberOfDecimalPlaces -
public static String createDefaultOutputFolder(String destinationFolder)
destinationFolder -
public static String getCurrentFolder()
public static String createFolder(String absoluteLocation)
absoluteLocation -
public static String getFormattedDate(Date date)
date -
public static String getAbsoluteLocation(String location)
location -
public static String cleanPath(String path)
The result is convenient for path comparison. For other uses, notice that Windows separators ("\") are replaced by simple slashes.
path - the original path
public static String collectionToDelimitedString(Collection coll,
String delim)
toString() implementations.
coll - the Collection to displaydelim - the delimiter to use (probably a ",")
public static String collectionToDelimitedString(Collection coll,
String delim,
String prefix,
String suffix)
toString() implementations.
coll - the Collection to displaydelim - the delimiter to use (probably a ",")prefix - the String to start each element withsuffix - the String to end each element with
public static String[] delimitedListToStringArray(String str,
String delimiter)
A single delimiter can consists of more than one character: It will still
be considered as single delimiter string, rather than as bunch of potential
delimiter characters - in contrast to tokenizeToStringArray.
str - the input Stringdelimiter - the delimiter between elements (this is a single delimiter,
rather than a bunch individual delimiter characters)
#tokenizeToStringArray
public static String[] delimitedListToStringArray(String str,
String delimiter,
String charsToDelete)
A single delimiter can consists of more than one character: It will still
be considered as single delimiter string, rather than as bunch of potential
delimiter characters - in contrast to tokenizeToStringArray.
str - the input Stringdelimiter - the delimiter between elements (this is a single delimiter,
rather than a bunch individual delimiter characters)charsToDelete - a set of characters to delete. Useful for deleting unwanted
line breaks: e.g. "\r\n\f" will delete all new lines and line feeds in a String.
#tokenizeToStringArraypublic static String[] toStringArray(Collection collection)
collection - the Collection to copy
null if the passed-in
Collection was null)
public static String deleteAny(String inString,
String charsToDelete)
inString - the original StringcharsToDelete - a set of characters to delete.
E.g. "az\n" will delete 'a's, 'z's and new lines.
public static boolean hasLength(String str)
null nor of length 0.
Note: Will return true for a String that purely consists of whitespace.
StringUtils.hasLength(null) = false
StringUtils.hasLength("") = false
StringUtils.hasLength(" ") = true
StringUtils.hasLength("Hello") = true
str - the String to check (may be null)
true if the String is not null and has length#hasText(String)
public static String replace(String inString,
String oldPattern,
String newPattern)
inString - String to examineoldPattern - String to replacenewPattern - String to insert
public static File getFile(URI resourceUri)
throws FileNotFoundException
java.io.File,
i.e. to a file in the file system.
resourceUri - the resource URI to resolve
FileNotFoundException - if the URL cannot be resolved to
a file in the file system
public static File getFile(URI resourceUri,
String description)
throws FileNotFoundException
java.io.File,
i.e. to a file in the file system.
resourceUri - the resource URI to resolvedescription - a description of the original resource that
the URI was created for (for example, a class path location)
FileNotFoundException - if the URL cannot be resolved to
a file in the file system
public static File getFile(URL resourceUrl)
throws FileNotFoundException
java.io.File,
i.e. to a file in the file system.
resourceUrl - the resource URL to resolve
FileNotFoundException - if the URL cannot be resolved to
a file in the file system
public static File getFile(URL resourceUrl,
String description)
throws FileNotFoundException
java.io.File,
i.e. to a file in the file system.
resourceUrl - the resource URL to resolvedescription - a description of the original resource that
the URL was created for (for example, a class path location)
FileNotFoundException - if the URL cannot be resolved to
a file in the file system
public static URI toURI(URL url)
throws URISyntaxException
Furthermore, this method works on JDK 1.4 as well,
in contrast to the URL.toURI() method.
url - the URL to convert into a URI instance
URISyntaxException - if the URL wasn't a valid URIURL.toURI()
public static URI toURI(String location)
throws URISyntaxException
location - the location String to convert into a URI instance
URISyntaxException - if the location wasn't a valid URI
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||