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

one.util.streamex.VersionSpecific Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2015, 2023 StreamEx contributors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package one.util.streamex;

import java.nio.CharBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Spliterator;
import java.util.function.*;
import java.util.stream.IntStream;

/**
 * @author Tagir Valeev
 */
/* package */ class VersionSpecific {

    > S callWhile(AbstractStreamEx stream, Predicate predicate, boolean drop) {
        Spliterator spltr = stream.spliterator();
        return stream.supply(
                spltr.hasCharacteristics(Spliterator.ORDERED) ? new TakeDrop.TDOfRef<>(spltr, drop, false, predicate)
                        : new TakeDrop.UnorderedTDOfRef(spltr, drop, false, predicate));
    }

    IntStreamEx callWhile(IntStreamEx stream, IntPredicate predicate, boolean drop) {
        return stream.delegate(new TakeDrop.TDOfInt(stream.spliterator(), drop, false, predicate));
    }

    LongStreamEx callWhile(LongStreamEx stream, LongPredicate predicate, boolean drop) {
        return stream.delegate(new TakeDrop.TDOfLong(stream.spliterator(), drop, false, predicate));
    }

    DoubleStreamEx callWhile(DoubleStreamEx stream, DoublePredicate predicate, boolean drop) {
        return stream.delegate(new TakeDrop.TDOfDouble(stream.spliterator(), drop, false, predicate));
    }

     StreamEx callMapMulti(AbstractStreamEx s, BiConsumer> mapper) {
        return s.flatCollection(e -> {
            List result = new ArrayList<>();
            mapper.accept(e, (Consumer) result::add);
            return result;
        });
    }

     IntStreamEx callMapMultiToInt(AbstractStreamEx s, BiConsumer mapper) {
        return s.flatMapToInt(e -> {
            Internals.IntBuffer result = new Internals.IntBuffer();
            mapper.accept(e, (IntConsumer) result::add);
            return result.stream();
        });
    }
    
     LongStreamEx callMapMultiToLong(AbstractStreamEx s, BiConsumer mapper) {
        return s.flatMapToLong(e -> {
            Internals.LongBuffer result = new Internals.LongBuffer();
            mapper.accept(e, (LongConsumer) result::add);
            return result.stream();
        });
    }

     DoubleStreamEx callMapMultiToDouble(AbstractStreamEx s, BiConsumer mapper) {
        return s.flatMapToDouble(e -> {
            Internals.DoubleBuffer result = new Internals.DoubleBuffer();
            mapper.accept(e, (DoubleConsumer) result::add);
            return result.stream();
        });
    }
    
    IntStream ofChars(CharSequence seq) {
        // In JDK 8 there's only default chars() method which uses
        // IteratorSpliterator
        // In JDK 9 chars() method for most of implementations is much better
        return CharBuffer.wrap(seq).chars();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy