com.barchart.util.enums.lookup.EnumLookup Maven / Gradle / Ivy
The newest version!
/**
* Copyright (C) 2011-2012 Barchart, Inc.
*
* All rights reserved. Licensed under the OSI BSD License.
*
* http://www.opensource.org/licenses/bsd-license.php
*/
package com.barchart.util.enums.lookup;
import java.util.HashMap;
import java.util.Map;
public final class EnumLookup & Keyable> {
private final Map map;
private EnumLookup(Map map) {
this.map = map;
}
public V get(K key) {
return map.get(key);
}
public static & Keyable> EnumLookup create(Class enumClass) {
V[] enumConstants = enumClass.getEnumConstants();
Map map = new HashMap();
for (V constant : enumConstants) {
K key = constant.getKey();
map.put(key, constant);
}
return new EnumLookup(map);
}
}