Package com.complexible.common.base

# Class Copyables

java.lang.Object
com.complexible.common.base.Copyables

public final class Copyables extends Object

Utility methods for copying collections of `Copyable` objects.

Since:
  2.1
Version:
  5.0.1
Author:
  Michael Grove

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T extends Copyable<T>, C extends Collection<T>>
  C`
  `copy(C theToCopy)`
  Perform a copy of a collection.
  `static <T> com.google.common.base.Optional<T>`
  `copy(com.google.common.base.Optional<T> theObj)`
  If the `Optional` has (`isPresent a value` a `Copyable.copy()` is made of the object.
  `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 a `copy(Object)` of each element and return a new ImmutableList
  `static <K, V> com.google.common.collect.ImmutableMap<K,V>`
  `copy(com.google.common.collect.ImmutableMap<K,V> theMap)`
  Perform a copy of an `ImmutableMap`.
  `static <T> com.google.common.collect.ImmutableSet<T>`
  `copy(com.google.common.collect.ImmutableSet<T> theSet)`
  Perform a copy of an `ImmutableSet`.
  `static <T> T`
  `copy(T theObject)`
  `Copies` the 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.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### 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 a `copy(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 an `ImmutableSet`. The set is immutable, but the elements it contains may not be, so this will make a `copy(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 an `ImmutableMap`. The map is immutable, but the keys and values it contains may not be, so this will make a `copy(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 Collection<T>> C copy(C theToCopy)
    Perform a copy of a collection. Creates a new Collection of the same type as the original (via `getClass().newInstance()`) and `copies` each element from the source into the new collection.
    Parameters:
      `theToCopy` - the collection to copy
    Returns:
      the copy of the collection
    Throws:
      `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 and `copies` each 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)
    `Copies` the 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 the `Optional` has (`isPresent a value` a `Copyable.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.