public final class ObjectUtils extends Object
Constructor and Description |
---|
ObjectUtils() |
Modifier and Type | Method and Description |
---|---|
static int |
binarySearch(double[] array,
double key,
int startIndex,
int endIndex,
int missingOffset)
Fastest possible binary search.
|
static int |
binarySearch(float[] array,
float key,
int startIndex,
int endIndex,
int missingOffset)
Fastest possible binary search.
|
static int |
binarySearch(int[] array,
int key,
int startIndex,
int endIndex,
int missingOffset)
Fastest possible binary search.
|
static int |
binarySearch(long[] array,
long key,
int startIndex,
int endIndex,
int missingOffset)
Fastest possible binary search.
|
static <T extends Comparable<T>> |
binarySearch(T[] array,
T key,
int startIndex,
int endIndex,
int missingOffset)
Fastest possible binary search.
|
static Date |
clone(Date value)
Null safe clone of a date.
|
static int |
compareTo(Comparable a,
Comparable b)
Return the output of a.compareTo(b)
Safe if a or b is null
|
static <T> List<T> |
copyOf(List<T> value)
Null safe copy of a list.
|
static boolean |
equals(double a,
double b)
Returns true if a is equivalent to b.
|
static boolean |
equals(float a,
float b)
Returns true if a is equivalent to b.
|
static boolean |
equals(List<? extends Throwable> a,
List<? extends Throwable> b)
Compares if 2 lists of
Throwable s are equivalent. |
static boolean |
equals(Object a,
Object b)
Returns true if a is equivalent to b.
|
static boolean |
equals(Throwable a,
Throwable b)
Compares equality of 2
Throwable s. |
static <T extends Throwable> |
getCause(Throwable ex,
Class<T> type)
Returns the exception of 'type' if anywhere in the exception's cause tree a class of 'type' is found, null otherwise
|
static boolean |
getDefault(Boolean value,
boolean defaultValue)
Returns
defaultValue if value is null, value otherwise. |
static double |
getDefault(Double value,
double defaultValue)
Returns
defaultValue if value is null, value otherwise. |
static float |
getDefault(Float value,
float defaultValue)
Returns
defaultValue if value is null, value otherwise. |
static int |
getDefault(Integer value,
int defaultValue)
Returns
defaultValue if value is null, value otherwise. |
static long |
getDefault(Long value,
long defaultValue)
Returns
defaultValue if value is null, value otherwise. |
static <T> T |
getDefault(T value,
T defaultValue)
Returns
defaultValue if value is null, value otherwise. |
static int |
hashCode(boolean value)
Compute the hash code of a primitive
boolean . |
static int |
hashCode(Class<?> clazz)
Compute the hash code of a Class by using the hashcode of
Class.getName() . |
static int |
hashCode(double value)
Compute the hash code of a primitive
double . |
static int |
hashCode(double[] data,
int start,
int count)
Compute the hash code of a segment of an int[].
|
static int |
hashCode(float value)
Compute the hash code of a primitive
float . |
static int |
hashCode(int[] data,
int start,
int count)
Compute the hash code of a segment of an int[].
|
static int |
hashCode(int hash,
boolean value)
Add the hashCode for
value to hash . |
static int |
hashCode(int hash,
double value)
Add the hashCode for
value to hash . |
static int |
hashCode(int hash,
float value)
Add the hashCode for
value to hash . |
static int |
hashCode(int hash,
int value)
Add the hashCode for
value to hash . |
static int |
hashCode(int hash,
long value)
Add the hashCode for
value to hash . |
static int |
hashCode(int hash,
Object value)
Add the hashCode for
value to hash . |
static int |
hashCode(List<?> list)
Compute the hash code of a list of objects, using our internal routines when possible.
|
static int |
hashCode(long value)
Compute the hash code of a primitive
long . |
static int |
hashCode(Object value)
Returns the value's hash code or 0 if null.
|
static String |
intern(String value)
Intern and return
value (handles nulls). |
static boolean |
isFalse(String value)
Returns true if the string
value is a boolean value indicating false . |
static boolean |
isTrue(String value)
Returns true if the string
value is a boolean value indicating true . |
static <T> List<T> |
newList(T... vals)
Creates a new
List implementation based on ordered input values. |
static <K,V> Map<K,V> |
newMap(K key,
V val,
Object... args)
Creates a new
LinkedHashMap implementation based on key value pairs specified as paired arguments. |
static Boolean |
parseBoolean(Object value)
Convert
value to a Boolean (or null if not parseable). |
static Boolean |
parseBoolean(String value)
Parse a boolean value (more lenient than Boolean.valueOf()).
|
static BigDecimal |
parseDecimal(Object value)
Parse an arbitrary object as a
BigDecimal . |
static double |
parseDouble(Object value)
Parse an arbitrary object as a double.
|
static float |
parseFloat(Object value)
Parse an arbitrary object as a float.
|
static int |
parseInt(Object value)
Parse an arbitrary object as an integer.
|
static long |
parseLong(Object value)
Parse an arbitrary object as a long.
|
static int |
parseUnsigned(Object value)
Parses an arbitrary object into an unsigned integer.
|
static void |
prettyPrint(int[][] matrix)
Pretty prints a 2-D int array
|
static <T> void |
prettyPrint(T[][] matrix)
Pretty prints a 2-D object array
|
static <T> int |
size(List<List<T>> matrix)
Returns the total number of cells in a matrix
|
static <T> int |
size(T[][] matrix)
Returns the total number of cells in a matrix
|
static <T> T[] |
toArray(T... args)
Autobox-like creating of array.
|
static boolean |
toBooleanValue(Object value,
boolean defaultValue)
Converts an arbitrary object to a primitive boolean.
|
static double |
toDoubleValue(Object value,
double defaultValue)
Converts an arbitrary object to a primitive double.
|
static float |
toFloatValue(Object value,
float defaultValue)
Converts an arbitrary object to a primitive float.
|
static int |
toIntValue(Object value,
int defaultValue)
Converts an arbitrary object to a primitive integer.
|
static long |
toLongValue(Object value,
long defaultValue)
Converts an arbitrary object to a primitive long.
|
static <T extends Comparable<? super T>> |
toSortedList(Collection<T> collec)
Converts an arbitrary collection into a sorted list.
|
static String |
toStringValue(Object value,
String defaultValue)
Converts an arbitrary object to a String.
|
static int |
toUnsignedValue(Object value,
int defaultValue)
Converts an arbitrary object to a primitive unsigned integer.
|
public static <T> T getDefault(T value, T defaultValue)
defaultValue
if value
is null, value
otherwise.public static boolean getDefault(Boolean value, boolean defaultValue)
defaultValue
if value
is null, value
otherwise.public static int getDefault(Integer value, int defaultValue)
defaultValue
if value
is null, value
otherwise.public static long getDefault(Long value, long defaultValue)
defaultValue
if value
is null, value
otherwise.public static float getDefault(Float value, float defaultValue)
defaultValue
if value
is null, value
otherwise.public static double getDefault(Double value, double defaultValue)
defaultValue
if value
is null, value
otherwise.public static <T> T[] toArray(T... args)
public static int binarySearch(int[] array, int key, int startIndex, int endIndex, int missingOffset)
WARNING: no bounds checking is performed.
array
- the array to search.key
- the key to search for.startIndex
- the start index to start looking at (inclusive).endIndex
- the end index to stop looking at (inclusive).public static int binarySearch(long[] array, long key, int startIndex, int endIndex, int missingOffset)
WARNING: no bounds checking is performed.
array
- the array to search.key
- the key to search for.startIndex
- the start index to start looking at (inclusive).endIndex
- the end index to stop looking at (inclusive).public static int binarySearch(float[] array, float key, int startIndex, int endIndex, int missingOffset)
WARNING: no bounds checking is performed.
array
- the array to search.key
- the key to search for.startIndex
- the start index to start looking at (inclusive).endIndex
- the end index to stop looking at (inclusive).public static int binarySearch(double[] array, double key, int startIndex, int endIndex, int missingOffset)
WARNING: no bounds checking is performed.
array
- the array to search.key
- the key to search for.startIndex
- the start index to start looking at (inclusive).endIndex
- the end index to stop looking at (inclusive).public static <T> List<T> copyOf(List<T> value)
NOTE: this is a shallow clone.
public static <T extends Comparable<T>> int binarySearch(T[] array, T key, int startIndex, int endIndex, int missingOffset)
WARNING: no bounds checking is performed.
array
- the array to search.key
- the key to search for.startIndex
- the start index to start looking at (inclusive).endIndex
- the end index to stop looking at (inclusive).public static <T> int size(T[][] matrix)
matrix
- the matrixpublic static <T> int size(List<List<T>> matrix)
matrix
- the matrixpublic static boolean equals(Object a, Object b)
a
- left hand sideb
- right hand sidepublic static boolean equals(float a, float b)
a
- left hand sideb
- right hand sidepublic static boolean equals(double a, double b)
a
- left hand sideb
- right hand sidepublic static boolean equals(List<? extends Throwable> a, List<? extends Throwable> b)
Throwable
s are equivalent.
Uses equals(Throwable, Throwable)
for comparing elements.
public static boolean equals(Throwable a, Throwable b)
Throwable
s.
Equality check will validate a and b are of the same type and have same message.
public static int compareTo(Comparable a, Comparable b)
a
- left hand sideb
- right hand sidepublic static <T extends Comparable<? super T>> List<T> toSortedList(Collection<T> collec)
collec
- the collection to convertpublic static String toStringValue(Object value, String defaultValue)
value
- the value to convertdefaultValue
- if value is nullpublic static int parseInt(Object value)
public static long parseLong(Object value)
public static float parseFloat(Object value)
public static double parseDouble(Object value)
public static BigDecimal parseDecimal(Object value)
BigDecimal
.public static int toIntValue(Object value, int defaultValue)
value
- the value to convertdefaultValue
- if value cannot be converted, this will be returnedpublic static int toUnsignedValue(Object value, int defaultValue)
value
- the value to convertdefaultValue
- if value cannot be parsed, this will be returnedpublic static int parseUnsigned(Object value) throws NumberFormatException, IllegalArgumentException
value
- the value to convertNumberFormatException
- if object cannot be converted to intIllegalArgumentException
- if integer value is negativepublic static long toLongValue(Object value, long defaultValue)
value
- the value to convertdefaultValue
- if value cannot be converted, this will be returnedpublic static float toFloatValue(Object value, float defaultValue)
value
- the value to convertdefaultValue
- if value cannot be converted, this will be returnedpublic static double toDoubleValue(Object value, double defaultValue)
value
- the value to convertdefaultValue
- if value cannot be converted, this will be returnedpublic static boolean toBooleanValue(Object value, boolean defaultValue)
value
- the value to convertdefaultValue
- if value cannot be converted, this will be returnedpublic static boolean isTrue(String value)
value
is a boolean value indicating true
.public static boolean isFalse(String value)
value
is a boolean value indicating false
.public static Boolean parseBoolean(String value)
true will be returned if the value's lower cased string representation is true, yes, or on. false will be returned if values' lower cased string representation is false, no, or off. non-zero numbers will be return true, 0 returns false.
value
- public static Boolean parseBoolean(Object value)
value
to a Boolean (or null if not parseable).public static void prettyPrint(int[][] matrix)
public static <T> void prettyPrint(T[][] matrix)
public static <T extends Throwable> T getCause(Throwable ex, Class<T> type)
public static <K,V> Map<K,V> newMap(K key, V val, Object... args) throws IllegalArgumentException
LinkedHashMap
implementation based on key value pairs specified as paired arguments.
The first key/value are used for compiler time type safety and are put into the map. All of the other arguments
are NOT validated for type safety.IllegalArgumentException
- if an odd number of arguments are specified@SafeVarargs public static <T> List<T> newList(T... vals)
List
implementation based on ordered input values. Same as Arrays.asList() but provides type safetyT
- the type of generic list to createvals
- the values to add to the listpublic static int hashCode(boolean value)
boolean
.public static int hashCode(float value)
float
.public static int hashCode(double value)
double
.public static int hashCode(long value)
long
.public static int hashCode(Class<?> clazz)
Class.getName()
. Null safe.public static int hashCode(List<?> list)
public static int hashCode(int[] data, int start, int count)
public static int hashCode(double[] data, int start, int count)
public static int hashCode(int hash, boolean value)
value
to hash
.public static int hashCode(int hash, float value)
value
to hash
.public static int hashCode(int hash, double value)
value
to hash
.public static int hashCode(int hash, long value)
value
to hash
.public static int hashCode(int hash, Object value)
value
to hash
.public static int hashCode(Object value)
public static int hashCode(int hash, int value)
value
to hash
.Copyright © 2018 Attivio, Inc. All Rights Reserved.
PATENT NOTICE: Attivio, Inc. Software Related Patents. With respect to the Attivio software product(s) being used, the following patents apply: Querying Joined Data Within A Search Engine Index: United States Patent No.(s): 8,073,840. Ordered Processing of Groups of Messages: U.S. Patent No.(s) 8,495,656. Signal processing approach to sentiment analysis for entities in documents: U.S. Patent No.(s) 8,725,494. Other U.S. and International Patents Pending.