java.lang.Object
org.glassfish.jersey.internal.util.collection.Views

public class Views extends Object
Collections utils, which provide transforming views for List and Map.
Author:
Pavel Bucek
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T, R> List<T>
    listView(List<R> originalList, Function<R,T> transformer)
    Create a List view, which transforms the values of provided original list.
    static <K, V, O> Map<K,V>
    mapView(Map<K,O> originalMap, Function<O,V> valuesTransformer)
    Create a Map view, which transforms the values of provided original map.
    static <E> Set<E>
    setDiffView(Set<? extends E> set1, Set<? extends E> set2)
    Create a view of a difference of provided sets, i.e. the diff filters out from the first set the items included in the second set.
    static <E> Set<E>
    setUnionView(Set<? extends E> set1, Set<? extends E> set2)
    Create a view of an union of provided sets.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • listView

      public static <T, R> List<T> listView(List<R> originalList, Function<R,T> transformer)
      Create a List view, which transforms the values of provided original list.

      Removing elements from the view is supported, adding and setting isn't and throws UnsupportedOperationException when invoked.

      Type Parameters:
      T - transformed type parameter.
      R - type of the element from provided list.
      Parameters:
      originalList - original list.
      transformer - transforming functions.
      Returns:
      transformed list view.
    • mapView

      public static <K, V, O> Map<K,V> mapView(Map<K,O> originalMap, Function<O,V> valuesTransformer)
      Create a Map view, which transforms the values of provided original map.

      Removing elements from the map view is supported, adding and setting isn't and throws UnsupportedOperationException when invoked.

      Type Parameters:
      K - key type.
      V - transformed value type.
      O - original value type.
      Parameters:
      originalMap - provided map.
      valuesTransformer - values transformer.
      Returns:
      transformed map view.
    • setUnionView

      public static <E> Set<E> setUnionView(Set<? extends E> set1, Set<? extends E> set2)
      Create a view of an union of provided sets.

      View is updated whenever any of the provided set changes.

      Type Parameters:
      E - set item type.
      Parameters:
      set1 - first set.
      set2 - second set.
      Returns:
      union view of given sets.
    • setDiffView

      public static <E> Set<E> setDiffView(Set<? extends E> set1, Set<? extends E> set2)
      Create a view of a difference of provided sets, i.e. the diff filters out from the first set the items included in the second set.

      View is updated whenever any of the provided set changes.

      Type Parameters:
      E - set item type.
      Parameters:
      set1 - first set.
      set2 - second set.
      Returns:
      view that is a difference of given sets.