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

com.github.ormfux.common.utils.MapUtils Maven / Gradle / Ivy

There is a newer version: 1.6.2
Show newest version
package com.github.ormfux.common.utils;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * Utilities to operate on maps.
 */
public final class MapUtils {
    
    private MapUtils() {
        throw new IllegalAccessError(MapUtils.class.getSimpleName() + " class is not intended to be instantiated");
    }
    
    /**
     * Creates a new map from the entries.
     * 
     * @param entries The map entries.
     * @return The map with the entries.
     */
    @SafeVarargs
    public static  Map fillMap(final Entry... entries) {
        final Map result = new HashMap<>();
        Arrays.stream(entries).forEach(entry -> result.put(entry.key, entry.value));
        
        return result;
    }
    
    /**
     * Convenience method to create an entry instance for {@link #fillMap(Entry...)}
     * 
     * @param key Key.
     * @param value Value.
     * @return Key and value wrapped in an Entry.
     */
    public static  Entry entry(final K key, final V value) {
        return new Entry(key, value);
    }
    
    /**
     * A map entry.
     *
     * @param 
     * @param 
     */
    public static class Entry {
        
        /**
         * Entry key.
         */
        private final K key;
        
        /**
         * Entry value.
         */
        private final V value;
        
        /**
         * @param key Key.
         * @param value Value.
         */
        private Entry(final K key, final V value) {
            this.key = key;
            this.value = value;
        }
        
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy