Class Views

java.lang.Object
pascal.taie.util.collection.Views

public final class Views extends Object
Provides unmodifiable view collections. TODO: doc complexity of specific operations.
  • Method Details

    • toMappedCollection

      public static <T, R> Collection<R> toMappedCollection(Collection<T> c, Function<T,R> mapper, Predicate<Object> contains)
      Given a mapper function, creates an immutable view collection for given collection. The elements of the resulting collection are mapped from given collection.
      Type Parameters:
      T - type of elements in backing collection
      R - type of elements in view collection
      Parameters:
      c - the backing collection
      mapper - the function maps elements in backing collection to the ones in view collection
      contains - the predicate function that check if view collection contains given object.
      Returns:
      an immutable view collection.
    • toMappedCollection

      public static <T, R> Collection<R> toMappedCollection(Collection<T> c, Function<T,R> mapper)
      Given a mapper function, creates an immutable view collection for given collection. The elements of the resulting collection are mapped from given collection.
      Type Parameters:
      T - type of elements in backing collection
      R - type of elements in view collection
      Parameters:
      c - the backing collection
      mapper - the function maps elements in backing collection to the ones in view collection
      Returns:
      an immutable view collection.
    • toMappedSet

      public static <T, R> Set<R> toMappedSet(Collection<T> c, Function<T,R> mapper, Predicate<Object> contains)
      Given a mapper function, creates an immutable view set for given collection.

      WARNING: the uniqueness of elements in the resulting set view is guaranteed by given collection c and function mapper, not by the resulting set view itself.

      Type Parameters:
      T - type of elements in backing collection
      R - type of elements in view collection
      Parameters:
      c - the backing collection
      mapper - the function maps elements in backing collection to the ones in view collection
      contains - the predicate function that check if view collection contains given object
      Returns:
      an immutable view set.
    • toMappedSet

      public static <T, R> Set<R> toMappedSet(Collection<T> c, Function<T,R> mapper)
      Given a mapper function, creates an immutable view set for given collection.

      WARNING: the uniqueness of elements in the resulting set view is guaranteed by given collection c and function mapper, not by the resulting set view itself.

      Type Parameters:
      T - type of elements in backing collection
      R - type of elements in view collection
      Parameters:
      c - the backing collection
      mapper - the function maps elements in backing collection to the ones in view collection
      Returns:
      an immutable view set.
    • toFilteredCollection

      public static <T> Collection<T> toFilteredCollection(Collection<? extends T> backing, Predicate<T> filter)
      Given a filter function, creates an immutable view collection for given collection. The elements in the original collection that do not satisfy the filter function will be absent in the resulting collection.
      Type Parameters:
      T - type of elements in the resulting collection
      Parameters:
      backing - the backing collection
      filter - the function that decides which elements stay in the resulting collection
      Returns:
      an immutable view collection.
    • toCombinedSet

      public static <T> Set<T> toCombinedSet(Set<? extends T> set1, Set<? extends T> set2)
      Given two sets, creates an immutable view set consisting of elements of the two sets.

      WARNING: this implementation simply treats two sets as one set and does not guarantee the uniqueness of elements. It is responsibility of the client code to guarantee that the elements in set1 and set2 are disjoint.

      Type Parameters:
      T - type of elements
      Parameters:
      set1 - the first set to combine
      set2 - the second set to combine
      Returns:
      an immutable view set containing elements of set1 and set2