Package cdc.enums
Class AbstractMask<M extends AbstractMask<M,V>,V>
- java.lang.Object
-
- cdc.enums.AbstractMask<M,V>
-
- Type Parameters:
M- The mask type.V- The enum type.
- All Implemented Interfaces:
Mask<M,V>
- Direct Known Subclasses:
BooleanMask,EnumMask,NullableBooleanMask,NullableEnumMask
public class AbstractMask<M extends AbstractMask<M,V>,V> extends Object implements Mask<M,V>
Mask (set) of values belonging to a list type.Objects of this class are immutable.
A typical implementation should look like this:
For a standard enum, one can declare:public final class FooMask extends AbstractEnumMask<FooMask, Foo> { public static final Support<FooMask, Foo> SUPPORT = support(FooMask.class, FooMask::new, FooType, Nullable.FALSE); private FooMask(Support<FooMask, Foo> support, Set<Foo> values) { super(support, values); } }public final class FooMask extends AbstractEnumMask<FooMask, Foo> { public static final Support<FooMask, Foo> SUPPORT = support(FooMask.class, FooMask::new, Foo.class, Nullable.FALSE); private FooMask(Support<FooMask, Foo> support, Set<Foo> values) { super(support, values); } }- Author:
- Damien Carbonne
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractMask(MaskSupport<M,V> support, Set<V> values)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Mand(M other)Returns the intersection of this mask with another one.Mand(V value)Mand(V... values)Mclear(V value)Returns a new mask reduced with a value.booleancontains(M other)Returnstrueif all values of this mask are contained in another mask.booleancontains(V... values)Mempty()booleanequals(Object other)Mfull()MaskSupport<M,V>getSupport()Set<V>getValues()inthashCode()booleanisClear(V value)Returnstrueif a value is not contained.booleanisEmpty()booleanisFull()booleanisNullable()booleanisSet(V value)Returnstrueif a value is contained.Mnot()Returns the complement of this mask (at the time of calling this method).Mor(M other)Returns the union of this mask with another one.Mor(V value)Mor(V... values)Mset(V value)Returns a new mask augmented with a value.Mset(V value, boolean enabled)Sets or clears a value.MsetAll(boolean enabled)Returns an empty or full mask.protected static <M extends AbstractMask<M,V>,V>
MaskSupport<M,V>support(Class<M> maskClass, AbstractMask.Creator<M,V> creator, ListType<V> type, Nullable nullable)Creates a Support implementation.protected static <M extends AbstractMask<M,V>,V extends Enum<V>>
MaskSupport<M,V>support(Class<M> maskClass, AbstractMask.Creator<M,V> creator, Class<V> enumClass, Nullable nullable)Creates a Support implementation for a standard enum.StringtoString()StringtoString(Function<? super V,String> valueToString, String separator)Returns a string representation of this mask.
-
-
-
Field Detail
-
support
protected final MaskSupport<M extends AbstractMask<M,V>,V> support
The associated support class.
-
-
Constructor Detail
-
AbstractMask
protected AbstractMask(MaskSupport<M,V> support, Set<V> values)
-
-
Method Detail
-
support
protected static <M extends AbstractMask<M,V>,V> MaskSupport<M,V> support(Class<M> maskClass, AbstractMask.Creator<M,V> creator, ListType<V> type, Nullable nullable)
Creates a Support implementation.- Type Parameters:
M- The mask type.V- The enum type.- Parameters:
maskClass- The mask class.creator- The mask factory.type- The type.nullable-Nullable.TRUEifnullis a valid value.- Returns:
- A Support implementation.
-
support
protected static <M extends AbstractMask<M,V>,V extends Enum<V>> MaskSupport<M,V> support(Class<M> maskClass, AbstractMask.Creator<M,V> creator, Class<V> enumClass, Nullable nullable)
Creates a Support implementation for a standard enum.- Type Parameters:
M- The mask type.V- The enum type.- Parameters:
maskClass- The mask class.creator- The mask factory.enumClass- The enum class.nullable-Nullable.TRUEifnullis a valid value.- Returns:
- A Support implementation.
-
getSupport
public MaskSupport<M,V> getSupport()
- Specified by:
getSupportin interfaceMask<M extends AbstractMask<M,V>,V>- Returns:
- The enum type.
-
isNullable
public boolean isNullable()
- Specified by:
isNullablein interfaceMask<M extends AbstractMask<M,V>,V>- Returns:
trueif this mask is a nullable mask.
-
isEmpty
public boolean isEmpty()
-
isFull
public boolean isFull()
-
isSet
public boolean isSet(V value)
Description copied from interface:MaskReturnstrueif a value is contained.
-
isClear
public boolean isClear(V value)
Description copied from interface:MaskReturnstrueif a value is not contained.
-
set
public M set(V value, boolean enabled)
Description copied from interface:MaskSets or clears a value.
-
set
public M set(V value)
Description copied from interface:MaskReturns a new mask augmented with a value.If
valueis already set, returns this mask.
-
clear
public M clear(V value)
Description copied from interface:MaskReturns a new mask reduced with a value.If
valueis already cleared, returns this mask.
-
setAll
public M setAll(boolean enabled)
Description copied from interface:MaskReturns an empty or full mask.The full mask may change if underlying enum type is dynamic.
-
empty
public M empty()
-
full
public M full()
-
and
public M and(M other)
Description copied from interface:MaskReturns the intersection of this mask with another one.
-
or
public M or(M other)
Description copied from interface:MaskReturns the union of this mask with another one.
-
not
public M not()
Description copied from interface:MaskReturns the complement of this mask (at the time of calling this method).
-
contains
public final boolean contains(M other)
Description copied from interface:MaskReturnstrueif all values of this mask are contained in another mask.
-
contains
@SafeVarargs public final boolean contains(V... values)
-
toString
public String toString(Function<? super V,String> valueToString, String separator)
Description copied from interface:MaskReturns a string representation of this mask.
-
-