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

cdc.util.enums.NullableEnumMask 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 standard enums.
 * 

* 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 NullableEnumMask> extends AbstractMask, E> { private static final Map>, MaskSupport> MAP = new HashMap<>(); private NullableEnumMask(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. */ public static > MaskSupport, E> newSupport(Class enumClass) { final Class> maskClass = Introspection.uncheckedCast(NullableEnumMask.class); final Creator, E> creator = NullableEnumMask::new; return support(maskClass, creator, enumClass, Nullable.TRUE); } /** * Returns the support associated to an enum class. * * @param The enum type. * @param enumClass The enum class. * @return The support for {@code NullableEnumMask}. */ 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 NullableEnumMask}. */ public static > NullableEnumMask 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 NullableEnumMask}. */ public static > NullableEnumMask full(Class enumClass) { return support(enumClass).full(); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy