All Downloads are FREE. Search and download functionalities are using the official Maven repository.

functionalj.stream.StreamableAdditionalTerminalOperators Maven / Gradle / Ivy

There is a newer version: 1.0.17
Show newest version
// ============================================================================
// Copyright (c) 2017-2019 Nawapunth Manusitthipol (NawaMan - http://nawaman.net).
// ----------------------------------------------------------------------------
// MIT License
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// ============================================================================
package functionalj.stream;

import java.util.Comparator;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.stream.Collector;

import functionalj.function.Func1;
import functionalj.list.FuncList;
import functionalj.map.FuncMap;
import functionalj.tuple.Tuple2;

public interface StreamableAdditionalTerminalOperators {
    
    public StreamPlus stream();
    
    
    //-- Functionalities --
    
    public default void forEachWithIndex(
            BiConsumer action) {
        stream()
        .forEachWithIndex(action);
    }
    
    //-- groupingBy --
    
    // Eager
    public default  FuncMap> groupingBy(
            Function classifier) {
        return stream()
                .groupingBy(classifier);
    }
    
    // Eager
    public default  FuncMap groupingBy(
            Function   classifier,
            Function, VALUE> aggregate) {
        return stream()
                .groupingBy(classifier, aggregate);
    }
    
    // Eager
    public default  FuncMap groupingBy(
            Function classifier,
            StreamProcessor  processor) {
        return stream()
                .groupingBy(classifier, processor);
    }
    
    // Eager
    public default  FuncMap groupingBy(
            Function                  classifier,
            Supplier> collectorSupplier) {
        return stream()
                .groupingBy(classifier, collectorSupplier);
    }
    
    //-- min-max --
    
    public default > Optional minBy(
            Func1 mapper) {
        return stream()
                .minBy(mapper);
    }
    
    public default > Optional maxBy(
            Func1 mapper) {
        return stream()
                .maxBy(mapper);
    }
    
    public default  Optional minBy(
            Func1        mapper, 
            Comparator comparator) {
        return stream()
                .minBy(mapper, comparator);
    }
    
    public default  Optional maxBy(
            Func1        mapper, 
            Comparator comparator) {
        return stream()
                .maxBy(mapper, comparator);
    }
    
    public default Tuple2, Optional> minMax(
            Comparator comparator) {
        return stream()
                .minMax(comparator);
    }
    
    public default > Tuple2, Optional> minMaxBy(
            Func1 mapper) {
        return stream()
                .minMaxBy(mapper);
    }
    
    public default  Tuple2, Optional> minMaxBy(
            Func1        mapper, 
            Comparator comparator) {
        return stream()
                .minMaxBy(mapper, comparator);
    }
    
    //-- Find --
    
    public default  Optional findFirst(
            Function mapper, 
            Predicate theCondition) {
        return stream()
                .findFirst(mapper, theCondition);
    }
    
    public default   Optional findAny(
            Function mapper, 
            Predicate theCondition) {
        return stream()
                .findAny(mapper, theCondition);
    }
    
    public default Optional findFirst(
            Predicate predicate) {
        return stream()
                .findFirst(predicate);
    }
    
    public default Optional findAny(
            Predicate predicate) {
        return stream()
                .findAny(predicate);
    }
    
    //-- toMap --
    
    public default  FuncMap toMap(
            Function keyMapper) {
        return stream()
                .toMap(keyMapper);
    }
    
    public default  FuncMap toMap(
            Function  keyMapper,
            Function valueMapper) {
        return stream()
                .toMap(keyMapper, valueMapper);
    }
    
    public default  FuncMap toMap(
            Function   keyMapper,
            Function valueMapper,
            BinaryOperator                   mergeFunction) {
        return stream()
                .toMap(keyMapper, valueMapper, mergeFunction);
    }
    
    public default  FuncMap toMap(
            Function keyMapper,
            BinaryOperator                  mergeFunction) {
        return stream()
                .toMap(keyMapper, mergeFunction);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy