|
jCookie v0.8b | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.sonalb.Utils
Utility class containing several general-purpose methods for system-wide consumption.
Method Summary | |
static String |
commaFormatInteger(int i)
Converts the input integer into a more readable comma-separated String. |
static String |
convertToHttpDate(Date d)
Converts the input Date into a String formatted as specified by RFC 1123 of the IETF. |
static int |
countInstances(String s,
char c)
Counts the number of times the specified character appears in the input String. |
static int |
countInstances(String s,
String c)
Counts the number of times the specified String appears in the input String. |
static String[] |
csvStringToArray(String s)
Tokenizes the argument String into several constituent Strings, separated by commas, and returns the tokens as an array. |
static String[] |
delimitedStringToArray(String s,
String delimiters)
Tokenizes the argument String into several constituent Strings, separated by specified delimiters, and returns the tokens as an array. |
static Object |
findMax(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 Object |
findMax(Object[] inputlist,
int n,
Comparator c)
Returns the nth largest object in the input array. |
static Object |
findMin(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 Object |
findMin(Object[] inputlist,
int n,
Comparator c)
Returns the nth smallest object in the input array. |
static Object |
findOrderedMax(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 Object |
findOrderedMax(Object[] inputlist,
int n,
Comparator c)
Returns the object which would be in the nth place if the input array were sorted in descending order. |
static Object |
findOrderedMin(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 Object |
findOrderedMin(Object[] inputlist,
int n,
Comparator c)
Returns the object which would be in the nth place if the input array were sorted in ascending order. |
static boolean |
isEmpty(String s)
Returns true if argument is either null or it equals(""). |
static boolean |
isInArray(Object obj,
Object[] array)
Checks whether the specified Object exists in the given array. |
static boolean |
isIPAddress(String s)
Checks whether the input String is a valid IP address (quad). |
static boolean |
isNullOrWhiteSpace(String s)
Returns true if argument is either null or is full of
whitespace. |
static boolean |
isQuoted(String s)
Determines whether the input String is enclosed in double-quotes. |
static boolean |
matchQuotes(String s)
Determines whether every double-quote has its closing partner in the input String. |
static Date |
parseHttpDateStringToDate(String date)
Parses the input date String into a Date object. |
static String |
replaceAll(String source,
String find,
String replace,
boolean bIgnoreCase)
Replaces all occurrences of a String in the input String with another String. |
static String |
stripQuotes(String s)
Removes the outermost double-quotes pair from the input String. |
static String |
trimLeftWS(String s)
Returns the String obtained by removing any whitespace at the left hand side of the argument. |
static String |
trimRightWS(String s)
Returns the String obtained by removing any whitespace at the right hand side of the argument. |
static String |
trimWhitespace(String s)
Returns the String obtained by removing any whitespace at both ends of the argument. |
static String |
trimWS(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(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 String trimWhitespace(String s)
Character.isWhitespace(char)
. It is
different from String.trim()
which also removes any control characters.s
- the String to be trimmed.java.lang.Character#isWhitespace(char)
,
String.trim()
public static String trimLeftWS(String s)
Character.isWhitespace(char)
.s
- the String to be trimmed.java.lang.Character#isWhitespace(char)
public static String trimRightWS(String s)
Character.isWhitespace(char)
.s
- the String to be trimmed.java.lang.Character#isWhitespace(char)
public static String trimWS(String s)
trimWhitespace(String)
.s
- the String to be trimmed.trimWhitespace(String)
public static String[] csvStringToArray(String s)
s
- the String to be tokenized.delimitedStringToArray(String, String)
public static String[] delimitedStringToArray(String s, String delimiters)
s
- the String to be tokenized.delimiters
- the String of delimiters.public static boolean isInArray(Object obj, 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(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(String s, 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(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 String convertToHttpDate(Date d)
d
- the Date to be converted.null
if input is null
.Date
public static Date parseHttpDateStringToDate(String date)
date
- the HTTP date String to be converted.null
if
parsing was unsuccessful or input was null
.public static boolean isEmpty(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 String replaceAll(String source, String find, String replace, boolean bIgnoreCase) throws 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.IllegalArgumentException
- Thrown if source String is empty.public static boolean matchQuotes(String s)
s
- the String to be tested.true
if quotes match or no quotes exist ; false
otherwise.public static String stripQuotes(String s)
s
- the String to be stripped.public static boolean isQuoted(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 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.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.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.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.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 Object findOrderedMax(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.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 Object findMax(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.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 Object findOrderedMin(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.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 Object findMin(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.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 Object findOrderedMax(Object[] inputlist, int n, 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.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 Object findMax(Object[] inputlist, int n, 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.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 Object findOrderedMin(Object[] inputlist, int n, 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.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 Object findMin(Object[] inputlist, int n, 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.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)
|
Copyright (c) 2001-2002 Sonal Bansal | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |