Package ghidra.util

# Class StreamUtils

java.lang.Object
ghidra.util.StreamUtils

public class StreamUtils extends Object
Some utilities for streams

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static <T> Iterable<T>`
  `iter(Stream<? extends T> stream)`
  Adapt a stream into an iterable
  `static <T> Stream<T>`
  `lock(Lock lock, Stream<T> stream)`
  Wrap the given stream into a synchronized stream on the given lock
  `static <T> Stream<T>`
  `merge(Collection<? extends Stream<? extends T>> streams, Comparator<? super T> comparator)`
  Union two sorted streams into a single sorted stream
  `static <T> Stream<T>`
  `sync(Object lock, Stream<T> stream)`
  Wrap the given stream into a synchronized stream on the given object's intrinsic lock

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### merge

    public static <T> Stream<T> merge(Collection<? extends Stream<? extends T>> streams, Comparator<? super T> comparator)
    Union two sorted streams into a single sorted stream
    Type Parameters:
      `T` - the type of elements
    Parameters:
      `streams` - the streams to be merged
      `comparator` - the comparator that orders each stream and that will order the resulting stream
    Returns:
      the sorted stream

  - ### iter

    public static <T> Iterable<T> iter(Stream<? extends T> stream)
    Adapt a stream into an iterable
    Type Parameters:
      `T` - the type of elements
    Parameters:
      `stream` - the stream
    Returns:
      an iterable over the same elements in the stream in the same order

  - ### sync

    public static <T> Stream<T> sync(Object lock, Stream<T> stream)
    Wrap the given stream into a synchronized stream on the given object's intrinsic lock

    NOTE: This makes no guarantees regarding the consistency or visit order if the underlying resource is modified between elements being visited. It merely prevents the stream client from accessing the underlying resource concurrently. For such guarantees, the client may need to acquire the lock for its whole use of the stream.

    Type Parameters:
      `T` - the type of elements
    Parameters:
      `lock` - the object on which to synchronize
      `stream` - the (un)synchronized stream
    Returns:
      the synchronized stream

  - ### lock

    public static <T> Stream<T> lock(Lock lock, Stream<T> stream)
    Wrap the given stream into a synchronized stream on the given lock

    NOTE: This makes no guarantees regarding the consistency or visit order if the underlying resource is modified between elements being visited. It merely prevents the stream client from accessing the underlying resource concurrently. For such guarantees, the client may need to acquire the lock for its whole use of the stream.

    Type Parameters:
      `T` - the type of elements
    Parameters:
      `lock` - the lock
      `stream` - the (un)synchronized stream
    Returns:
      the synchronized stream