Top Description Inners Fields Constructors Methods
org.glassfish.pfl.test

public final Class ObjectUtility

extends Object
Class Inheritance
Imports
java.lang.reflect.Array, .Field, .Method, .Modifier, java.math.BigDecimal, .BigInteger, java.security.AccessController, .CodeSource, .Permission, .PermissionCollection, .Principal, .PrivilegedAction, .ProtectionDomain, java.util.ArrayList, .Arrays, .Collection, .Enumeration, .HashSet, .IdentityHashMap, .Iterator, .List, .ListIterator, .Map, .Map.Entry, .Properties, .Set, org.glassfish.pfl.basic.reflection.FieldValueHelper

General object related utilities. This class must not depend on generated log wrappers.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static interface
private static class

Field Summary

Modifier and TypeField and Description
private ObjectUtility.ClassMap
private ObjectUtility.ObjectPrinter
private static ObjectUtility
private int
private int
private boolean
private ObjectUtility.ObjectPrinter
private ObjectUtility.ObjectPrinter
private static ObjectUtility
private boolean

Constructor Summary

AccessConstructor and Description
private
ObjectUtility(boolean useToString, boolean isIndenting, int initialLevel, int increment)

Method Summary

Modifier and TypeMethod and Description
private static void
a()

private static void
b()

private static void
c()

private void
public static String
public static Object
concatenateArrays(Object arr1, Object arr2)

If arr1 and arr2 are both arrays of the same component type, return an array of that component type that consists of the elements of arr1 followed by the elements of arr2.

private static void
d()

public static String
defaultObjectToString(Object object)

A convenience method that gives the default behavior: use indenting to display the object's structure and do not use built-in toString methods.

public static void
private static void
e()

private static boolean
equalArrays(Map<K, V> counterpart, Set<E> considered, Object[] arr1, Object[] arr2)

private static boolean
equalLists(Map<K, V> counterpart, Set<E> considered, List<E> list1, List<E> list2)

private static boolean
equalMaps(Map<K, V> counterpart, Set<E> considered, Map<K, V> map1, Map<K, V> map2)

public static boolean
equals(Object obj1, Object obj2)

private static boolean
equalSets(Map<K, V> counterpart, Set<E> considered, Set<E> set1, Set<E> set2)

private static boolean
equalsHelper(Map<K, V> counterpart, Set<E> considered, Object obj1, Object obj2)

private static boolean
equalsObject(Map<K, V> counterpart, Set<E> considered, Class<T> cls, Object obj1, Object obj2)

private static boolean
equalsObjectFields(Map<K, V> counterpart, Set<E> considered, Class<T> cls, Object obj1, Object obj2)

private Field[]
private void
handleArray(IdentityHashMap<K, V> printed, ObjectWriter result, Object obj)

private void
handleObject(IdentityHashMap<K, V> printed, ObjectWriter result, Object obj)

public static void
main(String[] args)

public static ObjectUtility
make(boolean useToString, boolean isIndenting, int initialLevel, int increment)

Construct an Utility instance with the desired objectToString behavior.

public static ObjectUtility
make(boolean useToString, boolean isIndenting)

Construct an Utility instance with the desired objectToString behavior.

public static ObjectUtility
make()

Get the standard Utility object that supports objectToString with indented display and no use of toString() methods.

private boolean
public String
objectToString(Object obj)

objectToString handles display of arbitrary objects.

private void
private static void
sop(String msg)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

classToPrinterback to summary
private ObjectUtility.ClassMap classToPrinter
collectionPrinterback to summary
private ObjectUtility.ObjectPrinter collectionPrinter
compactback to summary
private static ObjectUtility compact
incrementback to summary
private int increment
initialLevelback to summary
private int initialLevel
isIndentingback to summary
private boolean isIndenting
mapPrinterback to summary
private ObjectUtility.ObjectPrinter mapPrinter
propertiesPrinterback to summary
private ObjectUtility.ObjectPrinter propertiesPrinter
standardback to summary
private static ObjectUtility standard
useToStringback to summary
private boolean useToString

Constructor Detail

ObjectUtilityback to summary
private ObjectUtility(boolean useToString, boolean isIndenting, int initialLevel, int increment)

Method Detail

aback to summary
private static void a()
bback to summary
private static void b()
cback to summary
private static void c()
checkPackageAccessback to summary
private void checkPackageAccess(Class<T> cls)
compactObjectToStringback to summary
public static String compactObjectToString(Object object)
concatenateArraysback to summary
public static Object concatenateArrays(Object arr1, Object arr2)

