de.caff.generics.util

## Class CopyRef<T extends Copyable<T>>

- java.lang.Object
- - de.caff.generics.util.CopyRef<T>

- All Implemented Interfaces:
    IReference<T>

      public class CopyRef<T extends Copyable<T>>
      extends java.lang.Object
      implements IReference<T>

  A reference which copies its object on construction (incoming) and when requested (outgoing). Thus immutabilitly is acquired, as there is no way to change the object kept by this reference even if it is basically mutable.

  As the object is copied once incoming and each time it is requested this reference is used most efficiently for basically mutable objects which implement an immutable interface. Copying should then return an immutable object which no longer require copying. Then no more than one copy operation has to happen when using this reference.

  Since:
    November 17, 2021
  Author:
    Rammi

- - ### Field Summary

    - ### Fields inherited from interface de.caff.generics.util.IReference

      `NULL_REF`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `CopyRef(T object, java.util.function.UnaryOperator<T> copier)` Constructor.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `T` | `get()` Get the referenced object.
    `<R extends Copyable<R>> CopyRef<R>` | `make(R object)` Create a copy reference for a copyable object.
    `<R extends Copyable<R>> IReference<R>` | `makeN(R object)` Create a reference of a copyable object which might be `null`.

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

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

    - ### Methods inherited from interface de.caff.generics.util.IReference

      `hard, isNull, nullRef, soft, weak`

- - ### Constructor Detail

    - #### CopyRef

          public CopyRef(@NotNull
                         T object,
                         @NotNull
                         java.util.function.UnaryOperator<T> copier)

      Constructor.
      Parameters:
        `object` - object which will be copied into this reference
        `copier` - copier used for copying objects here and on `get()`

  - ### Method Detail

    - #### get

          @NotNull
          public T get()

      Description copied from interface: `IReference`
      Get the referenced object. Depending on the implementation this might return `null` if the referenced object is garbage collected or this is a `null reference`.
      Specified by:
        `get` in interface `IReference<T extends Copyable<T>>`
      Returns:
        referenced object, or `null`

    - #### make

          @NotNull
          public <R extends Copyable<R>> CopyRef<R> make(@NotNull
                                                                  R object)

      Create a copy reference for a copyable object.
      Type Parameters:
        `R` - object type
      Parameters:
        `object` - copyable object
      Returns:
        copy reference

    - #### makeN

          @NotNull
          public <R extends Copyable<R>> IReference<R> makeN(@Nullable
                                                                      R object)

      Create a reference of a copyable object which might be `null`.
      Type Parameters:
        `R` - object type
      Parameters:
        `object` - copyable object
      Returns:
        copy reference or `null reference` if object is `null`