|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectedu.rice.cs.plt.recur.RecurUtil
public final class RecurUtil
TODO: Is the extra overhead required to check for infinite loops enough to justify non-checking alternatives to safeToString, safeEquals, and safeHashCode?
| Nested Class Summary | |
|---|---|
static class |
RecurUtil.ArrayStringMode
Defines the representation to be used in array string-generating methods |
| Method Summary | ||
|---|---|---|
static boolean |
arrayEquals(Object[] a1,
Object[] a2)
Test the equality of the given arrays. |
|
static boolean |
arrayEquals(Object a1,
Object a2)
Test the equality of the given arrays. |
|
static int |
arrayHashCode(boolean[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(byte[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(char[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(double[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(float[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(int[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(long[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(Object array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(Object[] array)
Generate a hash code for the given array. |
|
static int |
arrayHashCode(short[] array)
Generate a hash code for the given array. |
|
static String |
arrayToString(boolean[] array)
Invoke arrayToString(boolean[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(boolean[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(byte[] array)
Invoke arrayToString(byte[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(byte[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(char[] array)
Invoke arrayToString(char[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(char[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(double[] array)
Invoke arrayToString(double[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(double[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(float[] array)
Invoke arrayToString(float[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(float[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(int[] array)
Invoke arrayToString(int[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(int[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(long[] array)
Invoke arrayToString(long[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(long[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(Object array)
Invoke arrayToString(Object, ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(Object[] array)
Invoke arrayToString(Object[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(Object[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(Object array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static String |
arrayToString(short[] array)
Invoke arrayToString(short[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED |
|
static String |
arrayToString(short[] array,
RecurUtil.ArrayStringMode stringMode)
Generate a string representation of the given array. |
|
static boolean |
safeEquals(Object obj1,
Object obj2)
Invokes safeEquals(Object, Object, Predicate2) using true for
infiniteEquals (note that false is not a reasonable value for
infiniteEquals, since an infinite structure must be equal to itself) |
|
static
|
safeEquals(T1 obj1,
T2 obj2,
Predicate2<? super T1,? super T2> infiniteEquals)
Evaluate obj1.equals(obj2) under the protection of an infinite-recursion check. |
|
static int |
safeHashCode(Object obj)
Invokes safeHashCode(Object, Lambda) using an arbitrary default value as the
infiniteHashCode. |
|
static int |
safeHashCode(Object obj,
int infiniteHashCode)
Invokes safeHashCode(Object, Lambda) using the given value as the
infiniteHashCode. |
|
static
|
safeHashCode(T obj,
Lambda<? super T,Integer> infiniteHashCode)
Evaluate obj.hashCode() under the protection of an infinite-recursion check. |
|
static String |
safeToString(Object obj)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... |
|
static String |
safeToString(Object obj,
int depth)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... |
|
static String |
safeToString(Object obj,
int depth,
RecurUtil.ArrayStringMode arrayMode)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... |
|
static String |
safeToString(Object obj,
RecurUtil.ArrayStringMode arrayMode)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... |
|
static String |
safeToString(Object obj,
String infiniteString)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using the given string as
the infiniteString, a default depth of 1, and
RecurUtil.ArrayStringMode.DEEP_BRACED as a default array string mode. |
|
static String |
safeToString(Object obj,
String infiniteString,
int depth)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using the given string as
the infiniteString, and RecurUtil.ArrayStringMode.DEEP_BRACED as a default array string
mode. |
|
static String |
safeToString(Object obj,
String infiniteString,
int depth,
RecurUtil.ArrayStringMode arrayMode)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using the given
string as the infiniteString. |
|
static String |
safeToString(Object obj,
String infiniteString,
RecurUtil.ArrayStringMode arrayMode)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using the given
string as the infiniteString, and a default depth of 1. |
|
static
|
safeToString(T obj,
Lambda<? super T,String> infiniteString)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) with a default
depth of 1, and using RecurUtil.ArrayStringMode.DEEP_BRACED as a default array
string mode. |
|
static
|
safeToString(T obj,
Lambda<? super T,String> infiniteString,
int depth)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using
RecurUtil.ArrayStringMode.DEEP_BRACED as a default array string mode. |
|
static
|
safeToString(T obj,
Lambda<? super T,String> infiniteString,
int depth,
RecurUtil.ArrayStringMode arrayMode)
Evaluate obj.toString() under the protection of an infinite-recursion check. |
|
static
|
safeToString(T obj,
Lambda<? super T,String> infiniteString,
RecurUtil.ArrayStringMode arrayMode)
Invokes safeToString(Object, Lambda, int, ArrayStringMode) using a default
depth of 1. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Method Detail |
|---|
public static String safeToString(Object obj)
safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... }", a default
depth of 1, and RecurUtil.ArrayStringMode.DEEP_BRACED as a default array
string mode.
public static String safeToString(Object obj,
String infiniteString)
safeToString(Object, Lambda, int, ArrayStringMode) using the given string as
the infiniteString, a default depth of 1, and
RecurUtil.ArrayStringMode.DEEP_BRACED as a default array string mode.
public static <T> String safeToString(T obj,
Lambda<? super T,String> infiniteString)
safeToString(Object, Lambda, int, ArrayStringMode) with a default
depth of 1, and using RecurUtil.ArrayStringMode.DEEP_BRACED as a default array
string mode.
public static String safeToString(Object obj,
RecurUtil.ArrayStringMode arrayMode)
safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... }", and a default
depth of 1.
public static String safeToString(Object obj,
String infiniteString,
RecurUtil.ArrayStringMode arrayMode)
safeToString(Object, Lambda, int, ArrayStringMode) using the given
string as the infiniteString, and a default depth of 1.
public static <T> String safeToString(T obj,
Lambda<? super T,String> infiniteString,
RecurUtil.ArrayStringMode arrayMode)
safeToString(Object, Lambda, int, ArrayStringMode) using a default
depth of 1.
public static String safeToString(Object obj,
int depth)
safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... }", and
RecurUtil.ArrayStringMode.DEEP_BRACED as a default array string mode.
public static String safeToString(Object obj,
String infiniteString,
int depth)
safeToString(Object, Lambda, int, ArrayStringMode) using the given string as
the infiniteString, and RecurUtil.ArrayStringMode.DEEP_BRACED as a default array string
mode.
public static <T> String safeToString(T obj,
Lambda<? super T,String> infiniteString,
int depth)
safeToString(Object, Lambda, int, ArrayStringMode) using
RecurUtil.ArrayStringMode.DEEP_BRACED as a default array string mode.
public static String safeToString(Object obj,
int depth,
RecurUtil.ArrayStringMode arrayMode)
safeToString(Object, Lambda, int, ArrayStringMode) using a default
infiniteString like "ClassName..." or "{ ... }".
public static String safeToString(Object obj,
String infiniteString,
int depth,
RecurUtil.ArrayStringMode arrayMode)
safeToString(Object, Lambda, int, ArrayStringMode) using the given
string as the infiniteString.
public static <T> String safeToString(T obj,
Lambda<? super T,String> infiniteString,
int depth,
RecurUtil.ArrayStringMode arrayMode)
Evaluate obj.toString() under the protection of an infinite-recursion check.
If a string for obj is already in the process of being computed by this method
depth times (that is, this is the depth+1st nested invocation),
infiniteString will be applied. Otherwise, the result is obj.toString().
To simplify client code, this method also handles null values (returning
"null") and arrays (calling arrayToString(Object, ArrayStringMode)).
obj - An object (may be null or an array)infiniteString - A lambda to generate a string for obj if its toString
method has already been invoked depth timesdepth - The number of times to allow a toString invocation before using
infiniteString insteadarrayMode - The RecurUtil.ArrayStringMode to use if obj is an array
objpublic static String arrayToString(Object array)
arrayToString(Object, ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(Object array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list of each of the elements (calling
safeToString(Object, ArrayStringMode) where applicable, using the mode
produced by RecurUtil.ArrayStringMode.nestedMode()).
IllegalArgumentException - If array is not an arraypublic static String arrayToString(Object[] array)
arrayToString(Object[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(Object[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise call safeToString(Object, ArrayStringMode)
on each of the elements, using the mode produced by RecurUtil.ArrayStringMode.nestedMode().
If stringMode is RecurUtil.ArrayStringMode.SHALLOW_BRACKETED, the result will match
that of Arrays.toString(Object[]); if stringMode is
RecurUtil.ArrayStringMode.DEEP_BRACKETED, the result will match that of
Arrays.deepToString(java.lang.Object[]).
public static String arrayToString(boolean[] array)
arrayToString(boolean[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(boolean[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static String arrayToString(char[] array)
arrayToString(char[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(char[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static String arrayToString(byte[] array)
arrayToString(byte[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(byte[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static String arrayToString(short[] array)
arrayToString(short[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(short[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static String arrayToString(int[] array)
arrayToString(int[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(int[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static String arrayToString(long[] array)
arrayToString(long[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(long[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static String arrayToString(float[] array)
arrayToString(float[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(float[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static String arrayToString(double[] array)
arrayToString(double[], ArrayStringMode) with a default string mode
RecurUtil.ArrayStringMode.DEEP_BRACED
public static String arrayToString(double[] array,
RecurUtil.ArrayStringMode stringMode)
stringMode is
RecurUtil.ArrayStringMode.CLASS_NAME or RecurUtil.ArrayStringMode.TYPE_AND_SIZE, generate
a simple name, as specified; otherwise, generate a list containing each element.
public static boolean safeEquals(Object obj1,
Object obj2)
safeEquals(Object, Object, Predicate2) using true for
infiniteEquals (note that false is not a reasonable value for
infiniteEquals, since an infinite structure must be equal to itself)
public static <T1,T2> boolean safeEquals(T1 obj1,
T2 obj2,
Predicate2<? super T1,? super T2> infiniteEquals)
Evaluate obj1.equals(obj2) under the protection of an infinite-recursion check.
If the equality of obj1 and obj2 is already in the process of being computed
by this method, infiniteEquals will be applied. Otherwise, the result is
obj1.equals(obj2).
To simplify client code, this method also handles null values (equal iff both
values are null) and arrays (calling arrayEquals(Object, Object).
obj1 - An object (may be null or an array)obj2 - An object (may be null or an array)infiniteEquals - A predicate to determine equality of obj1.equals(obj2) has
already been invoked
true iff the two objects are equal
public static boolean arrayEquals(Object a1,
Object a2)
safeEquals(Object, Object). Unlike
Arrays.deepEquals(java.lang.Object[], java.lang.Object[]), this method is able to handle an array nested within
itself.
IllegalArgumentException - If array1 or array2 is not an array
public static boolean arrayEquals(Object[] a1,
Object[] a2)
safeEquals(Object, Object). Note that arrays of different runtime types
may still be equal if their elements are equal. Unlike Arrays.deepEquals(java.lang.Object[], java.lang.Object[]), this
method is able to handle an array nested within itself.
public static int safeHashCode(Object obj)
safeHashCode(Object, Lambda) using an arbitrary default value as the
infiniteHashCode.
public static int safeHashCode(Object obj,
int infiniteHashCode)
safeHashCode(Object, Lambda) using the given value as the
infiniteHashCode.
public static <T> int safeHashCode(T obj,
Lambda<? super T,Integer> infiniteHashCode)
Evaluate obj.hashCode() under the protection of an infinite-recursion check.
If the hash code for obj is already in the process of being computed by this method,
infiniteHashCode will be applied. Otherwise, the result is obj.hashCode().
To simplify client code, this method also handles null values (returning 0)
and arrays (calling arrayHashCode(Object)).
obj - An object (may be null or an array)infiniteHashCode - A lambda to generate a hash code for obj if its
hashCode method has already been invoked
objpublic static int arrayHashCode(Object array)
List.hashCode(), recurring on any nested objects (including arrays)
using safeHashCode(Object). Unlike Arrays.deepHashCode(java.lang.Object[]),
this method is able to handle an array nested within itself.
IllegalArgumentException - If array is not an arraypublic static int arrayHashCode(Object[] array)
List.hashCode(), recurring on each element using safeHashCode(Object).
Unlike Arrays.deepHashCode(java.lang.Object[]), this method is able to handle an array nested
within itself.
public static int arrayHashCode(boolean[] array)
List.hashCode(), invoking the Boolean#hashCode method on
each element. (Note that Arrays.hashCode(boolean[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
public static int arrayHashCode(char[] array)
List.hashCode(), invoking the Character#hashCode method on
each element. (Note that Arrays.hashCode(char[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
public static int arrayHashCode(byte[] array)
List.hashCode(), invoking the Byte#hashCode method on
each element. (Note that Arrays.hashCode(byte[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
public static int arrayHashCode(short[] array)
List.hashCode(), invoking the Short#hashCode method on
each element. (Note that Arrays.hashCode(short[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
public static int arrayHashCode(int[] array)
List.hashCode(), invoking the Integer#hashCode method on
each element. (Note that Arrays.hashCode(int[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
public static int arrayHashCode(long[] array)
List.hashCode(), invoking the Long#hashCode method on
each element. (Note that Arrays.hashCode(long[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
public static int arrayHashCode(float[] array)
List.hashCode(), invoking the Float#hashCode method on
each element. (Note that Arrays.hashCode(float[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
public static int arrayHashCode(double[] array)
List.hashCode(), invoking the Double#hashCode method on
each element. (Note that Arrays.hashCode(double[]) implements the
same method; this is defined here for compatibility with earlier APIs.)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||