Package ucar.nc2.ogc.erddap.util
Class ErddapStringArray
- java.lang.Object
-
- ucar.nc2.ogc.erddap.util.ErddapStringArray
-
public class ErddapStringArray extends Object
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).
-
-
Constructor Summary
Constructors Constructor Description ErddapStringArray()
A constructor for a capacity of 8 elements.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(String value)
This adds an item to the array (increasing 'size' by 1).void
ensureCapacity(long minCapacity)
This ensures that the capacity is at least 'minCapacity'.static ErddapStringArray
fromInputStream(InputStream inputStream, String charset)
Reads the contents ofinputStream
into a StringArray.String
get(int index)
This gets a specified element.int
size()
Return the number of elements in the array.
-
-
-
Field Detail
-
size
protected int size
The number of active values (which may be different from the array's capacity).
-
array
public String[] 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.
-
-
Method Detail
-
fromInputStream
public static ErddapStringArray fromInputStream(InputStream inputStream, String charset) throws IOException
Reads the contents ofinputStream
into 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
public void add(String value)
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
public String get(int index)
This gets a specified element.- Parameters:
index
- 0 ... size-1
-
-