Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.sonalb
Class Utils  view Utils download Utils.java

java.lang.Object
  extended bycom.sonalb.Utils

public abstract class Utils
extends java.lang.Object

Utility class containing several general-purpose methods for system-wide consumption.


Field Summary
static java.lang.String CVSID
           
 
Constructor Summary
private Utils()
           
 
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CVSID

public static final java.lang.String CVSID
See Also:
Constant Field Values
Constructor Detail

Utils

private Utils()
Method Detail

isNullOrWhiteSpace

public static boolean isNullOrWhiteSpace(java.lang.String s)
Returns true if argument is either 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().


trimWhitespace

public static java.lang.String trimWhitespace(java.lang.String s)
Returns the String obtained by removing any whitespace at both ends of the argument. Whitespace is defined as stated by Character.isWhitespace(char). It is different from String.trim() which also removes any control characters.


trimLeftWS

public 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. Whitespace is defined as stated by Character.isWhitespace(char).


trimRightWS

public 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. Whitespace is defined as stated by Character.isWhitespace(char).


trimWS

public static java.lang.String trimWS(java.lang.String s)
Convenience synonym for trimWhitespace(String).


csvStringToArray

public 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.


delimitedStringToArray

public 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. Every character of the delimiter String is treated as a token-separator individually.


isInArray

public static boolean isInArray(java.lang.Object obj,
                                java.lang.Object[] array)
Checks whether the specified Object exists in the given array. The Object.equals(Object) method is used to test for equality.


countInstances

public static int countInstances(java.lang.String s,
                                 char c)
Counts the number of times the specified character appears in the input String. For example, countInstances("abcabcdabcde",'a') returns 3.


countInstances

public static int countInstances(java.lang.String s,
                                 java.lang.String c)
Counts the number of times the specified String appears in the input String. For example, countInstances("abcabcdabcde","cd") returns 2.


isIPAddress

public static boolean isIPAddress(java.lang.String s)
Checks whether the input String is a valid IP address (quad).


convertToHttpDate

public 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. The output String is in the format "Sun, 06 Nov 1994 08:49:37 GMT".


parseHttpDateStringToDate

public static java.util.Date parseHttpDateStringToDate(java.lang.String date)
Parses the input date String into a Date object. The input date String is expected to be in one of the following formats (note the spaces) :-

  • "Sun, 06 Nov 1994 08:49:37 GMT" ; RFC 822, updated by RFC 1123
  • "Sunday, 06-Nov-94 08:49:37 GMT" ; RFC 850, obsoleted by RFC 1036
  • "Sunday, 06-Nov-1994 08:49:37 GMT" ; RFC 1036
  • "Sun Nov 6 08:49:37 1994" ; ANSI C's asctime() format


isEmpty

public static boolean isEmpty(java.lang.String s)
Returns true if argument is either null or it equals(""). It does not trim the input, unlike isNullOrWhiteSpace(String).


replaceAll

public static java.lang.String replaceAll(java.lang.String source,
                                          java.lang.String find,
                                          java.lang.String replace,
                                          boolean bIgnoreCase)
                                   throws java.lang.IllegalArgumentException
Replaces all occurrences of a String in the input String with another String.


matchQuotes

public static boolean matchQuotes(java.lang.String s)
Determines whether every double-quote has its closing partner in the input String.


stripQuotes

public static java.lang.String stripQuotes(java.lang.String s)
Removes the outermost double-quotes pair from the input String. Trims the input String before processing.


isQuoted

public static boolean isQuoted(java.lang.String s)
Determines whether the input String is enclosed in double-quotes. Trims the input String first.


commaFormatInteger

public static java.lang.String commaFormatInteger(int i)
Converts the input integer into a more readable comma-separated String. A comma is inserted after every three digits, starting from the unit's place. For example,


     12345        is converted to     12,345

     987654321    is converted to     987,654,321


findOrderedMax

public 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. For arrays with distinct elements, this returns the nth largest number. For example, in the array {1,2,3,4,5,6}, 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.


findMax

public static int findMax(int[] inputlist,
                          int n)
Returns the nth largest number in the input array. This method disregards duplicate elements unlike the 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).


findOrderedMin

public 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. For arrays with distinct elements, this returns the nth smallest number. For example, in the array {1,2,3,4,5,6}, 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.


findMin

public static int findMin(int[] inputlist,
                          int n)
Returns the nth smallest number in the input array. This method disregards duplicate elements unlike the 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).


findOrderedMax

public 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. This method allows comparison of Objects. It follows similar semantics as the findOrderedMax(int[], int) method.


findMax

public static java.lang.Object findMax(java.lang.Comparable[] inputlist,
                                       int n)
Returns the nth largest object in the input array. This method allows comparison of Objects. It follows similar semantics as the findMax(int[], int) method.


findOrderedMin

public 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. This method allows comparison of Objects. It follows similar semantics as the findOrderedMin(int[], int) method.


findMin

public static java.lang.Object findMin(java.lang.Comparable[] inputlist,
                                       int n)
Returns the nth smallest object in the input array. This method allows comparison of Objects. It follows similar semantics as the findMin(int[], int) method.


findOrderedMax

public 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. This method allows comparison of Objects. The comparison logic is provided by the Comparator argument. It follows similar semantics as the findOrderedMax(int[], int) method.


findMax

public static java.lang.Object findMax(java.lang.Object[] inputlist,
                                       int n,
                                       java.util.Comparator c)
Returns the nth largest object in the input array. This method allows comparison of Objects. The comparison logic is provided by the Comparator argument. It follows similar semantics as the findMax(int[], int) method.


findOrderedMin

public 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. This method allows comparison of Objects. The comparison logic is provided by the Comparator argument. It follows similar semantics as the findOrderedMin(int[], int) method.


findMin

public static java.lang.Object findMin(java.lang.Object[] inputlist,
                                       int n,
                                       java.util.Comparator c)
Returns the nth smallest object in the input array. This method allows comparison of Objects. The comparison logic is provided by the Comparator argument. It follows similar semantics as the findMin(int[], int) method.