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

org.vfdtech.implementations.Helpers Maven / Gradle / Ivy

Go to download

A utilities service with generic tools implementation. Can be plugged into your java project

There is a newer version: 0.3.5
Show newest version
package org.vfdtech.implementations;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
import java.util.function.Predicate;
import java.util.stream.Collectors;

public class Helpers {
    private static final Logger log = LoggerFactory.getLogger(Helpers.class);
    public static  Map> groupListBy(List listOfValues, String groupBy) {
        return listOfValues.stream().collect(Collectors.groupingBy(m -> {
            try {
                return String.valueOf(m.getClass().getMethod("get".concat(groupBy)).invoke(m));
            } catch (Exception ignored) {
                log.debug("ERROR WHILE REFLECTING FIELDS:::");
            }
            return groupBy;
        }));
    }

    @SuppressWarnings("unused")
    public static  Map> partitionBasedOnCondition
            (List inputList, Predicate condition) {
        return inputList.stream().collect(Collectors.partitioningBy(condition));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy