com.faunos.util
Class Measure

java.lang.Object
  extended by com.faunos.util.Measure

public class Measure
extends Object

Utilty for comparing and measuring various common object types and primitives (such as char). Most of the methods in this class have well-defined behavior when invoked with one or more null parameters.


Method Summary
static boolean equal(Object a, Object b)
          Compares the two given objects for equality.
static int getCommonPrefixLength(CharSequence a, CharSequence b)
          Returns the length of the prefix shared by the two given strings (never negative).
static int getLength(CharSequence string)
          Returns the length of the given string.
static int getLength(Object[] array)
          Returns the length of the given array if not null; -1, otherwise.
static int getSize(Collection<?> collection)
          Returns the size of the given collection if not null; -1, otherwise.
static int indexOf(CharSequence string, char c)
          Returns the index of the first occurrence of c in string, if found; returns -1, otherwise.
static int indexOf(CharSequence string, char c, int fromIndex)
          Returns the index of the first occurrence of c in string that is ≥ fromIndex, if found; returns -1, otherwise.
static int indexOf(CharSequence string, CharSequence pattern)
          Returns the index of the first occurrence of the specified pattern in the given string, if found; returns -1, otherwise.
static int indexOf(CharSequence string, CharSequence pattern, int fromIndex)
          Returns the index of the first occurrence of the specified pattern in the given string that is ≥ to fromIndex, if found; returns -1, otherwise.
static int indexOfNonspace(CharSequence string, int fromIndex)
          Returns the index of the first non-space character in the given string, starting from fromIndex, if found; returns -1, otherwise.
static int indexOfSpace(CharSequence string, int fromIndex)
          Returns the index of the first space character in the given string, starting from fromIndex, if found; returns -1, otherwise.
static boolean isDigit(char ch)
           
static boolean isEmpty(CharSequence string)
          Determines whether the given string is empty.
static boolean isEmpty(Collection<?> collection)
          Determines whether the given collection is empty.
static boolean isEmpty(Object[] array)
          Determines whether the given array is empty.
static boolean isFilepath(CharSequence path)
           
static boolean isFilepath(CharSequence path, char seperator)
           
static boolean isLowerCaseAscii(char ch)
           
static boolean isSubpathChar(char ch)
           
static boolean isSubpathOf(CharSequence subpath, CharSequence parent)
          Determines whether the given subpath is in fact a subpath of the specified parent path.
static boolean isSubpathOf(CharSequence subpath, CharSequence parent, char sep)
          Determines whether the given subpath is in fact a subpath of the specified parent path.
static boolean isUpperCaseAscii(char ch)
           
static int lastIndexOf(CharSequence string, char c)
          Returns the last index of the character c in the given string, if found; returns -1, otherwise.
static int lastIndexOf(CharSequence string, char c, int fromIndex)
          Returns the last index of the character c in the given string that is ≤ fromIndex, if found; returns -1, otherwise.
static int lastIndexOf(CharSequence string, CharSequence pattern)
          Returns the last index of the specified pattern in the given string, if found; returns -1, otherwise.
static int lastIndexOf(CharSequence string, CharSequence pattern, int fromIndex)
          Returns the last index of the specified pattern in the given string that is ≤ fromIndex, if found; returns -1, otherwise.
static
<T extends Comparable<T>>
Comparator<T>
naturalComparator()
           
static boolean startsWith(CharSequence string, CharSequence start)
          Determines whether the given string starts with the given start sequence.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

equal

public static boolean equal(Object a,
                            Object b)
Compares the two given objects for equality. A null reference is considered equal only to itself.


isEmpty

public static boolean isEmpty(Object[] array)
Determines whether the given array is empty. A null reference is considered empty.


isEmpty

public static boolean isEmpty(CharSequence string)
Determines whether the given string is empty. A null reference is considered empty.


isEmpty

public static boolean isEmpty(Collection<?> collection)
Determines whether the given collection is empty. A null reference is considered empty.


getLength

public static int getLength(CharSequence string)
Returns the length of the given string. If a null reference, then -1 is returned.


startsWith

public static boolean startsWith(CharSequence string,
                                 CharSequence start)
Determines whether the given string starts with the given start sequence. If either of the input parameters is null, then false is returned.


indexOf

public static int indexOf(CharSequence string,
                          char c)
Returns the index of the first occurrence of c in string, if found; returns -1, otherwise.

Parameters:
string - the char sequence to be searched. Must not be null.

indexOf

public static int indexOf(CharSequence string,
                          char c,
                          int fromIndex)
Returns the index of the first occurrence of c in string that is ≥ fromIndex, if found; returns -1, otherwise.

Parameters:
string - the char sequence to be searched. Must not be null.

indexOfSpace

public static int indexOfSpace(CharSequence string,
                               int fromIndex)
Returns the index of the first space character in the given string, starting from fromIndex, if found; returns -1, otherwise. The space characters are recognized by this method are ' ', '\n', '\r', '\t', and '\f'.

Parameters:
string - the char sequence to be searched. Must not be null.

indexOfNonspace

public static int indexOfNonspace(CharSequence string,
                                  int fromIndex)
Returns the index of the first non-space character in the given string, starting from fromIndex, if found; returns -1, otherwise. The space characters are recognized by this method are ' ', '\n', '\r', '\t', and '\f'.

Parameters:
string - the char sequence to be searched. Must not be null.

indexOf

public static int indexOf(CharSequence string,
                          CharSequence pattern)
Returns the index of the first occurrence of the specified pattern in the given string, if found; returns -1, otherwise.

Neither of the arguments may be null.


indexOf

public static int indexOf(CharSequence string,
                          CharSequence pattern,
                          int fromIndex)
Returns the index of the first occurrence of the specified pattern in the given string that is ≥ to fromIndex, if found; returns -1, otherwise.

Neither of the arguments may be null.


lastIndexOf

public static int lastIndexOf(CharSequence string,
                              char c)
Returns the last index of the character c in the given string, if found; returns -1, otherwise.

Parameters:
string - the char sequence to be searched. Must not be null.

lastIndexOf

public static int lastIndexOf(CharSequence string,
                              char c,
                              int fromIndex)
Returns the last index of the character c in the given string that is ≤ fromIndex, if found; returns -1, otherwise.

Parameters:
string - the char sequence to be searched. Must not be null.

lastIndexOf

public static int lastIndexOf(CharSequence string,
                              CharSequence pattern)
Returns the last index of the specified pattern in the given string, if found; returns -1, otherwise.

Neither of the arguments may be null.


lastIndexOf

public static int lastIndexOf(CharSequence string,
                              CharSequence pattern,
                              int fromIndex)
Returns the last index of the specified pattern in the given string that is ≤ fromIndex, if found; returns -1, otherwise.

Neither of the arguments may be null.


getLength

public static int getLength(Object[] array)
Returns the length of the given array if not null; -1, otherwise.


getSize

public static int getSize(Collection<?> collection)
Returns the size of the given collection if not null; -1, otherwise.


getCommonPrefixLength

public static int getCommonPrefixLength(CharSequence a,
                                        CharSequence b)
Returns the length of the prefix shared by the two given strings (never negative).


isSubpathOf

public static boolean isSubpathOf(CharSequence subpath,
                                  CharSequence parent)
Determines whether the given subpath is in fact a subpath of the specified parent path. Slash ('/') is used as the default separator character.


isSubpathOf

public static boolean isSubpathOf(CharSequence subpath,
                                  CharSequence parent,
                                  char sep)
Determines whether the given subpath is in fact a subpath of the specified parent path.

Parameters:
sep - the separator character (usually '/')

isSubpathChar

public static boolean isSubpathChar(char ch)

isDigit

public static boolean isDigit(char ch)

isLowerCaseAscii

public static boolean isLowerCaseAscii(char ch)

isUpperCaseAscii

public static boolean isUpperCaseAscii(char ch)

isFilepath

public static boolean isFilepath(CharSequence path)

isFilepath

public static boolean isFilepath(CharSequence path,
                                 char seperator)

naturalComparator

public static <T extends Comparable<T>> Comparator<T> naturalComparator()


SourceForge.net Logo