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

group.rxcloud.capa.addons.serialzer.value.MapValues Maven / Gradle / Ivy

package group.rxcloud.capa.addons.serialzer.value;

import group.rxcloud.capa.addons.serialzer.delegate.Func1;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

public final class MapValues {

    private MapValues() {

    }

    public static boolean isNullOrEmpty(Map map) {
        return map == null || map.isEmpty();
    }

    public static  Map from(Collection collection, Func1 keySelector) {
        HashMap result = new HashMap<>();
        for (V item : collection) {
            result.put(keySelector.execute(item), item);
        }
        return result;
    }

    public static  Map from(Collection collection, Func1 keySelector, Func1 valueSelector) {
        HashMap result = new HashMap<>();
        for (S item : collection) {
            result.put(keySelector.execute(item), valueSelector.execute(item));
        }
        return result;
    }

    public static  Map from(V[] array, Func1 keySelector) {
        HashMap result = new HashMap<>();
        for (V item : array) {
            result.put(keySelector.execute(item), item);
        }
        return result;
    }

    public static  Map from(S[] array, Func1 keySelector, Func1 valueSelector) {
        HashMap result = new HashMap<>();
        for (S item : array) {
            result.put(keySelector.execute(item), valueSelector.execute(item));
        }
        return result;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy