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

one.xingyi.utils.StreamHelper Maven / Gradle / Ivy

There is a newer version: 1.5.9
Show newest version
package one.xingyi.utils;

import lombok.var;

import java.util.Optional;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public interface StreamHelper {
    static  Stream streamOf(Optional opt) {
        return opt.map(Stream::of).orElseGet(Stream::empty);
    }
    static  Stream lastN(Stream s, int n) {
        var list = s.collect(Collectors.toList());
        return list.subList(Math.max(0, list.size() - n), list.size()).stream();
    }
    static  T last(Stream s) {
        return s.reduce(null, (acc, v) -> v);
    }

    static  T first(Stream s) {
        return s.findFirst().orElse(null);
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy