Interface Partition<K,V>
- Type Parameters:
K- the type of the partition keyV- the type of the partition value
- All Superinterfaces:
Displayable,Formattable<org.apache.commons.lang3.tuple.Pair<K,V>>
- All Known Implementing Classes:
Groups,ImmutablePartition,SampledResults
A stream of key-value pairs. Duplicate keys are permitted.
-
Method Summary
Modifier and TypeMethodDescriptionany()Returns any key-value pair from this partition.default TabularData<org.apache.commons.lang3.tuple.Pair<K,V>> Returns the contents of this object as aTabularDatainstance, which can be used to save, print, or format the data in various ways.distinct()Retains only the unique key-value pairs in this partition.default voidenumerate(BiConsumer<Integer, org.apache.commons.lang3.tuple.Pair<K, V>> consumer) Similar toforEach(BiConsumer)except the index is included.Filters this partition, keeping only those keys evaluating totrue.first()Returns the first key-value pair from this partition.default voidforEach(BiConsumer<K, V> consumer) Invokes a method for each key-value pair in this partition.Applies a grouping function to the keys in this partition.default booleanisEmpty()Returnstrueif this partition is empty.keys()Returns the keys in this partition as a list.default K[]keys(IntFunction<K[]> generator) Returns the keys in this partition as an array.Applies a function to each value in the partition, returning a partition of the results.default <R> RApplies a measurement function to the values in this partition.static <K,V> Partition<K, V> of()Creates an empty partition.static <V> Partition<V,V> Creates a partition with the contents of anIterable.of(Function<Double, K> key, DoubleStream stream) Creates a partition with the contents of aDoubleStream.Creates a partition with the contents of aIntStream.static <K,V> Partition<K, V> Creates a partition with the contents of anIterable.static <K,V> Partition<K, V> Creates a partition with the contents of aStream.static <K,V> Partition<K, V> Creates a partition with the contents of an array.static <K,V> Partition<K, V> Creates a partition with the contents of aMap.of(DoubleStream stream) Creates a partition with the contents of aDoubleStream.Creates a partition with the contents of aIntStream.static <V> Partition<V,V> Creates a partition with the contents of aStream.static <V> Partition<V,V> of(V[] array) Creates a partition with the contents of an array.default Vreduce(BinaryOperator<V> op) Applies a binary reduction operator to the values in this partition.default Vreduce(V identity, BinaryOperator<V> op) Applies a binary reduction operator to the values in this partition.single()Asserts this partition contains exactly one key-value pair, returning said item.singleOrDefault(K defaultKey, V defaultValue) Returns the singular key-value pair contained in this partition, or if empty, returns the given default value.intsize()Returns the number of key-value pairs in this partition.sorted()Sorts the partition using the natural ordering of keys.sorted(Comparator<K> comparator) Sorts the partition based on their keys.stream()Returns aStreamof the key-value pairs in this partition.values()Returns the values in this partition as a list.default V[]values(IntFunction<V[]> generator) Returns the values in this partition as an array.static <K,V> Partition<K, V> Creates a partition by "zipping" together two iterables.static <K,V> Partition<K, V> zip(K[] keys, V[] values) Creates a partition by "zipping" together two arrays.Methods inherited from interface org.moeaframework.util.format.Displayable
display
-
Method Details
-
size
int size()Returns the number of key-value pairs in this partition.- Returns:
- the number of items
-
stream
Returns aStreamof the key-value pairs in this partition.- Returns:
- the stream
-
isEmpty
default boolean isEmpty()Returnstrueif this partition is empty.- Returns:
trueif this partition is empty;falseotherwise
-
keys
Returns the keys in this partition as a list.- Returns:
- the list of keys
-
keys
Returns the keys in this partition as an array.- Parameters:
generator- generator for creating the array- Returns:
- the array of keys
-
values
Returns the values in this partition as a list.- Returns:
- the list of values
-
values
Returns the values in this partition as an array.- Parameters:
generator- generator for creating the array- Returns:
- the array of values
-
map
Applies a function to each value in the partition, returning a partition of the results.- Type Parameters:
R- the result type- Parameters:
map- the mapping function- Returns:
- the partition of results
-
sorted
Sorts the partition using the natural ordering of keys.- Returns:
- the sorted stream
- Throws:
ClassCastException- if the key type is notComparable
-
sorted
Sorts the partition based on their keys.- Parameters:
comparator- the comparator used to sort keys- Returns:
- the sorted partition
-
first
Returns the first key-value pair from this partition.- Returns:
- the selected key-value pair
- Throws:
NoSuchElementException- if the partition is empty
-
any
Returns any key-value pair from this partition.- Returns:
- the selected key-value pair
- Throws:
NoSuchElementException- if the partition is empty
-
singleOrDefault
Returns the singular key-value pair contained in this partition, or if empty, returns the given default value.- Parameters:
defaultKey- the default keydefaultValue- the default value- Returns:
- the single key-value pair or default value
-
single
Asserts this partition contains exactly one key-value pair, returning said item.- Returns:
- the key-value pair
- Throws:
NoSuchElementException- if the partition was empty or contained more than one key-value pair
-
filter
Filters this partition, keeping only those keys evaluating totrue.- Parameters:
predicate- the predicate function based on the key- Returns:
- the resulting partition
-
groupBy
Applies a grouping function to the keys in this partition. Keys with the same grouping key are grouped together.- Type Parameters:
G- the type of the grouping key- Parameters:
group- the grouping function- Returns:
- the resulting groups
-
reduce
Applies a binary reduction operator to the values in this partition. SeeStream.reduce(BinaryOperator)for more details.- Parameters:
op- the binary reduction operator- Returns:
- the final result from the reduction operator
- Throws:
NoSuchElementException- if the partition is empty
-
reduce
Applies a binary reduction operator to the values in this partition. SeeStream.reduce(Object, BinaryOperator)for more details.- Parameters:
identity- the initial value supplied to the binary operatorop- the binary reduction operator- Returns:
- the final result from the reduction operator
-
distinct
Retains only the unique key-value pairs in this partition.- Returns:
- the resulting partition
-
measure
Applies a measurement function to the values in this partition.- Type Parameters:
R- the return value- Parameters:
measure- the measurement function- Returns:
- the measured value
-
forEach
Invokes a method for each key-value pair in this partition.- Parameters:
consumer- the method to invoke
-
enumerate
Similar toforEach(BiConsumer)except the index is included.- Parameters:
consumer- the method to invoke
-
asTabularData
Description copied from interface:FormattableReturns the contents of this object as aTabularDatainstance, which can be used to save, print, or format the data in various ways.- Specified by:
asTabularDatain interfaceFormattable<K>- Returns:
- the
TabularDatainstance
-
of
Creates an empty partition.- Type Parameters:
K- the type of the keysV- the type of the values- Returns:
- the constructed partition
-
of
Creates a partition with the contents of aStream. The values are also used as the keys.- Type Parameters:
V- the type of the stream- Parameters:
stream- the source stream- Returns:
- the constructed partition
-
of
Creates a partition with the contents of aIntStream. The values are also used as the keys.- Parameters:
stream- the source stream- Returns:
- the constructed partition
-
of
Creates a partition with the contents of aDoubleStream. The values are also used as the keys.- Parameters:
stream- the source stream- Returns:
- the constructed partition
-
of
Creates a partition with the contents of anIterable. The values are also used as the keys.- Type Parameters:
V- the type of the iterable- Parameters:
iterable- the iterable- Returns:
- the constructed partition
-
of
Creates a partition with the contents of an array. The values are also used as the keys.- Type Parameters:
V- the type of the array- Parameters:
array- the array- Returns:
- the constructed partition
-
of
Creates a partition with the contents of aMap.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
map- the source map- Returns:
- the constructed partition
-
of
Creates a partition with the contents of aStream.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
key- the function returning the key for each valuestream- the source stream- Returns:
- the constructed partition
-
of
Creates a partition with the contents of aIntStream.- Type Parameters:
K- the type of the keys- Parameters:
key- the function returning the key for each valuestream- the source stream- Returns:
- the constructed partition
-
of
Creates a partition with the contents of aDoubleStream.- Type Parameters:
K- the type of the keys- Parameters:
key- the function returning the key for each valuestream- the source stream- Returns:
- the constructed partition
-
of
Creates a partition with the contents of anIterable.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
key- the function returning the key for each valueiterable- the source iterable- Returns:
- the constructed partition
-
of
Creates a partition with the contents of an array.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
key- the function returning the key for each valuearray- the source array- Returns:
- the constructed partition
-
zip
Creates a partition by "zipping" together two iterables.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
keys- the iterable of keysvalues- the iterable of values- Returns:
- the constructed partition
-
zip
Creates a partition by "zipping" together two arrays.- Type Parameters:
K- the type of the keysV- the type of the values- Parameters:
keys- the array of keysvalues- the array of values- Returns:
- the constructed partition
-