Package org.apache.el.stream
Class Stream
- java.lang.Object
-
- org.apache.el.stream.Stream
-
public class Stream extends java.lang.ObjectA stream of elements supporting sequential operations such as filter, map, reduce, and various terminal operations.
-
-
Constructor Summary
Constructors Constructor Description Stream(java.util.Iterator<java.lang.Object> iterator)Constructs a new Stream from the given iterator.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description OptionalallMatch(LambdaExpression le)Checks if all elements in the stream match the given predicate.OptionalanyMatch(LambdaExpression le)Checks if any element in the stream matches the given predicate.Optionalaverage()Calculates the average of all numeric elements in the stream.java.lang.Longcount()Counts the number of elements in the stream.Streamdistinct()Returns a stream consisting of the distinct elements of this stream.Streamfilter(LambdaExpression le)Returns a stream consisting of the elements that match the given predicate.OptionalfindFirst()Returns an Optional describing the first element of this stream, or an empty Optional if the stream is empty.StreamflatMap(LambdaExpression le)Returns a stream consisting of the results of replacing each element of this stream with the contents of a stream produced by applying the provided function to each element.java.lang.ObjectforEach(LambdaExpression le)Performs an action for each element of this stream.java.util.Iterator<?>iterator()Returns the underlying iterator for this stream.Streamlimit(java.lang.Number count)Returns a stream consisting of the firstcountelements of this stream.Streammap(LambdaExpression le)Returns a stream consisting of the results of applying the given function to the elements of this stream.Optionalmax()Returns the maximum element of this stream according to natural order.Optionalmax(LambdaExpression le)Returns the maximum element of this stream according to the provided comparator.Optionalmin()Returns the minimum element of this stream according to natural order.Optionalmin(LambdaExpression le)Returns the minimum element of this stream according to the provided comparator.OptionalnoneMatch(LambdaExpression le)Checks if no elements of this stream match the given predicate.Streampeek(LambdaExpression le)Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed.Optionalreduce(LambdaExpression le)Performs a reduction on the elements of this stream, using the provided accumulator function.java.lang.Objectreduce(java.lang.Object seed, LambdaExpression le)Performs a reduction on the elements of this stream, using the provided initial value and accumulator function.Streamsorted()Returns a stream consisting of the elements of this stream, sorted according to natural order.Streamsorted(LambdaExpression le)Returns a stream consisting of the elements of this stream, sorted according to the order induced by the provided comparator.Streamsubstream(java.lang.Number start)Returns a stream consisting of the elements of this stream from the specified start position to the end.Streamsubstream(java.lang.Number start, java.lang.Number end)Returns a stream consisting of the elements of this stream from the specified start position up to, but not including, the specified end position.java.lang.Numbersum()Returns the sum of all numeric elements in the stream.java.lang.Object[]toArray()Returns an array containing all the elements of this stream.java.util.List<java.lang.Object>toList()Returns a list containing all the elements of this stream.
-
-
-
Method Detail
-
filter
public Stream filter(LambdaExpression le)
Returns a stream consisting of the elements that match the given predicate.- Parameters:
le- the predicate to apply to each element- Returns:
- the new filtered stream
-
map
public Stream map(LambdaExpression le)
Returns a stream consisting of the results of applying the given function to the elements of this stream.- Parameters:
le- the function to apply to each element- Returns:
- the new mapped stream
-
flatMap
public Stream flatMap(LambdaExpression le)
Returns a stream consisting of the results of replacing each element of this stream with the contents of a stream produced by applying the provided function to each element.- Parameters:
le- the function to apply to each element which produces a new stream- Returns:
- the new flattened stream
-
distinct
public Stream distinct()
Returns a stream consisting of the distinct elements of this stream.- Returns:
- the new stream with distinct elements
-
sorted
public Stream sorted()
Returns a stream consisting of the elements of this stream, sorted according to natural order.- Returns:
- the new sorted stream
-
sorted
public Stream sorted(LambdaExpression le)
Returns a stream consisting of the elements of this stream, sorted according to the order induced by the provided comparator.- Parameters:
le- the comparator to determine sort order- Returns:
- the new sorted stream
-
forEach
public java.lang.Object forEach(LambdaExpression le)
Performs an action for each element of this stream.- Parameters:
le- the action to perform for each element- Returns:
- null
-
peek
public Stream peek(LambdaExpression le)
Returns a stream consisting of the elements of this stream, additionally performing the provided action on each element as elements are consumed.- Parameters:
le- the action to perform on each element- Returns:
- the new stream
-
iterator
public java.util.Iterator<?> iterator()
Returns the underlying iterator for this stream.- Returns:
- the underlying iterator
-
limit
public Stream limit(java.lang.Number count)
Returns a stream consisting of the firstcountelements of this stream.- Parameters:
count- the number of elements to limit to- Returns:
- the new limited stream
-
substream
public Stream substream(java.lang.Number start)
Returns a stream consisting of the elements of this stream from the specified start position to the end.- Parameters:
start- the start position (inclusive)- Returns:
- the new substream
-
substream
public Stream substream(java.lang.Number start, java.lang.Number end)
Returns a stream consisting of the elements of this stream from the specified start position up to, but not including, the specified end position.- Parameters:
start- the start position (inclusive)end- the end position (exclusive)- Returns:
- the new substream
-
toList
public java.util.List<java.lang.Object> toList()
Returns a list containing all the elements of this stream.- Returns:
- the list of elements
-
toArray
public java.lang.Object[] toArray()
Returns an array containing all the elements of this stream.- Returns:
- the array of elements
-
reduce
public Optional reduce(LambdaExpression le)
Performs a reduction on the elements of this stream, using the provided accumulator function. The first element is used as the initial value.- Parameters:
le- the accumulator function- Returns:
- an Optional describing the reduced value, or empty if this stream is empty
-
reduce
public java.lang.Object reduce(java.lang.Object seed, LambdaExpression le)Performs a reduction on the elements of this stream, using the provided initial value and accumulator function.- Parameters:
seed- the initial value for the reductionle- the accumulator function- Returns:
- the result of the reduction
-
max
public Optional max()
Returns the maximum element of this stream according to natural order.- Returns:
- an Optional describing the maximum element, or empty if this stream is empty
-
max
public Optional max(LambdaExpression le)
Returns the maximum element of this stream according to the provided comparator.- Parameters:
le- the comparator to determine the maximum- Returns:
- an Optional describing the maximum element, or empty if this stream is empty
-
min
public Optional min()
Returns the minimum element of this stream according to natural order.- Returns:
- an Optional describing the minimum element, or empty if this stream is empty
-
min
public Optional min(LambdaExpression le)
Returns the minimum element of this stream according to the provided comparator.- Parameters:
le- the comparator to determine the minimum- Returns:
- an Optional describing the minimum element, or empty if this stream is empty
-
average
public Optional average()
Calculates the average of all numeric elements in the stream.- Returns:
- an Optional containing the average, or empty if the stream is empty
-
sum
public java.lang.Number sum()
Returns the sum of all numeric elements in the stream.- Returns:
- the sum of all elements
-
count
public java.lang.Long count()
Counts the number of elements in the stream.- Returns:
- the number of elements
-
anyMatch
public Optional anyMatch(LambdaExpression le)
Checks if any element in the stream matches the given predicate.- Parameters:
le- the predicate lambda expression- Returns:
- an Optional containing true if any element matches, or empty if the stream is empty
-
allMatch
public Optional allMatch(LambdaExpression le)
Checks if all elements in the stream match the given predicate.- Parameters:
le- the predicate lambda expression- Returns:
- an Optional containing true if all elements match, or empty if the stream is empty
-
noneMatch
public Optional noneMatch(LambdaExpression le)
Checks if no elements of this stream match the given predicate.- Parameters:
le- the predicate lambda expression- Returns:
- an Optional containing true if no elements match, or empty if the stream is empty
-
findFirst
public Optional findFirst()
Returns an Optional describing the first element of this stream, or an empty Optional if the stream is empty.- Returns:
- an Optional describing the first element of this stream
-
-