opendap.dap
Class PrimitiveVector

java.lang.Object
  extended by opendap.dap.PrimitiveVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ClientIO
Direct Known Subclasses:
BaseTypePrimitiveVector, BooleanPrimitiveVector, BytePrimitiveVector, Float32PrimitiveVector, Float64PrimitiveVector, Int16PrimitiveVector, Int32PrimitiveVector

public abstract class PrimitiveVector
extends java.lang.Object
implements ClientIO, java.lang.Cloneable, java.io.Serializable

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 OPeNDAP, and a BaseTypePrimitiveVector class handles DArrays and DLists of compound types.

Version:
$Revision: 23881 $
Author:
jehamby
See Also:
BaseType, DVector, Serialized Form

Constructor Summary
PrimitiveVector(BaseType var)
          Constructs a new PrimitiveVector.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this PrimitiveVector.
abstract  void deserialize(java.io.DataInputStream source, ServerVersion sv, StatusUI statusUI)
          Reads data from a DataInputStream.
abstract  void externalize(java.io.DataOutputStream sink)
          Writes data to a DataOutputStream.
abstract  java.lang.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(java.io.PrintWriter os, java.lang.String space, boolean print_semi)
          Write the variable's declaration in a C-style syntax.
 void printDecl(java.io.PrintWriter os, java.lang.String space, boolean print_semi, boolean constrained)
          Write the variable's declaration in a C-style syntax.
abstract  void printSingleVal(java.io.PrintWriter os, int index)
          Prints the value of a single variable in this vector.
abstract  void printVal(java.io.PrintWriter os, java.lang.String space)
          Prints the value of all variables in this vector.
abstract  void setInternalStorage(java.lang.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 java.lang.Object clone()
Returns a clone of this PrimitiveVector. A deep copy is performed on all data inside the variable.

Overrides:
clone in class java.lang.Object
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(java.io.DataInputStream source,
                                 ServerVersion sv,
                                 StatusUI statusUI)
                          throws java.io.IOException,
                                 java.io.EOFException,
                                 DataReadException
Reads data from a DataInputStream. This method is only used on the client side of the OPeNDAP 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.
java.io.EOFException - if EOF is found before the variable is completely deserialized.
java.io.IOException - thrown on any other InputStream exception.
See Also:
ClientIO.deserialize(DataInputStream, ServerVersion, StatusUI)

externalize

public abstract void externalize(java.io.DataOutputStream sink)
                          throws java.io.IOException
Writes data to a DataOutputStream. This method is used primarily by GUI clients which need to download OPeNDAP 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:
java.io.IOException - thrown on any OutputStream exception.

printDecl

public final void printDecl(java.io.PrintWriter os,
                            java.lang.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(java.io.PrintWriter os,
                            java.lang.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(java.io.PrintWriter os,
                              java.lang.String space)
Prints the value of all variables in this vector. This method is primarily intended for debugging OPeNDAP 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(java.io.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 java.lang.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 OPeNDAP 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(java.lang.Object o)
Set the internal storage for PrimitiveVector.

WARNING:

Because this method breaks encapsulation rules the user must beware! If we (the OPeNDAP 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.

Parameters:
start - starting index (i=start)
stop - ending index (i<=stop)
stride - index stride (i+=stride)
Returns:
new primitive vector