Class OWLAPIStreamUtils

java.lang.Object
org.semanticweb.owlapi.util.OWLAPIStreamUtils

public class OWLAPIStreamUtils extends Object
A few util methods for common stream operations.
  • Method Details

    • sorted

      public static <T> List<T> sorted(Class<T> type, Stream<? extends T> s)
      Type Parameters:
      T - type of the returned collection
      Parameters:
      type - type of the returned collection
      s - 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

      public static <T> List<T> sorted(Class<T> type, Collection<? extends T> c)
      Type Parameters:
      T - type of the returned collection
      Parameters:
      type - type of the returned collection
      c - 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

      public static <T> List<T> sorted(Class<T> type, List<? extends T> c)
      Type Parameters:
      T - type of the returned collection
      Parameters:
      type - type of the returned collection
      c - 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

      public static <T> List<T> sorted(Class<T> type, Set<? extends T> c)
      Type Parameters:
      T - type of the returned collection
      Parameters:
      type - type of the returned collection
      c - 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

      @SafeVarargs public static <T> List<T> sorted(Class<T> type, T... c)
      Type Parameters:
      T - type of the returned collection
      Parameters:
      type - type of the returned collection
      c - array to sort
      Returns:
      sorted list containing all elements in the collection, minus nulls and duplicates. The list is immutable.
    • streamFromSorted

      public static <T> Stream<T> streamFromSorted(Collection<T> c)
      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

      public static <T> Stream<T> streamFromSorted(T[] c)
      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

      public static <T> Set<T> asSet(Stream<T> s)
      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

      public static <T> Set<T> asSet(Stream<?> s, Class<T> type)
      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

      public static <T> Set<T> asUnorderedSet(Stream<T> s)
      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

      public static <T> Set<T> asUnorderedSet(Stream<?> s, Class<T> type)
      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

      public static <T> List<T> asList(Stream<T> s)
      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

      public static <T> List<T> asListNullsForbidden(Stream<T> s)
      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

      public static <T> List<T> asList(Stream<?> s, Class<T> type)
      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

      public static <T, Q> Map<T,Q> asMap(Stream<Q> s, Function<Q,T> f)
      Type Parameters:
      T - type of key
      Q - 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

      public static <K, V, Q> Map<K,V> asMap(Stream<Q> s, Function<Q,K> key, Function<Q,V> val)
      Type Parameters:
      K - type of key
      V - type of value
      Q - type of input
      Parameters:
      s - stream to turn to map. The stream is consumed by this operation.
      key - function to create the key
      val - function to create the value
      Returns:
      map including all elements in the stream, keyed by key and valued by val
    • contains

      public static boolean contains(Stream<?> s, Object o)
      Parameters:
      s - stream to check for containment. The stream is consumed at least partially by this operation
      o - object to search
      Returns:
      true if the stream contains the object
    • add

      public static <T> boolean add(Collection<? super T> c, Stream<T> s)
      Type Parameters:
      T - type of the stream
      Parameters:
      c - collection to add to
      s - 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 compare
      set2 - 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

      public static int compareStreams(Stream<?> set1, Stream<?> set2)
      Compare streams through iterators (sensitive to order)
      Parameters:
      set1 - stream to compare
      set2 - 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

      public static int compareIterators(Iterator<?> set1, Iterator<?> set2)
      Compare iterators element by element (sensitive to order)
      Parameters:
      set1 - iterator to compare
      set2 - 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

      public static boolean equalIterators(Iterator<?> set1, Iterator<?> set2)
      Check iterator contents for equality (sensitive to order)
      Parameters:
      set1 - iterator to compare
      set2 - iterator to compare
      Returns:
      true if the iterators have the same content, false otherwise.
    • equalStreams

      public static boolean equalStreams(Stream<?> set1, Stream<?> set2)
      Check streams for equality (sensitive to order)
      Parameters:
      set1 - stream to compare
      set2 - stream to compare
      Returns:
      true if the streams have the same content, false otherwise.
    • compareLists

      public static int compareLists(List<? extends OWLObject> set1, List<? extends OWLObject> set2)
      Check lists for equality (sensitive to order)
      Parameters:
      set1 - list to compare
      set2 - list to compare
      Returns:
      true if the lists have the same content, false otherwise.
    • empty

      public static <T> Stream<T> empty()
      Annotated wrapper for Stream.empty()
      Type Parameters:
      T - type of the returned stream
      Returns:
      empty stream
    • allComponents

      public static Stream<?> allComponents(HasComponents root)
      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

      public static Stream<?> flatComponents(HasComponents root)
      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

      public static Stream<int[]> pairs(int size)
      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

      public static Stream<int[]> allPairs(int size)
      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

      public static <T> Stream<OWLAPIStreamUtils.Pair<T>> pairs(Collection<T> input)
      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

      public static <T> Stream<OWLAPIStreamUtils.Pair<T>> minimalPairs(Stream<T> input)
      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

      public static <T> Stream<OWLAPIStreamUtils.Pair<T>> minimalPairs(Collection<T> input)
      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

      public static <T> Stream<OWLAPIStreamUtils.Pair<T>> allPairs(Collection<T> input)
      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

      public static <T> Stream<OWLAPIStreamUtils.Pair<T>> pairs(Stream<T> input)
      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

      public static <T> Stream<OWLAPIStreamUtils.Pair<T>> allPairs(Stream<T> input)
      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

      public static <T> OWLAPIStreamUtils.Pair<T> pair(T i, T j)
      Type Parameters:
      T - type of the returned pair
      Parameters:
      i - first
      j - second
      Returns:
      pair of (i,j)