util~ BitmaskEnum

An immutable enum-like object with an associated bitmask support.

This class is essentially abstract, and must be extended by another class that overrides the inerited module:util~Enum.enumValues method.

Constructor

(abstract) new BitmaskEnum(name, bitNumber)

Constructor.

Parameters:
NameTypeDescription
namestring

the name

bitNumbernumber

the bit offset, starting from 1 for the least significant bit

Extends

Members

bitmaskBitNumber

Get the bit offset value, starting from 1 for the least significant bit.

bitmaskBitOffset

Get the bit offset value, starting from 0 for the least significant bit.

name

Get the enum name.

Methods

equals(value) → {boolean}

Test if a string is equal to this enum's name.

As long as enum values are consistently obtained from the module:util~Enum.enumValues array then enum instances can be compared with ===. If unsure, this method can be used to compare string values instead.

If value is passed as an actual Enum instance, then if that enum is the same class as this enum it's name is compared to this instance's name.

Parameters:
NameTypeDescription
valuestring | Enum

the value to test

Returns:

true if value is the same as this instance's name value

Type: 
boolean

(static) bitmaskValue(maskables) → {number}

Get a bitmask value for a set of {@code Bitmaskable} objects.

Parameters:
NameTypeDescription
maskablesIterable.<BitmaskEnum>

the set of BitmaskEnum objects

Returns:

a bitmask value of all module:util~BitmaskEnum#bitmaskBitOffset() values of the given maskables

Type: 
number

(static) enumForBitNumber(bitNumber, values) → {BitmaskEnum}

Get a BitmaskEnum objects for a bit number.

Parameters:
NameTypeDescription
bitNumbernumber

a bit number value of the BitmaskEnum object to find

valuesIterable.<BitmaskEnum>

the complete set of possible BitmaskEnum objects

Returns:

the matching BitmaskEnum, or null

Type: 
BitmaskEnum

(static) setForBitmask(mask, values) → {Set.<BitmaskEnum>}

Convert a bitmask value into a set of BitmaskEnum objects.

Parameters:
NameTypeDescription
masknumber

a bitmask value of a set of BitmaskEnum objects

valuesIterable.<BitmaskEnum>

the complete set of possible BitmaskEnum objects

Returns:

a set of BitmaskEnum objects

Type: 
Set.<BitmaskEnum>

(static) setForBitmaskEnum(mask, clazz) → {Set.<BitmaskEnum>}

Convert a bitmask value into a set of {@code Bitmaskable} objects.

Parameters:
NameTypeDescription
masknumber

a bitmask value of a set of {@code Bitmaskable} objects

clazzBitmaskEnum

the class of an enumeration of BitmaskEnum objects

Returns:

a set of BitmaskEnum objects

Type: 
Set.<BitmaskEnum>