If arr1 and arr2 are both arrays of the same component type, return an array of that component type that consists of the elements of arr1 followed by the elements of arr2. Throws IllegalArgumentException otherwise.

dback to summary
private static void d()
defaultObjectToStringback to summary
public static String defaultObjectToString(Object object)

A convenience method that gives the default behavior: use indenting to display the object's structure and do not use built-in toString methods.

displayExceptionback to summary
public static void displayException(Throwable thr)
eback to summary
private static void e()
equalArraysback to summary
private static boolean equalArrays(Map<K, V> counterpart, Set<E> considered, Object[] arr1, Object[] arr2)
equalListsback to summary
private static boolean equalLists(Map<K, V> counterpart, Set<E> considered, List<E> list1, List<E> list2)
equalMapsback to summary
private static boolean equalMaps(Map<K, V> counterpart, Set<E> considered, Map<K, V> map1, Map<K, V> map2)
equalsback to summary
public static boolean equals(Object obj1, Object obj2)
equalSetsback to summary
private static boolean equalSets(Map<K, V> counterpart, Set<E> considered, Set<E> set1, Set<E> set2)
equalsHelperback to summary
private static boolean equalsHelper(Map<K, V> counterpart, Set<E> considered, Object obj1, Object obj2)
equalsObjectback to summary
private static boolean equalsObject(Map<K, V> counterpart, Set<E> considered, Class<T> cls, Object obj1, Object obj2)
equalsObjectFieldsback to summary
private static boolean equalsObjectFields(Map<K, V> counterpart, Set<E> considered, Class<T> cls, Object obj1, Object obj2)
getDeclaredFieldsback to summary
private Field[] getDeclaredFields(Class<T> cls)
handleArrayback to summary
private void handleArray(IdentityHashMap<K, V> printed, ObjectWriter result, Object obj)
handleObjectback to summary
private void handleObject(IdentityHashMap<K, V> printed, ObjectWriter result, Object obj)
mainback to summary
public static void main(String[] args)
makeback to summary
public static ObjectUtility make(boolean useToString, boolean isIndenting, int initialLevel, int increment)

Construct an Utility instance with the desired objectToString behavior.

makeback to summary
public static ObjectUtility make(boolean useToString, boolean isIndenting)

Construct an Utility instance with the desired objectToString behavior.

makeback to summary
public static ObjectUtility make()

Get the standard Utility object that supports objectToString with indented display and no use of toString() methods.

mustUseToStringback to summary
private boolean mustUseToString(Class<T> cls)
objectToStringback to summary
public String objectToString(Object obj)

objectToString handles display of arbitrary objects. It correctly handles objects whose elements form an arbitrary graph. It uses reflection to display the contents of any kind of object. An object's toString() method may optionally be used, but the default is to ignore all toString() methods except for those defined for primitive types, primitive type wrappers, and strings.

objectToStringHelperback to summary
private void objectToStringHelper(IdentityHashMap<K, V> printed, ObjectWriter result, Object obj)
sopback to summary
private static void sop(String msg)
org.glassfish.pfl.test back to summary

private Class ObjectUtility.ClassMap

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv ArrayList<E>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Object
get(Class<T> cls)

Return the first element of the ClassMap that is assignable to cls.

public void
put(Class<T> cls, Object obj)

Add obj to the map with key cls.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

databack to summary
pack-priv ArrayList<E> data

Constructor Detail

ClassMapback to summary
public ClassMap()

Method Detail

getback to summary
public Object get(Class<T> cls)

Return the first element of the ClassMap that is assignable to cls. The order is determined by the order in which the put method was called. Returns null if there is no match.

putback to summary
public void put(Class<T> cls, Object obj)

Add obj to the map with key cls. Note that order matters, as the first match is returned.

org.glassfish.pfl.test back to summary

private Interface ObjectUtility.ObjectPrinter


Method Summary

Modifier and TypeMethod and Description
public void
print(IdentityHashMap<K, V> printed, ObjectWriter buff, Object obj)

Method Detail

printback to summary
public void print(IdentityHashMap<K, V> printed, ObjectWriter buff, Object obj)
org.glassfish.pfl.test back to summary

private Class ObjectUtility.Pair

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private Object
private Object

Constructor Summary

AccessConstructor and Description
pack-priv
Pair(Object obj1, Object obj2)

Method Summary

Modifier and TypeMethod and Description
public boolean
equals(Object obj)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

obj1back to summary
private Object obj1
obj2back to summary
private Object obj2

Constructor Detail

Pairback to summary
pack-priv Pair(Object obj1, Object obj2)

Method Detail

equalsback to summary
public boolean equals(Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.