## dods.dap
Class PrimitiveVector

    java.lang.Object
      dods.dap.PrimitiveVector

All Implemented Interfaces:
  ClientIO, Cloneable

Direct Known Subclasses:
  BaseTypePrimitiveVector, BooleanPrimitiveVector, BytePrimitiveVector, Float32PrimitiveVector, Float64PrimitiveVector, Int16PrimitiveVector, Int32PrimitiveVector

public abstract class PrimitiveVector
extends Object
implements ClientIO, Cloneable

A helper class for `DVector`. It allows `DVector`, and by extension, `DArray` and `DList`, to use more efficient primitive types to hold large arrays of data. A `PrimitiveVector` class is defined for each primitive type supported in DODS, and a `BaseTypePrimitiveVector` class handles `DArray`s and `DList`s of compound types.

See Also:
  `BaseType`, `DVector`

Constructor Summary
`PrimitiveVector(BaseType var)` Constructs a new `PrimitiveVector`.

Method Summary
`Object` `clone()` Returns a clone of this `PrimitiveVector`.
`abstract void` `deserialize(DataInputStream source, ServerVersion sv, StatusUI statusUI)` Reads data from a `DataInputStream`.
`abstract void` `externalize(DataOutputStream sink)` Writes data to a `DataOutputStream`.
`abstract Object` `getInternalStorage()` Returns (a reference to) the internal storage for PrimitiveVector.
`abstract int` `getLength()` Returns the number of elements in the array.
`BaseType` `getTemplate()` Returns the template variable for this vector.
`void` `printDecl(PrintWriter os, String space, boolean print_semi)` Write the variable's declaration in a C-style syntax.
`void` `printDecl(PrintWriter os, String space, boolean print_semi, boolean constrained)` Write the variable's declaration in a C-style syntax.
`abstract void` `printSingleVal(PrintWriter os, int index)` Prints the value of a single variable in this vector.
`abstract void` `printVal(PrintWriter os, String space)` Prints the value of all variables in this vector.
`abstract void` `setInternalStorage(Object o)` Set the internal storage for PrimitiveVector.
`abstract void` `setLength(int len)` Sets the number of elements in the array.
`abstract PrimitiveVector` `subset(int start, int stop, int stride)` Create a new primitive vector using a subset of the data.

Methods inherited from class java.lang.Object
`equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### PrimitiveVector

    public PrimitiveVector(BaseType var)

  Constructs a new `PrimitiveVector`.

Parameters:
  `var` - the template `BaseType` to use.

Method Detail

### clone

    public Object clone()

  Returns a clone of this `PrimitiveVector`. A deep copy is performed on all data inside the variable.

  Returns:
    a clone of this `PrimitiveVector`.

### getTemplate

    public final BaseType getTemplate()

  Returns the template variable for this vector.

  Returns:
    the template variable for this vector.
  See Also:
    `BaseTypePrimitiveVector.deserialize(DataInputStream, ServerVersion, StatusUI)`

### getLength

    public abstract int getLength()

  Returns the number of elements in the array.

  Returns:
    the number of elements in the array.

### setLength

    public abstract void setLength(int len)

  Sets the number of elements in the array. Allocates a new primitive array of the desired size. Note that if this is called multiple times, the old array and its contents will be lost.

  Only called inside of `deserialize` method or in derived classes on server.

  Parameters:
    `len` - the number of elements in the array.

### deserialize

    public abstract void deserialize(DataInputStream source,
                                     ServerVersion sv,
                                     StatusUI statusUI)
                              throws IOException,
                                     EOFException,
                                     DataReadException

  Reads data from a `DataInputStream`. This method is only used on the client side of the DODS client/server connection.

  Specified by:
    `deserialize` in interface `ClientIO`
  Parameters:
    `source` - a `DataInputStream` to read from.
    `sv` - The `ServerVersion` returned by the server. (used by `DSequence` to determine which protocol version was used).
    `statusUI` - The `StatusUI` object to use for GUI updates and user cancellation notification (may be null).
  Throws:
    `DataReadException` - when invalid data is read, or if the user cancels the download.
    `EOFException` - if EOF is found before the variable is completely deserialized.
    `IOException` - thrown on any other InputStream exception.
  See Also:
    `ClientIO.deserialize(DataInputStream, ServerVersion, StatusUI)`

### externalize

    public abstract void externalize(DataOutputStream sink)
                              throws IOException

  Writes data to a `DataOutputStream`. This method is used primarily by GUI clients which need to download DODS data, manipulate it, and then re-save it as a binary file.

  Specified by:
    `externalize` in interface `ClientIO`
  Parameters:
    `sink` - a `DataOutputStream` to write to.
  Throws:
    `IOException` - thrown on any `OutputStream` exception.

### printDecl

    public final void printDecl(PrintWriter os,
                                String space,
                                boolean print_semi,
                                boolean constrained)

  Write the variable's declaration in a C-style syntax. This method is used to create textual representation of the Data Descriptor Structure (DDS).

  Parameters:
    `os` - The `PrintWriter` on which to print the declaration.
    `space` - Each line of the declaration will begin with the characters in this string. Usually used for leading spaces.
    `print_semi` - a boolean value indicating whether to print a semicolon at the end of the declaration.
    `constrained` - a boolean value indicating whether to print the declartion dependent on the projection information. This is only used by Server side code.
  See Also:
    `BaseType.printDecl(PrintWriter, String, boolean, boolean)`

### printDecl

    public final void printDecl(PrintWriter os,
                                String space,
                                boolean print_semi)

  Write the variable's declaration in a C-style syntax. This method is used to create textual representation of the Data Descriptor Structure (DDS).

  Parameters:
    `os` - The `PrintWriter` on which to print the declaration.
    `space` - Each line of the declaration will begin with the characters in this string. Usually used for leading spaces.
    `print_semi` - a boolean value indicating whether to print a semicolon at the end of the declaration.
  See Also:
    `BaseType.printDecl(PrintWriter, String, boolean)`

### printVal

    public abstract void printVal(PrintWriter os,
                                  String space)

  Prints the value of all variables in this vector. This method is primarily intended for debugging DODS applications and text-based clients such as geturl.

  Parameters:
    `os` - the `PrintWriter` on which to print the value.
    `space` - this value is passed to the `printDecl` method, and controls the leading spaces of the output.
  See Also:
    `BaseType.printVal(PrintWriter, String, boolean)`

### printSingleVal

    public abstract void printSingleVal(PrintWriter os,
                                        int index)

  Prints the value of a single variable in this vector. method is used by `DArray`'s `printVal` method.

  Parameters:
    `os` - the `PrintWriter` on which to print the value.
    `index` - the index of the variable to print.
  See Also:
    `DArray.printVal(PrintWriter, String, boolean)`

### getInternalStorage

    public abstract Object getInternalStorage()

  Returns (a reference to) the internal storage for PrimitiveVector.

  ## WARNING:

  Because this method breaks encapsulation rules the user must beware! If we (the DODS prgramming team) choose to change the internal representation(s) of these types your code will probably break.

  This method is provided as an optimization to eliminate massive copying of data.

### setInternalStorage

    public abstract void setInternalStorage(Object o)

  Set the internal storage for PrimitiveVector.

  ## WARNING:

  Because this method breaks encapsulation rules the user must beware! If we (the DODS prgramming team) choose to change the internal representation(s) of these types your code will probably break.

  This method is provided as an optimization to eliminate massive copying of data.

### subset

    public abstract PrimitiveVector subset(int start,
                                           int stop,
                                           int stride)

  Create a new primitive vector using a subset of the data.

  Returns:
    new primitive vector