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

host.anzo.commons.utils.StreamUtils Maven / Gradle / Ivy

package host.anzo.commons.utils;

import org.jetbrains.annotations.NotNull;

import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

/***
 * @author ANZO
 */
public class StreamUtils {
    public static List closedRange(int startInclusive, int endInclusive) {
        return IntStream.rangeClosed(startInclusive, endInclusive)
                .boxed()
                .collect(Collectors.toList());
    }

    public static > Map sortMapByValue(@NotNull Map map, boolean isReverseOrder) {
        return map.entrySet().stream()
                .sorted(isReverseOrder ? Map.Entry.comparingByValue(Comparator.reverseOrder()) : Map.Entry.comparingByValue(Comparator.naturalOrder()))
                .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy