List of usage examples for org.apache.commons.lang3 EnumUtils getEnumMap
public static <E extends Enum<E>> Map<String, E> getEnumMap(final Class<E> enumClass)
Gets the Map of enums by name.
This method is useful when you need a map of enums by name.
From source file:net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement.java
/** * Returns true if this switch statement tests an expression * having an enum type and all the constants of this type * are covered by a switch case. Returns false if the type of * the tested expression could not be resolved. *//* w w w. j a v a2 s . com*/ public boolean isExhaustiveEnumSwitch() { ASTExpression expression = getTestedExpression(); if (expression.getType() == null) { return false; } if (Enum.class.isAssignableFrom(expression.getType())) { @SuppressWarnings("unchecked") Set<String> constantNames = EnumUtils.getEnumMap((Class<? extends Enum>) expression.getType()).keySet(); for (ASTSwitchLabel label : this) { // since this is an enum switch, the labels are necessarily // the simple name of some enum constant. constantNames.remove(label.getFirstDescendantOfType(ASTName.class).getImage()); } return constantNames.isEmpty(); } return false; }
From source file:org.apache.nutch.mapreduce.NutchCounter.java
public <T extends Enum<T>> void register(Class<T> counterClass) { register(EnumUtils.getEnumMap(counterClass).keySet()); }
From source file:org.apache.nutch.mapreduce.NutchCounter.java
protected void register(Collection<String> counters) { if (countersCount.get() != 0) { LOG.warn("already registered"); return;/*from w ww . j a v a2s. c o m*/ } ArrayList<String> newCounters = Lists.newArrayList(); newCounters.addAll(counters); newCounters.addAll(EnumUtils.getEnumMap(Counter.class).keySet()); registerCounters(newCounters); }
From source file:org.xlrnet.tibaija.memory.DefaultCalculatorMemory.java
/** * Takes an Enum class and creates a new map with each enum value as key and the given default value as the value. * * @param numberVariableClass//from w w w .java 2 s . c om * An enum class that is suppossed to become the key of maps. * @param defaultValue * The default value for all entries. * @param <T> * A class extending Enum. * @return A new map with each enum value as key and the given default value as the value. */ @NotNull private <T extends Enum<T>> Map<T, Value> newEnumValueMapWithDefault(@NotNull Class<T> numberVariableClass, @NotNull final Value defaultValue) { Map<T, Value> valueMap = new HashMap<>(); EnumUtils.getEnumMap(numberVariableClass) .forEach((name, enumObject) -> valueMap.put(enumObject, defaultValue)); return valueMap; }