cdc.util.enums.EnumSynthesisMask Maven / Gradle / Ivy
package cdc.util.enums;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import cdc.util.lang.Introspection;
/**
* Specialization of {@link AbstractSynthesisMask} to non nullable enum values.
*
* WARNING: The class can not be specialized.
*
* @author Damien Carbonne
*
* @param The enum type.
*/
public final class EnumSynthesisMask> extends AbstractSynthesisMask, E> {
private static final Map>, SynthesisMaskSupport, ?>> MAP = new HashMap<>();
private EnumSynthesisMask(SynthesisMaskSupport, E> support,
Map map) {
super(support,
map);
}
private static > SynthesisMaskSupport, E> newSupport(Class enumClass) {
final Class> maskClass = Introspection.uncheckedCast(EnumSynthesisMask.class);
final Creator, E> creator = EnumSynthesisMask::new;
return support(maskClass,
creator,
enumClass,
Nullable.FALSE);
}
/**
* Retrieves or creates the support associated to a class.
*
* @param The enum type.
* @param enumClass The enum class.
* @return The support associated to {@code enumClass}.
*/
public static > SynthesisMaskSupport, E> support(Class enumClass) {
final SynthesisMaskSupport, ?> tmp;
tmp = MAP.computeIfAbsent(enumClass, k -> newSupport(enumClass));
@SuppressWarnings("unchecked")
final SynthesisMaskSupport, E> result = (SynthesisMaskSupport, E>) tmp;
return result;
}
/**
* @return A set of all classes for which a support has been created.
*/
public static Set>> getEnumClasses() {
return MAP.keySet();
}
}