|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.sonalb.Utils
public abstract class Utils
Utility class containing several general-purpose methods for system-wide consumption.
Method Summary | |
---|---|
static java.lang.String |
commaFormatInteger(int i)
Converts the input integer into a more readable comma-separated String. |
static java.lang.String |
convertToHttpDate(java.util.Date d)
Converts the input Date into a String formatted as specified by RFC 1123 of the IETF. |
static int |
countInstances(java.lang.String s,
char c)
Counts the number of times the specified character appears in the input String. |
static int |
countInstances(java.lang.String s,
java.lang.String c)
Counts the number of times the specified String appears in the input String. |
static java.lang.String[] |
csvStringToArray(java.lang.String s)
Tokenizes the argument String into several constituent Strings, separated by commas, and returns the tokens as an array. |
static java.lang.String[] |
delimitedStringToArray(java.lang.String s,
java.lang.String delimiters)
Tokenizes the argument String into several constituent Strings, separated by specified delimiters, and returns the tokens as an array. |
static java.lang.Object |
findMax(java.lang.Comparable[] inputlist,
int n)
Returns the nth largest object in the input array. |
static int |
findMax(int[] inputlist,
int n)
Returns the nth largest number in the input array. |
static java.lang.Object |
findMax(java.lang.Object[] inputlist,
int n,
java.util.Comparator c)
Returns the nth largest object in the input array. |
static java.lang.Object |
findMin(java.lang.Comparable[] inputlist,
int n)
Returns the nth smallest object in the input array. |
static int |
findMin(int[] inputlist,
int n)
Returns the nth smallest number in the input array. |
static java.lang.Object |
findMin(java.lang.Object[] inputlist,
int n,
java.util.Comparator c)
Returns the nth smallest object in the input array. |
static java.lang.Object |
findOrderedMax(java.lang.Comparable[] inputlist,
int n)
Returns the object which would be in the nth place if the input array were sorted in descending order. |
static int |
findOrderedMax(int[] inputlist,
int n)
Returns the number which would be in the nth place if the input array were sorted in descending order. |
static java.lang.Object |
findOrderedMax(java.lang.Object[] inputlist,
int n,
java.util.Comparator c)
Returns the object which would be in the nth place if the input array were sorted in descending order. |
static java.lang.Object |
findOrderedMin(java.lang.Comparable[] inputlist,
int n)
Returns the object which would be in the nth place if the input array were sorted in ascending order. |
static int |
findOrderedMin(int[] inputlist,
int n)
Returns the number which would be in the nth place if the input array were sorted in ascending order. |
static java.lang.Object |
findOrderedMin(java.lang.Object[] inputlist,
int n,
java.util.Comparator c)
Returns the object which would be in the nth place if the input array were sorted in ascending order. |
static boolean |
isEmpty(java.lang.String s)
Returns true if argument is either null or it equals(""). |
static boolean |
isInArray(java.lang.Object obj,
java.lang.Object[] array)
Checks whether the specified Object exists in the given array. |
static boolean |
isIPAddress(java.lang.String s)
Checks whether the input String is a valid IP address (quad). |
static boolean |
isNullOrWhiteSpace(java.lang.String s)
Returns true if argument is either null or is full of
whitespace. |
static boolean |
isQuoted(java.lang.String s)
Determines whether the input String is enclosed in double-quotes. |
static boolean |
matchQuotes(java.lang.String s)
Determines whether every double-quote has its closing partner in the input String. |
static java.util.Date |
parseHttpDateStringToDate(java.lang.String date)
Parses the input date String into a Date object. |
static java.lang.String |
replaceAll(java.lang.String source,
java.lang.String find,
java.lang.String replace,
boolean bIgnoreCase)
Replaces all occurrences of a String in the input String with another String. |
static java.lang.String |
stripQuotes(java.lang.String s)
Removes the outermost double-quotes pair from the input String. |
static java.lang.String |
trimLeftWS(java.lang.String s)
Returns the String obtained by removing any whitespace at the left hand side of the argument. |
static java.lang.String |
trimRightWS(java.lang.String s)
Returns the String obtained by removing any whitespace at the right hand side of the argument. |
static java.lang.String |
trimWhitespace(java.lang.String s)
Returns the String obtained by removing any whitespace at both ends of the argument. |
static java.lang.String |
trimWS(java.lang.String s)
Convenience synonym for trimWhitespace(String) . |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static boolean isNullOrWhiteSpace(java.lang.String s)
null
or is full of
whitespace. The argument is full of whitespace if after calling
String.trim()
on it, it equals(""). In other words,
whitespace determination is done by String.trim()
.
s
- the String to be tested.String.trim()
public static java.lang.String trimWhitespace(java.lang.String s)
Character.isWhitespace(char)
. It is different from
String.trim()
which also removes any control characters.
s
- the String to be trimmed.
Character.isWhitespace(char)
,
String.trim()
public static java.lang.String trimLeftWS(java.lang.String s)
Character.isWhitespace(char)
.
s
- the String to be trimmed.
Character.isWhitespace(char)
public static java.lang.String trimRightWS(java.lang.String s)
Character.isWhitespace(char)
.
s
- the String to be trimmed.
Character.isWhitespace(char)
public static java.lang.String trimWS(java.lang.String s)
trimWhitespace(String)
.
s
- the String to be trimmed.
trimWhitespace(String)
public static java.lang.String[] csvStringToArray(java.lang.String s)
s
- the String to be tokenized.
delimitedStringToArray(String, String)
public static java.lang.String[] delimitedStringToArray(java.lang.String s, java.lang.String delimiters)
s
- the String to be tokenized.delimiters
- the String of delimiters.
public static boolean isInArray(java.lang.Object obj, java.lang.Object[] array)
Object.equals(Object)
method is used to test for equality.
obj
- the Object to be searched for.array
- the array which has to be searched.
true
if the Object exists in the array;
false
if the Object does not exist in the array,
or the object, or the array is null
.Object.equals(Object)
public static int countInstances(java.lang.String s, char c)
countInstances("abcabcdabcde",'a')
returns 3.
s
- the String to be counted in.c
- the character to be counted.
c
in s
;
-1 if s
is null
.public static int countInstances(java.lang.String s, java.lang.String c)
countInstances("abcabcdabcde","cd")
returns 2.
s
- the String to be counted in.c
- the String to be counted.
c
in s
;
-1 if s
or c
is null
.public static boolean isIPAddress(java.lang.String s)
s
- the String to be checked.
true
if the String IS an IP address ;
false
if it is not, or s
is
null
.InetAddress
public static java.lang.String convertToHttpDate(java.util.Date d)
d
- the Date to be converted.
null
if input is null
.Date
public static java.util.Date parseHttpDateStringToDate(java.lang.String date)
date
- the HTTP date String to be converted.
null
if parsing was
unsuccessful or input was null
.public static boolean isEmpty(java.lang.String s)
null
or it equals("").
It does not trim the input, unlike
isNullOrWhiteSpace(String)
.
s
- the String to be tested.isNullOrWhiteSpace(String)
public static java.lang.String replaceAll(java.lang.String source, java.lang.String find, java.lang.String replace, boolean bIgnoreCase) throws java.lang.IllegalArgumentException
source
- the String in which the replacements are to be carried out.find
- the String which must be searched for.replace
- the String which replaces the search String.bIgnoreCase
- determines whether case-sensitive search is done.
java.lang.IllegalArgumentException
- Thrown if source String is empty.public static boolean matchQuotes(java.lang.String s)
s
- the String to be tested.
true
if quotes match or no quotes exist ;
false
otherwise.public static java.lang.String stripQuotes(java.lang.String s)
s
- the String to be stripped.
public static boolean isQuoted(java.lang.String s)
s
- the String to be tested.
true
if input String is quoted ;
false
if it isn't or it is empty.trimWhitespace(String)
public static java.lang.String commaFormatInteger(int i)
12345 is converted to 12,345 987654321 is converted to 987,654,321
i
- the integer to be converted.
String.valueOf(int)
String.valueOf(int)
public static int findOrderedMax(int[] inputlist, int n)
findOrderedMax(list, 3)
would
return 4. However, the result is quite different in arrays with repeated
elements. For example, in the array {1,2,6,2}, both
findOrderedMax(list,2)
and
findOrderedMax(list,3)
return 2.
inputlist
- the array of numbers.n
- the desired position of sorted array. For example, 1 indicates
first from top of sorted array; 2 indicates second from top,
and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findMax(int[],int)
public static int findMax(int[] inputlist, int n)
findOrderedMax
method. For example, in the array
{1,2,3,4,5,6}, findMax(list, 3)
would return 4. In the
array {1,2,6,2}, findMax(list,2)
would return 2, and and
findMax(list,3)
would return 1.
Note that in an array with repeating elements, it is possible that the
required order may not exist. For example, in the array {1,2,2},
findMax(list,3)
, there is no third-largest number. In
such cases, this method returns the number with highest order less than
or equal to n
. In other words, in the above example, this
method would return 1, which is the same value as would be returned by
findMax(list,2)
.
inputlist
- the array of numbers.n
- the desired order. For example, 1 indicates largest number; 2
indicates second-largest number, and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findOrderedMax(int[],int)
public static int findOrderedMin(int[] inputlist, int n)
findOrderedMin(list, 3)
would
return 3. However, the result is quite different in arrays with repeated
elements. For example, in the array {1,2,6,2}, both
findOrderedMin(list,2)
and
findOrderedMin(list,3)
return 2.
inputlist
- the array of numbers.n
- the desired position of sorted array. For example, 1 indicates
first from top of sorted array; 2 indicates second from top,
and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findMin(int[],int)
public static int findMin(int[] inputlist, int n)
findOrderedMin
method. For example, in the array
{1,2,3,4,5,6}, findMin(list, 3)
would return 3. In the
array {1,2,6,2}, findMin(list,2)
would return 2, and and
findMin(list,3)
would return 6.
Note that in an array with repeating elements, it is possible that the
required order may not exist. For example, in the array {1,2,2},
findMin(list,3)
, there is no third-smallest number. In
such cases, this method returns the number with highest order less than
or equal to n
. In other words, in the above example, this
method would return 2, which is the same value as would be returned by
findMax(list,2)
.
inputlist
- the array of numbers.n
- the desired order. For example, 1 indicates smallest number; 2
indicates second-smallest number, and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findOrderedMin(int[],int)
public static java.lang.Object findOrderedMax(java.lang.Comparable[] inputlist, int n)
Object
s. It follows similar semantics as
the findOrderedMax(int[], int)
method.
inputlist
- the array of Comparable
objects. All elements
must be mutually Comparable (that is, e1.compareTo(e2)
must not throw a ClassCastException for any elements e1 and e2
in the array).n
- the desired position of sorted array. For example, 1 indicates
first from top of sorted array; 2 indicates second from top,
and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findMax(Comparable[],int)
,
findOrderedMax(int[],int)
public static java.lang.Object findMax(java.lang.Comparable[] inputlist, int n)
Object
s. It follows similar
semantics as the findMax(int[], int)
method.
inputlist
- the array of Comparable
objects. All elements
must be mutually Comparable (that is, e1.compareTo(e2)
must not throw a ClassCastException for any elements e1 and e2
in the array).n
- the desired order. For example, 1 indicates largest object; 2
indicates second-largest object, and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findOrderedMax(Comparable[],int)
,
findMax(int[],int)
public static java.lang.Object findOrderedMin(java.lang.Comparable[] inputlist, int n)
Object
s. It follows similar semantics as the
findOrderedMin(int[], int)
method.
inputlist
- the array of Comparable
objects. All elements
must be mutually Comparable (that is, e1.compareTo(e2)
must not throw a ClassCastException for any elements e1 and e2
in the array).n
- the desired position of sorted array. For example, 1 indicates
first from top of sorted array; 2 indicates second from top,
and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findMin(Comparable[],int)
,
findOrderedMin(int[],int)
public static java.lang.Object findMin(java.lang.Comparable[] inputlist, int n)
Object
s. It follows similar
semantics as the findMin(int[], int)
method.
inputlist
- the array of Comparable
objects. All elements
must be mutually Comparable (that is, e1.compareTo(e2)
must not throw a ClassCastException for any elements e1 and e2
in the array).n
- the desired order. For example, 1 indicates smallest object; 2
indicates second-smallest object, and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findOrderedMin(Comparable[],int)
,
findMin(int[],int)
public static java.lang.Object findOrderedMax(java.lang.Object[] inputlist, int n, java.util.Comparator c)
Object
s. The comparison logic is provided
by the Comparator
argument. It follows similar semantics
as the findOrderedMax(int[], int)
method.
c
- the Comparator
that provides the ordering
logic.inputlist
- the array of Object
s.n
- the desired position of sorted array. For example, 1 indicates
first from top of sorted array; 2 indicates second from top,
and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findMax(Object[],int,Comparator)
,
findOrderedMax(int[],int)
public static java.lang.Object findMax(java.lang.Object[] inputlist, int n, java.util.Comparator c)
Object
s. The comparison logic
is provided by the Comparator
argument. It follows similar
semantics as the findMax(int[], int)
method.
c
- the Comparator
that provides the ordering
logic.inputlist
- the array of Object
s.n
- the desired order. For example, 1 indicates largest object; 2
indicates second-largest object, and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findOrderedMax(Object[],int,Comparator)
,
findMax(int[],int)
public static java.lang.Object findOrderedMin(java.lang.Object[] inputlist, int n, java.util.Comparator c)
Object
s. The comparison logic is provided by the
Comparator
argument. It follows similar semantics as the
findOrderedMin(int[], int)
method.
c
- the Comparator
that provides the ordering
logic.inputlist
- the array of Object
s.n
- the desired position of sorted array. For example, 1 indicates
first from top of sorted array; 2 indicates second from top,
and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findMin(Object[],int,Comparator)
,
findOrderedMin(int[],int)
public static java.lang.Object findMin(java.lang.Object[] inputlist, int n, java.util.Comparator c)
Object
s. The comparison logic
is provided by the Comparator
argument. It follows similar
semantics as the findMin(int[], int)
method.
c
- the Comparator
that provides the ordering
logic.inputlist
- the array of Objects
.n
- the desired order. For example, 1 indicates smallest object; 2
indicates second-smallest object, and so on.
java.lang.IllegalArgumentException
- Thrown when the number of elements in the input array is less
than the desired order, that is, when n
exceeds inputlist.length
. Or, when the order
n
is less than or equal to 0.findOrderedMin(Object[],int,Comparator)
,
findMin(int[],int)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |