Class Metadata<T>

java.lang.Object
org.storynode.pigeon.wrap.Metadata<T>
Type Parameters:
T - The type of the inner value
All Implemented Interfaces:
SafelyWrapped<T>, Wrapped<T>

public class Metadata<T> extends Object implements SafelyWrapped<T>
Wraps a value associating it with arbitrary metadata
Since:
1.0.0
Author:
Andrea Coronese
  • Constructor Details

    • Metadata

      public Metadata(@NotNull T value)
      Creates a Metadata with a value and no metadata associated
      Parameters:
      value - The wrapped value
    • Metadata

      public Metadata(@NotNull T value, Map<Object,Object> metadata)
      Creates a Metadata with a value and associated metadata
      Parameters:
      value - the wrapped value
      metadata - a Map object describing the initial metadata entries
  • Method Details

    • from

      @NotNull public static <T> @NotNull Result<Metadata<T>,? extends Throwable> from(@NotNull @NotNull Wrapped<T> wrapped)
      Tries to create a Metadata instance from another Wrapped value. Since Wrapped.unwrap() can fail in some implementations (like in Result) this returns a Result containing the UnwrapException obtained when unwrapping the originally wrapped value, if any is thrown.
      If the original Wrapped is already a Metadata instance then its metadata will be copied into the new instance.
      Type Parameters:
      T - The type of the value
      Parameters:
      wrapped - The source wrapped value
      Returns:
      A Metadata instance with the original value that was Wrapped
    • from

      @NotNull public static <T> @NotNull Result<Metadata<T>,? extends Throwable> from(@NotNull @NotNull Wrapped<T> wrapped, Map<Object,Object> additionalMetadata)
      Tries to create a Metadata instance from another Wrapped value. Since Wrapped.unwrap() can fail in some implementations (like in Result) this returns a Result containing the UnwrapException obtained when unwrapping the originally wrapped value, if any is thrown.
      If the original Wrapped is already a Metadata instance then its metadata will be copied into the new instance.
      Type Parameters:
      T - The type of the value
      Parameters:
      wrapped - The source wrapped value
      additionalMetadata - Metadata to add
      Returns:
      A Metadata instance with the original value that was Wrapped
    • unwrap

      public T unwrap()
      Gets the wrapped value. This method is allowed to throw a UnwrapException if the specific implementors requires so.
      Specified by:
      unwrap in interface Wrapped<T>
      Returns:
      The wrapped value
    • toTuple

      public Pair<T,Map<Object,Object>> toTuple()
      A Pair composed by the value and its metadata map
      Returns:
      a Pair object with the value and the metadata