gumbo.util
Class Delegatables

java.lang.Object
  |
  +--gumbo.util.Delegatables

public final class Delegatables
extends java.lang.Object

Constants and utilities related to Delegatable.

Version:
$Revision: 1.15 $
Author:
Jon Barrilleaux (jonb@jmbaai.com) of JMB and Associates Inc.

Nested Class Summary
static class Delegatables.DelegatableImm
          A serializable immutable view wrapper for a target Delegatable.
static class Delegatables.DelegatableWrapper
          A serializable wrapper for a target Delegatable.
 
Method Summary
static java.lang.Object delegator(java.lang.Object delegate)
          Safely gets the delegator of a delegate.
static java.lang.Object delegator(java.lang.Object delegate, java.lang.Class type)
          Safely gets the delegator of a delegate.
static java.lang.Object delegator(java.lang.Object delegate, java.util.Collection types)
          Safely gets the delegator of a delegate.
static java.util.Collection delegators(java.util.Collection delegates, java.util.Collection retVal)
          Gets the delegators of a collection of delegates.
static java.util.List delegators(java.util.List retVal)
          Replaces the delegates in a list with their delegators.
static java.util.Collection excludeDelegators(java.util.Collection delegates, java.util.Collection types, java.util.Collection retVal)
          Returns only those delegates whose type is NOT assignable to one of the excluded types.
static java.util.Collection includeDelegators(java.util.Collection delegates, java.util.Collection types, java.util.Collection retVal)
          Returns only those delegates whose type is assignable to one of the included types.
static java.lang.Object rootDelegator(java.lang.Object delegate)
          Gets the root delegator of a delegate in a delegation chain by recursively calling getDelegator().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

delegator

public static java.lang.Object delegator(java.lang.Object delegate)
Safely gets the delegator of a delegate.

Parameters:
delegate - A delegate. Returns null if null.
Returns:
Reference to the delegator of the delegate. May be the delegate (no delegation or delegate is not Delegatable). Null only if the delegate is null.

delegator

public static java.lang.Object delegator(java.lang.Object delegate,
                                         java.lang.Class type)
Safely gets the delegator of a delegate.

Parameters:
delegate - A delegate. Null if none.
type - The required assignable type of the delegator. Null for any.
Returns:
Reference to the delegator of the delegate. May be the delegate (no delegation or delegate is not Delegatable). Null only if the delegate is null or the delegator is the wrong type.

delegator

public static java.lang.Object delegator(java.lang.Object delegate,
                                         java.util.Collection types)
Safely gets the delegator of a delegate.

Parameters:
delegate - A delegate. Null if none.
types - Allowed assignable types of delegator. Null for any.
Returns:
Reference to the delegator of the delegate. May be the delegate (no delegation or delegate is not Delegatable). Null only if the delegate is null or the delegator is the wrong type.

delegators

public static java.util.Collection delegators(java.util.Collection delegates,
                                              java.util.Collection retVal)
Gets the delegators of a collection of delegates. The result may contain duplicates if the return collection is not a set. If a delegate is not Delegatable, the delegate is returned as the delegator.

Parameters:
delegates - Collection of delegates (Object). Never null.
retVal - Return value object. Collection of delegators (Object). Never null.
Returns:
Reference to retVal. Never null.

delegators

public static java.util.List delegators(java.util.List retVal)
Replaces the delegates in a list with their delegators. If a delegate is not Delegatable, the delegate is returned as the delegator.

Parameters:
retVal - Input and return value object. Inputs delegates (Object). Returns delegators (Object). Never null.
Returns:
Reference to delegates. Never null.

rootDelegator

public static java.lang.Object rootDelegator(java.lang.Object delegate)
Gets the root delegator of a delegate in a delegation chain by recursively calling getDelegator(). The root delegator will be the first object that does not implement Delegatable or, if it does, references itself as the delegator.

Parameters:
delegate - A delegate. Null if none.
Returns:
Reference to the root delegator of the delegate. May be the delegate (no delegation or delegate is not Delegatable). Null if the delegate is null.

includeDelegators

public static java.util.Collection includeDelegators(java.util.Collection delegates,
                                                     java.util.Collection types,
                                                     java.util.Collection retVal)
Returns only those delegates whose type is assignable to one of the included types. If a delegate is not Delegatable, the delegate is returned as the delegator. The result may contain duplicates if the return collection is not a set.

Parameters:
delegates - Collection of delegates (Object). Never null.
types - Collection of included types (Class). If null, all types are included.
retVal - Return value object. Collection of delegators (Object) assignable to a type in types. Never null.
Returns:
Reference to retVal. Never null.

excludeDelegators

public static java.util.Collection excludeDelegators(java.util.Collection delegates,
                                                     java.util.Collection types,
                                                     java.util.Collection retVal)
Returns only those delegates whose type is NOT assignable to one of the excluded types. If a delegate is not Delegatable, the delegate is returned as the delegator. The result may contain duplicates if the return collection is not a set.

Parameters:
delegates - Collection of delegates (Object). Never null.
types - Collection of excluded types (Class). If null, all types are included.
retVal - Return value object. Collection of delegators (Object) not assignable to a type in types. Never null.
Returns:
Reference to retVal. Never null.