org.jvnet.jaxbcommons.util.EnumUtils Maven / Gradle / Ivy
package org.jvnet.jaxbcommons.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
public class EnumUtils {
private EnumUtils() {
}
public static String[] createCodes(final Map enumCodeMap, final Object[] ens) {
final String[] codes = new String[ens.length];
for (int index = 0; index < codes.length; index++) {
final Object value = ens[index];
final String code = (String) enumCodeMap.get(value);
codes[index] = code;
}
return codes;
}
public static Map createEnumCodeMap(final Map codeEnumMap) {
final Map enumCodeMap = new HashMap(codeEnumMap.size());
for (Iterator iterator = codeEnumMap.entrySet().iterator(); iterator.hasNext();) {
final Map.Entry entry = (Map.Entry) iterator.next();
final Object code = entry.getKey();
final Object value = entry.getValue();
enumCodeMap.put(value, code);
}
return enumCodeMap;
}
public static String[] orderCodes(List enumsOrder, String[] codes) {
final List oldCodes = Arrays.asList(codes);
final List newCodes = new ArrayList(codes.length);
for (Iterator iterator = enumsOrder.iterator(); iterator.hasNext();) {
final String code = (String) iterator.next();
if ("*".equals(code)) {
newCodes.addAll(oldCodes);
oldCodes.clear();
}
else {
if (oldCodes.remove(code)) {
newCodes.add(code);
}
}
}
return (String[]) newCodes.toArray(new String[newCodes.size()]);
}
public static Map orderEnumMap(final Map oldEnumMap, String[] codes)
{
final Map newEnumMap = new HashMap(oldEnumMap.size());
for (int index = 0; index < codes.length; index++) {
final String code = codes[index];
final Object value = oldEnumMap.get(code);
if (code != null && value != null)
{
newEnumMap.put(code, value);
}
}
return newEnumMap;
}
public static Map orderEnumCodeMap(final Map oldEnumMap, String[] codes)
{
final Map newEnumCodeMap = new HashMap(oldEnumMap.size());
for (int index = 0; index < codes.length; index++) {
final String code = codes[index];
final Object value = oldEnumMap.get(code);
if (code != null && value != null)
{
newEnumCodeMap.put(value, code);
}
}
return newEnumCodeMap;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy