# Class EnumArray

java.lang.Object
org.snpsift.annotate.mem.arrays.StringArrayBase
org.snpsift.annotate.mem.arrays.EnumArray

All Implemented Interfaces:
  `Serializable, Iterable<String>`

public class EnumArray extends StringArrayBase
The EnumArray class is a specialized array for storing and managing strings as enumerated values. It uses a byte array to store the ordinal values of the strings, which are mapped to their corresponding string values using two data structures: an ArrayList for ordinal-to-string mapping and a HashMap for string-to-ordinal mapping. The class provides methods to add strings to the array, retrieve strings by their index, and manage the internal mappings between strings and their ordinal values. It also includes methods to get the size of the array and the approximate memory size of the object. Key features: - Stores strings as enumerated values using a byte array. - Supports up to 255 unique strings. - Provides methods to add, retrieve, and manage strings in the array. - Ensures consistency between the ordinal-to-string and string-to-ordinal mappings. - Converts null strings to empty strings when adding to the array. Usage: - Use the constructor to initialize the array with a specified number of elements or an array of strings. - Use the addEnum method to add a new string and get its ordinal value. - Use the get method to retrieve a string by its index. - Use the set method to add or update a string at a specific index. - Use the size and sizeBytes methods to get the size of the array and the approximate memory size of the object.

See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`protected byte[]`
`data`
`protected Map<String,Integer>`
`enum2ord`
`static final int`
`MAX_NUM_STRING_TO_SHOW`
`static final int`
`MAX_NUMBER_OF_ENUM_VALUES`
`protected ArrayList<String>`
`ord2enum`

### Fields inherited from class StringArrayBase

`currentIndex`

## Constructor Summary

Constructors
Constructor
Description
`EnumArray(int numElements)`
Constructor
`EnumArray(String[] data)`
Constructor for using an array of strings

## Method Summary

Modifier and Type
Method
Description
`int`
`addEnum(String str)`
Add an enum, return the ordinal
`String`
`get(int i)`
Get the string at array index 'i'
`int`
`getOrd(int i)`
Get the ordinal at array index 'i'
`int`
`numEnums()`
Number of enums in the array
`int`
`set(int i, String str)`
Add a string to the array WARNING: Typically you use either 'add' or 'set', but not both
`int`
`size()`
Size of the data array (capacity of number of bytes)
`long`
`sizeBytes()`
Memory size of this object (approximate size in bytes)
`String`
`toString()`

### Methods inherited from class StringArrayBase

`add, iterator, length`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

### Methods inherited from interface Iterable

`forEach, spliterator`

## Field Details

### MAX_NUM_STRING_TO_SHOW

public static final int MAX_NUM_STRING_TO_SHOW

See Also:
  - Constant Field Values

### MAX_NUMBER_OF_ENUM_VALUES

public static final int MAX_NUMBER_OF_ENUM_VALUES

See Also:
  - Constant Field Values

### data

protected byte[] data

### ord2enum

protected ArrayList<String> ord2enum

### enum2ord

protected Map<String,Integer> enum2ord

## Constructor Details

### EnumArray

public EnumArray(String[] data)
Constructor for using an array of strings

Parameters:
  `data` -

### EnumArray

public EnumArray(int numElements)
Constructor

Parameters:
  `numElements` - : Number of elements in the array

## Method Details

### addEnum

public int addEnum(String str)
Add an enum, return the ordinal

### get

public String get(int i)
Get the string at array index 'i'

Specified by:
  `get` in class `StringArrayBase`

### getOrd

public int getOrd(int i)
Get the ordinal at array index 'i'

### numEnums

public int numEnums()
Number of enums in the array

### set

public int set(int i, String str)
Add a string to the array WARNING: Typically you use either 'add' or 'set', but not both

Specified by:
  `set` in class `StringArrayBase`

### size

public int size()
Size of the data array (capacity of number of bytes)

Specified by:
  `size` in class `StringArrayBase`

### sizeBytes

public long sizeBytes()
Memory size of this object (approximate size in bytes)

Specified by:
  `sizeBytes` in class `StringArrayBase`

### toString

public String toString()

Overrides:
  `toString` in class `Object`