br.com.objectos.comuns.sql.EnumSqlMap Maven / Gradle / Ivy
/*
* EnumSqlMap.java criado em 06/08/2012
*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package br.com.objectos.comuns.sql;
import static com.google.common.collect.Maps.newHashMap;
import java.util.EnumSet;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
/**
* @author [email protected] (Marcio Endo)
*/
public class EnumSqlMap & EnumSql> {
private final Map sqlValueMap;
private EnumSqlMap(Class enumClass) {
Map map = newHashMap();
EnumSet values = EnumSet.allOf(enumClass);
for (E value : values) {
String sqlValue = value.getSqlValue();
map.put(sqlValue, value);
}
sqlValueMap = ImmutableMap.copyOf(map);
}
public static & EnumSql> EnumSqlMap of(Class enumClass) {
return new EnumSqlMap(enumClass);
}
public E load(String codigo) {
return sqlValueMap.get(codigo);
}
}