Package org.semanticweb.owlapi.util
Class OWLAPIStreamUtils
java.lang.Object
org.semanticweb.owlapi.util.OWLAPIStreamUtils
A few util methods for common stream operations.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Class for pairwise partition -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> boolean
add
(Collection<? super T> c, Stream<T> s) static Stream
<?> allComponents
(HasComponents root) static Stream
<int[]> allPairs
(int size) static <T> Stream
<OWLAPIStreamUtils.Pair<T>> allPairs
(Collection<T> input) static <T> Stream
<OWLAPIStreamUtils.Pair<T>> static <T> List
<T> static <T> List
<T> static <T> List
<T> asListNullsForbidden
(Stream<T> s) static <K,
V, Q> Map <K, V> static <T,
Q> Map <T, Q> static <T> Set
<T> static <T> Set
<T> static <T> Set
<T> asUnorderedSet
(Stream<?> s, Class<T> type) static <T> Set
<T> asUnorderedSet
(Stream<T> s) static int
compareCollections
(Collection<? extends OWLObject> set1, Collection<? extends OWLObject> set2) static int
compareIterators
(Iterator<?> set1, Iterator<?> set2) Compare iterators element by element (sensitive to order)static int
compareLists
(List<? extends OWLObject> set1, List<? extends OWLObject> set2) Check lists for equality (sensitive to order)static int
compareStreams
(Stream<?> set1, Stream<?> set2) Compare streams through iterators (sensitive to order)static boolean
static <T> Stream
<T> empty()
Annotated wrapper for Stream.empty()static boolean
equalIterators
(Iterator<?> set1, Iterator<?> set2) Check iterator contents for equality (sensitive to order)static boolean
equalStreams
(Stream<?> set1, Stream<?> set2) Check streams for equality (sensitive to order)static Stream
<?> flatComponents
(HasComponents root) static <T> Stream
<OWLAPIStreamUtils.Pair<T>> minimalPairs
(Collection<T> input) static <T> Stream
<OWLAPIStreamUtils.Pair<T>> minimalPairs
(Stream<T> input) static <T> OWLAPIStreamUtils.Pair
<T> pair
(T i, T j) static Stream
<int[]> pairs
(int size) static <T> Stream
<OWLAPIStreamUtils.Pair<T>> pairs
(Collection<T> input) static <T> Stream
<OWLAPIStreamUtils.Pair<T>> static <T> List
<T> sorted
(Class<T> type, Collection<? extends T> c) static <T> List
<T> static <T> List
<T> static <T> List
<T> static <T> List
<T> static <T> Stream
<T> streamFromSorted
(Collection<T> c) A method to be used on collections that are sorted, immutable and do not contain nulls.static <T> Stream
<T> streamFromSorted
(T[] c) A method to be used on arrays that are sorted and do not contain nulls.
-
Method Details
-
sorted
- Type Parameters:
T
- type of the returned collection- Parameters:
type
- type of the returned collections
- stream to turn to sorted, duplicate free, no null, list- Returns:
- sorted array containing all elements in the stream, minus nulls and duplicates. The list is immutable.
-
sorted
- Type Parameters:
T
- type of the returned collection- Parameters:
type
- type of the returned collectionc
- collection to turn to sorted, duplicate free, no null, list- Returns:
- sorted array containing all elements in the collection, minus nulls and duplicates. The list is immutable.
-
sorted
- Type Parameters:
T
- type of the returned collection- Parameters:
type
- type of the returned collectionc
- collection to turn to sorted, duplicate free, no null, list- Returns:
- sorted array containing all elements in the collection, minus nulls and duplicates. The list is immutable.
-
sorted
- Type Parameters:
T
- type of the returned collection- Parameters:
type
- type of the returned collectionc
- collection to turn to sorted, duplicate free, no null, list- Returns:
- sorted array containing all elements in the collection, minus nulls and duplicates. The list is immutable.
-
sorted
- Type Parameters:
T
- type of the returned collection- Parameters:
type
- type of the returned collectionc
- array to sort- Returns:
- sorted list containing all elements in the collection, minus nulls and duplicates. The list is immutable.
-
streamFromSorted
A method to be used on collections that are sorted, immutable and do not contain nulls.- Type Parameters:
T
- type of the returned stream- Parameters:
c
- sorted collection of distinct, non null elements; the collection must be immutable- Returns:
- stream that won't cause sorted() calls to sort the collection again
-
streamFromSorted
A method to be used on arrays that are sorted and do not contain nulls.- Type Parameters:
T
- type of the returned stream- Parameters:
c
- sorted array of distinct, non null elements- Returns:
- stream that won't cause sorted() calls to sort the array again
-
asSet
- Type Parameters:
T
- type of the returned collection- Parameters:
s
- stream to turn to set. The stream is consumed by this operation.- Returns:
- set including all elements in the stream
-
asSet
- Type Parameters:
T
- type of return collection- Parameters:
s
- stream to turn to set. The stream is consumed by this operation.type
- force return type to be exactly T- Returns:
- set including all elements in the stream
-
asUnorderedSet
- Type Parameters:
T
- type of the returned collection- Parameters:
s
- stream to turn to set. The stream is consumed by this operation.- Returns:
- set including all elements in the stream
-
asUnorderedSet
- Type Parameters:
T
- type of return collection- Parameters:
s
- stream to turn to set. The stream is consumed by this operation.type
- force return type to be exactly T- Returns:
- set including all elements in the stream
-
asList
- Type Parameters:
T
- type of the returned collection- Parameters:
s
- stream to turn to list. The stream is consumed by this operation.- Returns:
- list including all elements in the stream
-
asListNullsForbidden
- Type Parameters:
T
- type of the returned collection- Parameters:
s
- stream to turn to list. The stream is consumed by this operation.- Returns:
- list including all elements in the stream
-
asList
- Type Parameters:
T
- type of return collection- Parameters:
s
- stream to turn to list. The stream is consumed by this operation.type
- force return type to be exactly T- Returns:
- list including all elements in the stream
-
asMap
- Type Parameters:
T
- type of keyQ
- type of input and value- Parameters:
s
- stream to turn to map. The stream is consumed by this operation.f
- function to create the key- Returns:
- map including all elements in the stream, keyed by f
-
asMap
- Type Parameters:
K
- type of keyV
- type of valueQ
- type of input- Parameters:
s
- stream to turn to map. The stream is consumed by this operation.key
- function to create the keyval
- function to create the value- Returns:
- map including all elements in the stream, keyed by key and valued by val
-
contains
- Parameters:
s
- stream to check for containment. The stream is consumed at least partially by this operationo
- object to search- Returns:
- true if the stream contains the object
-
add
- Type Parameters:
T
- type of the stream- Parameters:
c
- collection to add tos
- stream of elements to add- Returns:
- true if any element in the stream is added to the collection
-
compareCollections
public static int compareCollections(Collection<? extends OWLObject> set1, Collection<? extends OWLObject> set2) - Parameters:
set1
- collection to compareset2
- collection to compare- Returns:
- negative value if set1 comes before set2, positive value if set2 comes before set1, 0 if the two sets are equal or incomparable.
-
compareStreams
Compare streams through iterators (sensitive to order)- Parameters:
set1
- stream to compareset2
- stream to compare- Returns:
- negative value if set1 comes before set2, positive value if set2 comes before set1, 0 if the two sets are equal or incomparable.
-
compareIterators
Compare iterators element by element (sensitive to order)- Parameters:
set1
- iterator to compareset2
- iterator to compare- Returns:
- negative value if set1 comes before set2, positive value if set2 comes before set1, 0 if the two sets are equal or incomparable.
-
equalIterators
Check iterator contents for equality (sensitive to order)- Parameters:
set1
- iterator to compareset2
- iterator to compare- Returns:
- true if the iterators have the same content, false otherwise.
-
equalStreams
Check streams for equality (sensitive to order)- Parameters:
set1
- stream to compareset2
- stream to compare- Returns:
- true if the streams have the same content, false otherwise.
-
compareLists
Check lists for equality (sensitive to order)- Parameters:
set1
- list to compareset2
- list to compare- Returns:
- true if the lists have the same content, false otherwise.
-
empty
Annotated wrapper for Stream.empty()- Type Parameters:
T
- type of the returned stream- Returns:
- empty stream
-
allComponents
- Parameters:
root
- the root for the invisit- Returns:
- recursive invisit of all components included in the root component; includes the root and all intermediate nodes. Annotations and other groups of elements will be represented as streams or collections, same as if the accessor method on the object was used.
-
flatComponents
- Parameters:
root
- the root for the invisit- Returns:
- recursive invisit of all components included in the root component; includes the root and all intermediate nodes. Streams will be flattened.
-
pairs
- Parameters:
size
- size of matrix- Returns:
- a stream of coordinates for a triangular matrix of size
size
. For input 3, the values are (1,2), (1,3), (2,3)
-
allPairs
- Parameters:
size
- size of matrix- Returns:
- a stream of coordinates for a symmetric matrix of size
size
, excluding main diagonal. For input 3, the values are (1,2), (1,3), (2,3), (2,1),(3,1), (3,2)
-
pairs
- Type Parameters:
T
- type of the input- Parameters:
input
- collection to partition- Returns:
- a stream of elements for a triangular matrix of size
l.size()
, where l is the list corresponding to the input collection. For input of length 3, the values are (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3))
-
minimalPairs
- Type Parameters:
T
- type of the input and output- Parameters:
input
- stream to partition- Returns:
- a stream of elements for all pairs (input[i], input[i+1]), e.g., the minimal set of pairwise equivalent class axioms that can replace an n-ary equivalent class axiom.
-
minimalPairs
- Type Parameters:
T
- type of the input and output- Parameters:
input
- collection to partition- Returns:
- a stream of elements for all pairs (input[i], input[i+1]), e.g., the minimal set of pairwise equivalent class axioms that can replace an n-ary equivalent class axiom.
-
allPairs
- Type Parameters:
T
- type of the input and output- Parameters:
input
- collection to partition- Returns:
- a stream of coordinates for a symmetric matrix of size
l.size()
, where l is the list corresponding to the input collection, excluding main diagonal. For input 3, the values are (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)), (l.get(2),l.get(1)),(l.get(3),l.get(1)), (l.get(3),l.get(2))
-
pairs
- Type Parameters:
T
- type of the input and output- Parameters:
input
- collection to partition- Returns:
- a stream of elements for a triangular matrix of size
l.size()
, where l is the list corresponding to the input collection. For input of length 3, the values are (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3))
-
allPairs
- Type Parameters:
T
- type of the input and output- Parameters:
input
- collection to partition- Returns:
- a stream of coordinates for a symmetric matrix of size
l.size()
, where l is the list corresponding to the input collection, excluding main diagonal. For input 3, the values are (l.get(1),l.get(2)), (l.get(1),l.get(3)), (l.get(2),l.get(3)), (l.get(2),l.get(1)),(l.get(3),l.get(1)), (l.get(3),l.get(2))
-
pair
- Type Parameters:
T
- type of the returned pair- Parameters:
i
- firstj
- second- Returns:
- pair of (i,j)
-