Package pascal.taie.util.collection
Class Views
java.lang.Object
pascal.taie.util.collection.Views
Provides unmodifiable view collections.
TODO: doc complexity of specific operations.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <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.static <T> Collection<T>
toFilteredCollection
(Collection<? extends T> backing, Predicate<T> filter) Given a filter function, creates an immutable view collection for given collection.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.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.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.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.
-
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 collectionR
- type of elements in view collection- Parameters:
c
- the backing collectionmapper
- the function maps elements in backing collection to the ones in view collectioncontains
- the predicate function that check if view collection contains given object.- Returns:
- an immutable view collection.
-
toMappedCollection
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 collectionR
- type of elements in view collection- Parameters:
c
- the backing collectionmapper
- 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 functionmapper
, not by the resulting set view itself.- Type Parameters:
T
- type of elements in backing collectionR
- type of elements in view collection- Parameters:
c
- the backing collectionmapper
- the function maps elements in backing collection to the ones in view collectioncontains
- the predicate function that check if view collection contains given object- Returns:
- an immutable view set.
-
toMappedSet
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 functionmapper
, not by the resulting set view itself.- Type Parameters:
T
- type of elements in backing collectionR
- type of elements in view collection- Parameters:
c
- the backing collectionmapper
- 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 collectionfilter
- the function that decides which elements stay in the resulting collection- Returns:
- an immutable view collection.
-
toCombinedSet
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
andset2
are disjoint.- Type Parameters:
T
- type of elements- Parameters:
set1
- the first set to combineset2
- the second set to combine- Returns:
- an immutable view set containing elements of
set1
andset2
-