# Class: com.pnfsoftware.jeb.util.base.DynamicEnum

Base class for dynamic enumerations. Dynamic enumerations are custom\-built enumerations supporting the addition and removal of entries. 

 A dynamic enum must adhere to a defined contract. It is recommended to use the template below: 

```

 @Ser
 static public class Something extends DynamicEnum<Something\> {
     // --- start of static fields ---
     protected static LinkedHashMap<String, Something\> map = new LinkedHashMap<\>();
     // built-in constants must be created here (or in the a static initializer block)
     public static final Something UNKNOWN = register(0, "UNKNOWN");
     public static final Something BLAH = register(1, "BLAH");
     public static final Something FOOBAR = register(2, "FOOBAR");
     // count of built-in constants; those cannot be unregistered!
     public static final int builtinCount = map.size();
     // --- end of static fields ---

     // non-static fields are allowed, but naturally restricted to simple types (primitives, strings, etc.)

     // id and name are mandatory
     protected Something(int id, String name) {
         super(id, name);
     }

     @Override
     public int ordinal() {
         return ordinal(map, this);
     }

     public static int count() {
         return map.size();
     }

     public static Collection<Something\> values() {
         return values(map);
     }

     public static Something valueOf(String name) {
         return valueOf(map, name, UNKNOWN);
     }

     public static Something valueOf(int id) {
         return valueOf(map, id, UNKNOWN);
     }

     public static Something register(int id, String name) {
         return register(map, new Something(id, name));
     }

     public static boolean unregister(String name) {
         return unregister(map, builtinCount, name);
     }
 }
 
```

## Protected Constructor: DynamicEnum
- parameter: `id`, type: `int`
- parameter: `name`, type: `java.lang.String`

Description: Create a dynamic enum entry.
parameter: id: entry identifier
parameter: name: non\-empty entry name

## Protected Field: id
Type: `int`
Description: Unique identifier for this entry.

## Protected Field: name
Type: `java.lang.String`
Description: Unique name for this entry.

## Method: equals
- parameter: `obj`, type: `java.lang.Object`
- return type: `boolean`


## Method: hashCode
- return type: `int`


## Method: id
- return type: `int`

Description: Get this entry's identifier.
return: entry identifier

## Method: isCompatibleWith
- parameter: `other`, type: `E`
- return type: `boolean`

Description: Determine whether two dyn.enums are compatible. This default implementation performs a name\-based compatibility test, using \_ as a hierarchical separator. An enum named SOME\_THING is compatible with SOME\_THING\_ELSE, SOME, but not with SO, SOM, SOMETHING, SOME\_FOO or SOME\_THINGELSE. 

 This method may be overridden.
parameter: other: another enum
return: true if this enumerated constant is compatible with the provided enumerated constant

## Method: name
- return type: `java.lang.String`

Description: Get this entry's name.
return: entry name

## Method: ordinal
- return type: `int`

Description: Get this entry's current ordinal in its dynamic enum.
return: current ordinal of this entry

## Method: toString
- return type: `java.lang.String`


## Protected Static Method: isBuiltin
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- parameter: `builtinCount`, type: `int`
- parameter: `e`, type: `E`
- return type: `boolean`

Description: Determine whether an entry is part of the built\-in prefix of an entry map.
parameter: E: dynamic enum type
parameter: map: entry map
parameter: builtinCount: number of built\-in entries
parameter: e: entry
return: true if the entry is built in

## Protected Static Method: ordinal
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- parameter: `e`, type: `E`
- return type: `int`

Description: Retrieve the ordinal of an entry in an entry map.
parameter: E: dynamic enum type
parameter: map: entry map
parameter: e: entry
return: ordinal, or \-1 if the entry is not present

## Protected Static Method: register
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- parameter: `e`, type: `E`
- return type: `E`

Description: Register an entry.
parameter: E: dynamic enum type
parameter: map: entry map
parameter: e: entry to register
return: registered entry

## Protected Static Method: unregister
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- parameter: `builtinCount`, type: `int`
- parameter: `name`, type: `java.lang.String`
- return type: `boolean`

Description: Unregister a non\-built\-in entry.
parameter: E: dynamic enum type
parameter: map: entry map
parameter: builtinCount: number of built\-in entries
parameter: name: entry name
return: true if an entry was removed

## Protected Static Method: valueOf
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- parameter: `id`, type: `int`
- parameter: `def`, type: `E`
- return type: `E`

Description: Retrieve an entry by identifier.
parameter: E: dynamic enum type
parameter: map: entry map
parameter: id: entry identifier
parameter: def: optional; useful when deserializing unknown entries / entries that have not been            re\-registered
return: an entry or the provided default entry \(which may be null\)

## Protected Static Method: valueOf
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- parameter: `name`, type: `java.lang.String`
- parameter: `def`, type: `E`
- return type: `E`

Description: Retrieve an entry by name.
parameter: E: dynamic enum type
parameter: map: entry map
parameter: name: entry name
parameter: def: optional; useful when deserializing unknown entries / entries that have not been            re\-registered
return: an entry or the provided default entry \(which may be null\)

## Protected Static Method: values
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- return type: `java.util.Collection<E>`

Description: Retrieve all registered entries.
parameter: E: dynamic enum type
parameter: map: entry map
return: unmodifiable view of registered entries

## Protected Static Method: verifyAvailability
- parameter: `map`, type: `java.util.Map<java.lang.String,E>`
- parameter: `id`, type: `int`
- parameter: `name`, type: `java.lang.String`

Description: Verify that an identifier and name are available for registration.
parameter: E: dynamic enum type
parameter: map: entry map
parameter: id: entry identifier
parameter: name: entry name

