Package com.complexible.common.base
Class Copyables
- java.lang.Object
-
- com.complexible.common.base.Copyables
-
public final class Copyables extends java.lang.ObjectUtility methods for copying collections of
Copyableobjects.- Since:
- 2.1
- Version:
- 5.0.1
- Author:
- Michael Grove
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends Copyable<T>,C extends java.util.Collection<T>>
Ccopy(C theToCopy)Perform a copy of a collection.static <T> com.google.common.base.Optional<T>copy(com.google.common.base.Optional<T> theObj)static <T> com.google.common.collect.ImmutableList<T>copy(com.google.common.collect.ImmutableList<T> theList)Perform a copy of an ImmutableList; while the list itself cannot change, the elements it contains *may* be mutable, so this will perform acopy(Object)of each element and return a new ImmutableListstatic <K,V>
com.google.common.collect.ImmutableMap<K,V>copy(com.google.common.collect.ImmutableMap<K,V> theMap)Perform a copy of anImmutableMap.static <T> com.google.common.collect.ImmutableSet<T>copy(com.google.common.collect.ImmutableSet<T> theSet)Perform a copy of anImmutableSet.static <T> Tcopy(T theObject)Copiesthe object if it is an instance of Copyable, otherwise returns the object unchanged.static <T extends Copyable<T>>
T[]copy(T[] theArray)Perform a copy of an array.
-
-
-
Method Detail
-
copy
public static <T> com.google.common.collect.ImmutableList<T> copy(com.google.common.collect.ImmutableList<T> theList)
Perform a copy of an ImmutableList; while the list itself cannot change, the elements it contains *may* be mutable, so this will perform acopy(Object)of each element and return a new ImmutableList- Parameters:
theList- the list to copy- Returns:
- a new list with the elements copied
-
copy
public static <T> com.google.common.collect.ImmutableSet<T> copy(com.google.common.collect.ImmutableSet<T> theSet)
Perform a copy of anImmutableSet. The set is immutable, but the elements it contains may not be, so this will make acopy(Object)of each element and add them to a new set.- Parameters:
theSet- the set to copy- Returns:
- a copy of the set and its elementse
-
copy
public static <K,V> com.google.common.collect.ImmutableMap<K,V> copy(com.google.common.collect.ImmutableMap<K,V> theMap)
Perform a copy of anImmutableMap. The map is immutable, but the keys and values it contains may not be, so this will make acopy(Object)of each key-value pair and add them to a new map.- Parameters:
theMap- the map to copy- Returns:
- a copy of the map
-
copy
public static <T extends Copyable<T>,C extends java.util.Collection<T>> C copy(C theToCopy)
Perform a copy of a collection. Creates a new Collection of the same type as the original (viagetClass().newInstance()) andcopieseach element from the source into the new collection.- Parameters:
theToCopy- the collection to copy- Returns:
- the copy of the collection
- Throws:
java.lang.IllegalArgumentException- if the new collection could not be created
-
copy
public static <T extends Copyable<T>> T[] copy(T[] theArray)
Perform a copy of an array. Creates a new array andcopieseach element from the source into the new array.- Parameters:
theArray- the array to copy- Returns:
- the copy
-
copy
public static <T> T copy(T theObject)
Copiesthe object if it is an instance of Copyable, otherwise returns the object unchanged.- Parameters:
theObject- the object to try to copy.- Returns:
- the possibly copied object
-
copy
public static <T> com.google.common.base.Optional<T> copy(com.google.common.base.Optional<T> theObj)
If theOptionalhas (isPresent a valueaCopyable.copy()is made of the object. Otherwise, with an absent value, the Optional is returned as-is- Type Parameters:
T- the object's type- Parameters:
theObj- the object to copy- Returns:
- an Optional which contains a copy of the object if a value is present on the optional.
-
-