org.kuali.rice.core.api.mo
Class ModelObjectUtils

java.lang.Object
  extended by org.kuali.rice.core.api.mo.ModelObjectUtils

public class ModelObjectUtils
extends Object

A set of simple utilities to assist with common idioms in immutable model objects and their builders.

Author:
Kuali Rice Team (rice.collab@kuali.org)

Nested Class Summary
static interface ModelObjectUtils.Transformer<A,B>
           
 
Method Summary
static
<T> List<T>
buildImmutableCopy(List<? extends ModelBuilder> builderList)
          Takes the given list of ModelBuilder objects and invokes the ModelBuilder.build() method on each of them, adding them to a new list and return an unmodifiable copy.
static
<B> Set<B>
buildImmutableCopy(Set<? extends ModelBuilder> toConvert)
           
static
<T> List<T>
createImmutableCopy(List<T> listToCopy)
          Takes the given list and returns an unmodifiable copy of that list containing the same elements as the original list.
static
<K,V> Map<K,V>
createImmutableCopy(Map<K,V> mapToCopy)
          Takes the given map and returns an unmodifiable copy of that map containing the same entries as the original map.
static
<T> Set<T>
createImmutableCopy(Set<T> setToCopy)
          Takes the given set and returns an unmodifiable copy of that set containing the same elements as the original set.
static
<A,B> List<B>
transform(Collection<? extends A> toConvert, ModelObjectUtils.Transformer<A,B> xform)
          This method is useful for converting a List<? extends BlahContract> to a List<Blah.Builder>.
static
<A,B> Set<B>
transformSet(Collection<? extends A> toConvert, ModelObjectUtils.Transformer<A,B> xform)
          This method is useful for converting a Set<? extends BlahContract> to a Set<Blah.Builder>.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

buildImmutableCopy

public static <T> List<T> buildImmutableCopy(List<? extends ModelBuilder> builderList)
Takes the given list of ModelBuilder objects and invokes the ModelBuilder.build() method on each of them, adding them to a new list and return an unmodifiable copy. If the given list is empty or null, will return an empty and unmodifiable list.

Type Parameters:
T - the type of the object that is built by the builders in the list, it is up to the caller of this method to ensure they define the proper parameterized list for the return type.
Parameters:
builderList - the list of builders to build and add to resulting list, may be empty or null
Returns:
an unmodifiable list containing objects built from the given list of model builders

buildImmutableCopy

public static <B> Set<B> buildImmutableCopy(Set<? extends ModelBuilder> toConvert)

createImmutableCopy

public static <T> List<T> createImmutableCopy(List<T> listToCopy)
Takes the given list and returns an unmodifiable copy of that list containing the same elements as the original list. This method handles a null list being passed to it by returning an unmodifiable empty list.

Type Parameters:
T - the type of the elements in the given list
Parameters:
listToCopy - the list to copy
Returns:
an unmodifiable copy containing the same elements as the given list

createImmutableCopy

public static <T> Set<T> createImmutableCopy(Set<T> setToCopy)
Takes the given set and returns an unmodifiable copy of that set containing the same elements as the original set. This method handles a null set being passed to it by returning an unmodifiable empty set.

Type Parameters:
T - the type of the elements in the given set
Parameters:
setToCopy - the set to copy
Returns:
an unmodifiable copy containing the same elements as the given set

createImmutableCopy

public static <K,V> Map<K,V> createImmutableCopy(Map<K,V> mapToCopy)
Takes the given map and returns an unmodifiable copy of that map containing the same entries as the original map. This method handles a null map being passed to it by returning an unmodifiable empty map.

Parameters:
mapToCopy - the map to copy
- V> the type of the key and value elements in the given map
Returns:
an unmodifiable copy containing the same elements as the given set

transform

public static <A,B> List<B> transform(Collection<? extends A> toConvert,
                                      ModelObjectUtils.Transformer<A,B> xform)
This method is useful for converting a List<? extends BlahContract> to a List<Blah.Builder>. You'll just need to implement Transformer to use it.

Type Parameters:
A -
B -
Parameters:
toConvert -
xform -
Returns:

transformSet

public static <A,B> Set<B> transformSet(Collection<? extends A> toConvert,
                                        ModelObjectUtils.Transformer<A,B> xform)
This method is useful for converting a Set<? extends BlahContract> to a Set<Blah.Builder>. You'll just need to implement Transformer to use it.

Type Parameters:
A -
B -
Parameters:
toConvert -
xform -
Returns:


Copyright © 2005-2012 The Kuali Foundation. All Rights Reserved.