Interface Data.View<A>

Type Parameters:
A - the type of unwrapped values
All Known Implementing Classes:
Data.ViewProxy
Enclosing interface:
Data
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@FunctionalInterface public static interface Data.View<A>
Functional interface for unwrapping interpretation of semantic data.
  • Method Summary

    Modifier and Type
    Method
    Description
    default <B, C> Data.View<C>
    andThenCombining(Data.View<B> other, BiFunction<? super A,? super B,? extends C> pair)
    Returns a view that expects a pair, interprets the two elements according to this and a given other view, respectively, and combines the results with a given function.
    static <A> Data.View<A>
    atomic(Class<A> cls)
    Returns a view that expects atomic data of the given type.
    static <A> Data.View<A>
    Returns a view that expects atomic data of the given type.
    default <B> Data.View<B>
    map(Function<? super A,? extends B> fun)
    Returns a view that transforms data interpreted by this view with a given function.
    default <B> Data.View<Map.Entry<A,B>>
    mapsTo(Data.View<B> other)
    Returns a view that expects a pair, interprets the two elements according to this and a given other view, respectively, and combines the results as a map entry.
    default Data.View<Optional<A>>
    Returns a view that expects an optional data element, to be interpreted by this view if present.
    default Data.View<A>
    orElse(A defaultValue)
    Returns a view that expects an optional data element, to be interpreted by this view, or as the given default value if absent.
    default Data.View<A>
    orElseGet(Supplier<? extends A> defaultValue)
    Returns a view that expects an optional data element, to be interpreted by this view, or as the given default value if absent.
    default Data.View<List<A>>
    Returns a view that expects a sequence of data elements, each to be interpreted by this view.
    static <D, T> Data.View<Token<D,T>>
    Returns a view that expects a token.
    view(Data data)
    Returns the unwrapped interpretation of the given data according to this view.
  • Method Details

    • view

      A view(Data data)
      Returns the unwrapped interpretation of the given data according to this view.
      Parameters:
      data - the wrapped data
      Returns:
      the unwrapped data, if this view is compatible
      Throws:
      ClassCastException - if this view is incompatible
    • atomic

      static <A> Data.View<A> atomic(Class<A> cls)
      Returns a view that expects atomic data of the given type.

      The returned view checks that its results are instances of cls.

      Type Parameters:
      A - the type of unwrapped values
      Parameters:
      cls - the type of unwrapped values
      Returns:
      a view that expects atomic data of type cls
    • atomicUnchecked

      static <A> Data.View<A> atomicUnchecked()
      Returns a view that expects atomic data of the given type.

      The returned view does not check that its results are instances of A; ClassCastException may ensue later.

      Type Parameters:
      A - the type of unwrapped values
      Returns:
      a view that expects atomic data of type A
    • token

      static <D, T> Data.View<Token<D,T>> token()
      Returns a view that expects a token.
      Type Parameters:
      D - the type of document identifiers
      T - the type of token types
      Returns:
      a view that expects a token
    • sequence

      default Data.View<List<A>> sequence()
      Returns a view that expects a sequence of data elements, each to be interpreted by this view.
      Returns:
      a view that expects a sequence of data elements, each to be interpreted by this
    • orElse

      default Data.View<A> orElse(A defaultValue)
      Returns a view that expects an optional data element, to be interpreted by this view, or as the given default value if absent.
      Parameters:
      defaultValue - the defaultValue
      Returns:
      a view that expects an optional data element, to be interpreted by this or as defaultValue if absent
    • orElseGet

      default Data.View<A> orElseGet(Supplier<? extends A> defaultValue)
      Returns a view that expects an optional data element, to be interpreted by this view, or as the given default value if absent.

      The default value is provided by a supplier, and only requested if required.

      Parameters:
      defaultValue - a supplier for the defaultValue
      Returns:
      a view that expects an optional data element, to be interpreted by this or as defaultValue.get() if absent
    • optional

      default Data.View<Optional<A>> optional()
      Returns a view that expects an optional data element, to be interpreted by this view if present.
      Returns:
      a view that expects an optional data element, to be interpreted by this or as Optional.empty() if absent
    • map

      default <B> Data.View<B> map(Function<? super A,? extends B> fun)
      Returns a view that transforms data interpreted by this view with a given function.
      Type Parameters:
      B - the type of transformed values
      Parameters:
      fun - the transformation function
      Returns:
      a view that transforms data interpreted this with fun
      Throws:
      NullPointerException - if fun is null
    • andThenCombining

      default <B, C> Data.View<C> andThenCombining(Data.View<B> other, BiFunction<? super A,? super B,? extends C> pair)
      Returns a view that expects a pair, interprets the two elements according to this and a given other view, respectively, and combines the results with a given function.
      Type Parameters:
      B - the type of unwrapped values of the second element of the pair
      C - the type of combined values
      Parameters:
      other - the view for the second element of the pair
      pair - the combining function
      Returns:
      a view that expects a pair, interprets the two elements according to this and other view, respectively, and combines the results with pair
      Throws:
      NullPointerException - if other or pair is null
    • mapsTo

      default <B> Data.View<Map.Entry<A,B>> mapsTo(Data.View<B> other)
      Returns a view that expects a pair, interprets the two elements according to this and a given other view, respectively, and combines the results as a map entry.

      The resulting map entry is immutable.

      Type Parameters:
      B - the type of unwrapped values of the second element of the pair
      Parameters:
      other - the view for the second element of the pair
      Returns:
      a view that expects a pair, interprets the two elements according to this and other view, results, and combines the results as a map entry
      Throws:
      NullPointerException - if other is null