Package ucar.nc2.ogc.erddap.util
Class ErddapStringArray
java.lang.Object
ucar.nc2.ogc.erddap.util.ErddapStringArray
StringArray is a thin shell over a String[] with methods like ArrayList's
methods; it extends PrimitiveArray.
All of the methods which add strings to StringArray (e.g., add()),
use String2.canonical(), to ensure that canonical Strings are stored (to save memory
if there are duplicates).
This class uses "" to represent a missing value (NaN).
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis adds an item to the array (increasing 'size' by 1).voidensureCapacity(long minCapacity) This ensures that the capacity is at least 'minCapacity'.static ErddapStringArrayfromInputStream(InputStream inputStream, String charset) Reads the contents ofinputStreaminto a StringArray.get(int index) This gets a specified element.intsize()Return the number of elements in the array.
-
Field Details
-
size
protected int sizeThe number of active values (which may be different from the array's capacity). -
array
This is the main data structure. This should be private, but is public so you can manipulate it if you promise to be careful. Note that if the PrimitiveArray's capacity is increased, the PrimitiveArray will use a different array for storage.
-
-
Constructor Details
-
ErddapStringArray
public ErddapStringArray()A constructor for a capacity of 8 elements. The initial 'size' will be 0.
-
-
Method Details
-
fromInputStream
public static ErddapStringArray fromInputStream(InputStream inputStream, String charset) throws IOException Reads the contents ofinputStreaminto a StringArray. Each line of input will result in an element in the array. The specified stream remains open after this method returns.- Parameters:
inputStream- a stream with line-based content.charset- the name of a supportedcharset.- Returns:
- a StringArray created from the stream.
- Throws:
IOException- if an I/O error occurs
-
size
public int size()Return the number of elements in the array.- Returns:
- the number of elements in the array.
-
add
This adds an item to the array (increasing 'size' by 1).- Parameters:
value- the value to be added to the array
-
ensureCapacity
public void ensureCapacity(long minCapacity) This ensures that the capacity is at least 'minCapacity'.- Parameters:
minCapacity- the minimum acceptable capacity. minCapacity is type long, but >= Integer.MAX_VALUE will throw exception.
-
get
This gets a specified element.- Parameters:
index- 0 ... size-1
-