com.github.ormfux.common.utils.MapUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ormfux-common-util Show documentation
Show all versions of ormfux-common-util Show documentation
A small collection of Java utilities for every-day use
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;
}
}
}