Package org.snpsift.annotate.mem.arrays

# Class StringArray

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

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

public class StringArray extends StringArrayBase
Implement a memory efficient array of strings It only stores bytes (i.e. UTF-8 encoding) and uses a single byte to mark the end of a string ('\0')

See Also:
  - Serialized Form

## Field Summary

Fields
Modifier and Type
Field
Description
`protected byte[]`
`data`
`protected int[]`
`index2offset`
`static final int`
`MAX_NUM_STRING_TO_SHOW`
`protected int`
`offset`

### Fields inherited from class org.snpsift.annotate.mem.arrays.StringArrayBase

`currentIndex`

## Constructor Summary

Constructors
Constructor
Description
`StringArray(int numElements, int size)`
Constructor

## Method Summary

Modifier and Type
Method
Description
`String`
`get(int i)`
Get the string at array index 'i'
`int`
`getOffset()`
`static StringArray`
`of(String[] strings)`
Create a StringArray from an array of strings
`static StringArray`
`of(Collection<String> strings)`
Create a StringArray from a collection of strings
`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)
`static int`
`sizeOf(String s)`
Calculate the size of a string in memory
`static int`
`sizeOf(String[] strings)`
`static int`
`sizeOf(Collection<String> strings)`
`String`
`toString()`

### Methods inherited from class org.snpsift.annotate.mem.arrays.StringArrayBase

`add, iterator, length`

### Methods inherited from class java.lang.Object

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

### Methods inherited from interface java.lang.Iterable

`forEach, spliterator`

## Field Details

### MAX_NUM_STRING_TO_SHOW

public static final int MAX_NUM_STRING_TO_SHOW

See Also:
  - Constant Field Values

### data

protected byte[] data

### index2offset

protected int[] index2offset

### offset

protected int offset

## Constructor Details

### StringArray

public StringArray(int numElements, int size)
Constructor

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

## Method Details

### sizeOf

public static int sizeOf(String s)
Calculate the size of a string in memory

### sizeOf

public static int sizeOf(String[] strings)

### sizeOf

public static int sizeOf(Collection<String> strings)

### of

public static StringArray of(String[] strings)
Create a StringArray from an array of strings

### of

public static StringArray of(Collection<String> strings)
Create a StringArray from a collection of strings

### get

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

Specified by:
  `get` in class `StringArrayBase`

### getOffset

public int getOffset()

### 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`