Package org.jibx.util
Class StringArray
- java.lang.Object
-
- org.jibx.util.StringArray
-
public class StringArray extends java.lang.Object
Wrapper for arrays of ordered strings. This verifies the arrays and supports efficient lookups.- Author:
- Dennis M. Sosnoski
-
-
Field Summary
Fields Modifier and Type Field Description static StringArray
EMPTY_ARRAY
Empty array of strings.private java.lang.String[]
m_list
Ordered array of strings.
-
Constructor Summary
Constructors Constructor Description StringArray(java.lang.String[] list)
Constructor from array of values.StringArray(java.lang.String[] list, StringArray base)
Constructor from array of values to be added to base instance.StringArray(java.lang.String[] list, StringArray array1, StringArray array2)
Constructor from array of values to be added to pair of base instances.StringArray(java.lang.String[] list, StringArray array1, StringArray array2, StringArray array3)
Constructor from array of values to be added to three base instances.StringArray(java.lang.String[] list, StringArray array1, StringArray array2, StringArray array3, StringArray array4)
Constructor from array of values to be added to four base instances.StringArray(StringArray array1, StringArray array2)
Constructor from pair of base instances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
get(int index)
Get string at a particular index in the list.int
indexOf(java.lang.String value)
Find index of a particular string in the array.private java.lang.String[]
mergeArrays(java.lang.String[] list1, java.lang.String[] list2)
Merge a pair of ordered arrays into a single array.int
size()
Get number of values in arrayprivate void
validateArray(java.lang.String[] list)
Make sure passed-in array contains values that are in order and without duplicate values.
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final StringArray EMPTY_ARRAY
Empty array of strings.
-
m_list
private final java.lang.String[] m_list
Ordered array of strings.
-
-
Constructor Detail
-
StringArray
public StringArray(java.lang.String[] list)
Constructor from array of values. This checks the array values to make sure they're ordered and unique, and if they're not throws an exception. Once the array has been passed to this constructor it must not be modified by outside code.- Parameters:
list
- array of values
-
StringArray
public StringArray(java.lang.String[] list, StringArray base)
Constructor from array of values to be added to base instance. This merges the array values, making sure they're ordered and unique, and if they're not throws an exception.- Parameters:
list
- array of valuesbase
- base instance
-
StringArray
public StringArray(StringArray array1, StringArray array2)
Constructor from pair of base instances. This merges the values, making sure they're unique, and if they're not throws an exception.- Parameters:
array1
- first base arrayarray2
- second base array
-
StringArray
public StringArray(java.lang.String[] list, StringArray array1, StringArray array2)
Constructor from array of values to be added to pair of base instances. This merges the array values, making sure they're ordered and unique, and if they're not throws an exception.- Parameters:
list
- array of valuesarray1
- first base arrayarray2
- second base array
-
StringArray
public StringArray(java.lang.String[] list, StringArray array1, StringArray array2, StringArray array3)
Constructor from array of values to be added to three base instances. This merges the array values, making sure they're ordered and unique, and if they're not throws an exception.- Parameters:
list
- array of valuesarray1
- first base arrayarray2
- second base arrayarray3
- third base array
-
StringArray
public StringArray(java.lang.String[] list, StringArray array1, StringArray array2, StringArray array3, StringArray array4)
Constructor from array of values to be added to four base instances. This merges the array values, making sure they're ordered and unique, and if they're not throws an exception.- Parameters:
list
- array of valuesarray1
- first base arrayarray2
- second base arrayarray3
- third base arrayarray4
- fourth base array
-
-
Method Detail
-
mergeArrays
private java.lang.String[] mergeArrays(java.lang.String[] list1, java.lang.String[] list2)
Merge a pair of ordered arrays into a single array. The two source arrays must not contain any values in common.- Parameters:
list1
- first ordered arraylist2
- second ordered array- Returns:
- merged array
-
validateArray
private void validateArray(java.lang.String[] list)
Make sure passed-in array contains values that are in order and without duplicate values.- Parameters:
list
-
-
get
public java.lang.String get(int index)
Get string at a particular index in the list.- Parameters:
index
- list index to be returned- Returns:
- string at that index position
-
indexOf
public int indexOf(java.lang.String value)
Find index of a particular string in the array. This does a binary search through the array values, using a pair of index bounds to track the subarray of possible matches at each iteration.- Parameters:
value
- string to be found in list- Returns:
- index of string in array, or
-1
if not present
-
size
public int size()
Get number of values in array- Returns:
- number of values in array
-
-