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).

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    This is the main data structure.
    protected int
    The number of active values (which may be different from the array's capacity).
  • Constructor Summary

    Constructors
    Constructor
    Description
    A constructor for a capacity of 8 elements.
  • Method Summary

    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'.
    fromInputStream(InputStream inputStream, String charset)
    Reads the contents of inputStream into a StringArray.
    get(int index)
    This gets a specified element.
    int
    Return the number of elements in the array.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • 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.
  • 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 of inputStream 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 supported charset.
      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