jaggregate
Class Objects

java.lang.Object
  extended by jaggregate.Objects

public class Objects
extends Object

Utility class that offers useful operations on objects in general.

Version:
$Id: Objects.java,v 1.6 2008/10/03 19:01:23 pholser Exp $
Author:
Paul Holser

Method Summary
static boolean areEqual(Object first, Object second)
          Tells whether two object references are considered equivalent.
static UnaryPredicate<Class<?>> classifies(Object instance)
          Answers a predicate which will answer true if its argument is a class in the hierarchy of the given object's class.
static UnaryPredicate<Object> equalTo(Object comparand)
          Answers a predicate which will answer true if its argument compares equivalent to the given comparand.
static String identityToString(Object target)
          Answers the string representation for the target object, as Object's implementation would compute it, disregarding overrides.
static UnaryPredicate<Object> isA(Class<?> comparand)
          Answers a predicate which will answer true if its argument is an instance of the given comparand class.
static int nullSafeHashCode(Object target)
          Answers a hash value for the given target object.
static UnaryPredicate<Object> sameAs(Object comparand)
          Answers a predicate which will answer true if its argument refers to the same object as the given comparand.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

areEqual

public static boolean areEqual(Object first,
                               Object second)
Tells whether two object references are considered equivalent. Both references can be null.

Parameters:
first - first reference
second - second reference
Returns:
result of first == null ? second == null : first.equals(second)

nullSafeHashCode

public static int nullSafeHashCode(Object target)
Answers a hash value for the given target object.

Parameters:
target - the target object
Returns:
target's hash value, or 0 if target is null

identityToString

public static String identityToString(Object target)
Answers the string representation for the target object, as Object's implementation would compute it, disregarding overrides.

Parameters:
target - the target object
Returns:
the default string representation for target

equalTo

public static UnaryPredicate<Object> equalTo(Object comparand)
Answers a predicate which will answer true if its argument compares equivalent to the given comparand.

Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand

sameAs

public static UnaryPredicate<Object> sameAs(Object comparand)
Answers a predicate which will answer true if its argument refers to the same object as the given comparand.

Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand

isA

public static UnaryPredicate<Object> isA(Class<?> comparand)
Answers a predicate which will answer true if its argument is an instance of the given comparand class.

Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand
Throws:
NullPointerException - if comparand is null

classifies

public static UnaryPredicate<Class<?>> classifies(Object instance)
Answers a predicate which will answer true if its argument is a class in the hierarchy of the given object's class.

Parameters:
instance - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with instance


© Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. Licensed under the Academic Free License version 3.0. pholser@alumni.rice.edu