All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cdc.util.enums.EnumMask 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 AbstractEnumMask dedicated to non nullable standard enums masks.
 * 

* This class must not (and can not) be specialized to work correctly.
* If specialization is needed, use AbstractEnumMask directly. * * @author Damien Carbonne * * @param The enum type. */ public final class EnumMask> extends AbstractMask, E> { private static final Map>, MaskSupport> MAP = new HashMap<>(); private EnumMask(MaskSupport, E> support, Set values) { super(support, values); } /** * Creates a Support implementation for a standard enum. * * @param The enum type. * @param enumClass The enum class. * @return A Support implementation. */ private static > MaskSupport, E> newSupport(Class enumClass) { final Class> maskClass = Introspection.uncheckedCast(EnumMask.class); final Creator, E> creator = EnumMask::new; return support(maskClass, creator, enumClass, Nullable.FALSE); } /** * Returns the support associated to an enum class. * * @param The enum type. * @param enumClass The enum class. * @return The support for {@code EnumMask}. */ public static > MaskSupport, E> support(Class enumClass) { final MaskSupport tmp; tmp = MAP.computeIfAbsent(enumClass, k -> newSupport(enumClass)); @SuppressWarnings("unchecked") final MaskSupport, E> result = (MaskSupport, E>) tmp; return result; } /** * @return A set of enums for which a support has been created. */ public static Set>> getEnumClasses() { return MAP.keySet(); } /** * Returns the empty mask corresponding to an enum. * * @param The enum type. * @param enumClass The enum class. * @return The empty {@code EnumMask}. */ public static > EnumMask empty(Class enumClass) { return support(enumClass).empty(); } /** * Returns the full mask corresponding to an enum. * * @param The enum type. * @param enumClass The enum class. * @return The full {@code EnumMask}. */ public static > EnumMask full(Class enumClass) { return support(enumClass).full(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy