org.omegahat.Environment.ObjectDataStructures
Class vector

java.lang.Object
  |
  +--org.omegahat.Environment.ObjectDataStructures.vector
All Implemented Interfaces:
Addable, AssignableSubset, Divisable, MathOperable, MathOperations, Multiplicable, java.io.Serializable, Subsettable, Subtractable, VariableInt
Direct Known Subclasses:
BasicFactor, character, integer, list, logical, numeric, single

public abstract class vector
extends java.lang.Object
implements java.io.Serializable, Subsettable, AssignableSubset, MathOperations, VariableInt

Abstract class used to represent an S/R-like vector-based container for different elements, much like a Java array but with extensions. This provides different facilities such as operator overloading (+,-,*,/, [, [[), apply supporting functions and methods, etc. This version (as opposed to vector vector) contains most of the functionality inherited by the different typed classes - integer, numeric, etc.

See Also:
Serialized Form

Field Summary
protected  java.util.Vector _data
          Array of the elements managed by this vector.
protected static long NA_PATTERN
           
static java.lang.Object NullObject
           
 
Fields inherited from interface org.omegahat.Environment.DataStructures.MathOperable
DIVIDE, MINUS, MULTIPLY, PLUS
 
Constructor Summary
protected vector()
          Default method for use in derived classes.
  vector(int n)
          Specify just the length and initialize the array for storing the elements.
  vector(long n)
          Specify the length.
  vector(long n, boolean initialize)
           
  vector(vector src, boolean copy)
          Constructor to duplicate an existing vector, either initially linking the data or copying the container for the elments - semi deep copy.
 
Method Summary
 void add(double value, int which)
           
 void add(java.lang.Object value, int which)
           
 int addElement(java.lang.Object el)
           
 java.lang.Object addValue(java.lang.Object rhs, boolean inPlace)
          Method for operator + overloading.
 vector apply(Function func)
           
 vector apply(java.lang.String method)
          Invoke the method specified by name for each of the elements in the
 java.lang.Object[] asArray()
           
protected  java.lang.Object assignElement(int which, java.lang.Object element)
          Assumes that the _data array has been expanded suitably.
 java.lang.Object assignSubset(java.lang.Object index, java.lang.Object value)
           
protected abstract  java.lang.Object convertElement(java.lang.Object element)
           
 vector copy(boolean all)
          A generic method that copies the contents of the a vector or sub-class using reflectance.
 java.lang.Object createElement(double orig)
          Create a new element to be added to this vector using the default class of the elements.
 java.lang.Object createElement(double orig, java.lang.Object el)
          Create a new element for the vector using the first argument as the value and the second argument as a template which should be mimiced, if possible.
 VariableInt createVariable()
           
 java.util.Vector data()
           
 java.util.Vector data(int i)
           
 java.util.Vector data(int i, java.lang.Object el)
           
 java.util.Vector data(java.lang.Object x)
           
 java.util.Vector data(java.lang.Object[] x)
           
 java.lang.Object divide(java.lang.Number other)
           
 java.lang.Object divide(vector other)
           
 java.lang.Object divideValue(java.lang.Object rhs, boolean inPlace)
          Method for operator / overloading.
 java.lang.Object element(int i)
           
protected  java.lang.Object elementMathOp(java.lang.Object el, double v, int op)
          Internal method for performing the low-level math operation on the element el and right hand side v given the operation type op
 java.lang.String elementToString(java.lang.Object el)
           
 java.lang.Object exp(vector other)
           
 java.lang.reflect.Method findMethod(java.lang.String name, java.lang.Object obj)
           
 DataFrameInt getDataFrame()
           
 java.lang.String getName()
          Method for Variable interface.
 logical isNA()
           
 logical isNA(int which)
           
 int length()
           
 int length(int n)
          Set the length of the collection, either initializing the array or resetting the length and copying the existing elements appropriately.
 int length(int n, boolean initialize)
           
 vector mathOperation(double v, int op)
          Iterate over the elements of this vector, performing the mathematical operation identified by op given the right hand side of the operation as v
 java.lang.Object mathOperation(java.lang.Object rhs, boolean inPlace, int op)
          General work-horse method for doing mathematical operations.
 java.lang.Object mathOperation(vector v, int op)
          General method for perform a mathematical operation with this object as the left hand side and the first argument v as the right hand side.
 java.util.Hashtable metaData()
          Intended to be a Property table for storing additional attributes and information about a variable, including entries such as units, nicknames, source, etc.
 java.lang.Object minus(java.lang.Number other)
           
 java.lang.Object minus(vector other)
           
 java.lang.Object multiply(java.lang.Number other)
           
 java.lang.Object multiply(vector other)
           
 java.lang.Object multiplyValue(java.lang.Object rhs, boolean inPlace)
          Method for operator * overloading.
 long numObservations()
          Return the length or number of records in this VariableInt.
 java.lang.Object plus(java.lang.Number other)
           
 java.lang.Object plus(vector other)
           
 int read(java.io.InputStream stream)
           
 int read(java.io.Reader stream)
           
 java.lang.String separator()
           
 DataFrameInt setDataFrame(DataFrameInt fr)
           
 java.lang.String setName(java.lang.String nm)
           
 java.lang.Object subset(java.lang.Object index, boolean keepStructure)
          General method to compute the subset, usually called from the interactive language via expressions of the form x[[1]], x[y,2]
 java.lang.Object subtractValue(java.lang.Object rhs, boolean inPlace)
          Method for operator - overloading.
abstract  java.lang.Class targetClass()
          The default class of each element in the list.
 java.lang.String toString()
           
 java.lang.Object value(long which)
          Return the whichth observation.
 VariableInt values(int[] indices)
          Get a Variable consisting of the specified elements.
 VariableInt values(SelectorInt selector)
          Get a Variable consisting of the specified elements from a selector object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NA_PATTERN

protected static final long NA_PATTERN

NullObject

public static final java.lang.Object NullObject

_data

protected java.util.Vector _data
Array of the elements managed by this vector.
Constructor Detail

vector

protected vector()
Default method for use in derived classes.

vector

public vector(int n)
Specify just the length and initialize the array for storing the elements.

vector

public vector(long n)
Specify the length.
See Also:
vector(int)

vector

public vector(long n,
              boolean initialize)

vector

public vector(vector src,
              boolean copy)
Constructor to duplicate an existing vector, either initially linking the data or copying the container for the elments - semi deep copy.
Method Detail

metaData

public java.util.Hashtable metaData()
Description copied from interface: VariableInt
Intended to be a Property table for storing additional attributes and information about a variable, including entries such as units, nicknames, source, etc.
Specified by:
metaData in interface VariableInt

data

public java.util.Vector data(java.lang.Object[] x)

data

public java.util.Vector data(java.lang.Object x)

data

public java.util.Vector data()

data

public java.util.Vector data(int i)

element

public java.lang.Object element(int i)

length

public int length()

data

public java.util.Vector data(int i,
                             java.lang.Object el)

isNA

public logical isNA(int which)

isNA

public logical isNA()

asArray

public java.lang.Object[] asArray()

plus

public java.lang.Object plus(vector other)

plus

public java.lang.Object plus(java.lang.Number other)

minus

public java.lang.Object minus(vector other)

minus

public java.lang.Object minus(java.lang.Number other)

exp

public java.lang.Object exp(vector other)

multiply

public java.lang.Object multiply(vector other)

multiply

public java.lang.Object multiply(java.lang.Number other)

divide

public java.lang.Object divide(vector other)

divide

public java.lang.Object divide(java.lang.Number other)

assignElement

protected java.lang.Object assignElement(int which,
                                         java.lang.Object element)
Assumes that the _data array has been expanded suitably. This is used for checking that the element object is of the right type or that it is converted to be so. For lists, this is not important. For homegeous type arrays/vectors, this is more important.

convertElement

protected abstract java.lang.Object convertElement(java.lang.Object element)

targetClass

public abstract java.lang.Class targetClass()
The default class of each element in the list. Used to ensure type-integrity of the array as well as for creating new elements.

length

public int length(int n)
Set the length of the collection, either initializing the array or resetting the length and copying the existing elements appropriately. In other words, if we increase the length, we extend the collection and leave the new elements uninitialized. If we decrease the length, we keep only the values from 0 to the new length -1.

length

public int length(int n,
                  boolean initialize)

apply

public vector apply(java.lang.String method)
             throws java.lang.Throwable
Invoke the method specified by name for each of the elements in the

Different variants are possible using a Database object as an argument or to attach a "non-constructable" (i.e new objects are not created in this) as the first element in the evaluators search path.


findMethod

public java.lang.reflect.Method findMethod(java.lang.String name,
                                           java.lang.Object obj)

apply

public vector apply(Function func)
             throws java.lang.Throwable

copy

public vector copy(boolean all)
            throws java.lang.Throwable
A generic method that copies the contents of the a vector or sub-class using reflectance. The argument all indicates whether we want a shallow copy or deep copy of the array. This should be overridden in the different classes for efficiency reasons.

subset

public java.lang.Object subset(java.lang.Object index,
                               boolean keepStructure)
General method to compute the subset, usually called from the interactive language via expressions of the form x[[1]], x[y,2]
Specified by:
subset in interface Subsettable

values

public VariableInt values(int[] indices)
Description copied from interface: VariableInt
Get a Variable consisting of the specified elements.
Specified by:
values in interface VariableInt

assignSubset

public java.lang.Object assignSubset(java.lang.Object index,
                                     java.lang.Object value)
Specified by:
assignSubset in interface AssignableSubset

getName

public java.lang.String getName()
Method for Variable interface.
Specified by:
getName in interface VariableInt

setName

public java.lang.String setName(java.lang.String nm)
Specified by:
setName in interface VariableInt

getDataFrame

public DataFrameInt getDataFrame()

setDataFrame

public DataFrameInt setDataFrame(DataFrameInt fr)

value

public java.lang.Object value(long which)
Description copied from interface: VariableInt
Return the whichth observation.
Specified by:
value in interface VariableInt

numObservations

public long numObservations()
Description copied from interface: VariableInt
Return the length or number of records in this VariableInt.
Specified by:
numObservations in interface VariableInt

values

public VariableInt values(SelectorInt selector)
Description copied from interface: VariableInt
Get a Variable consisting of the specified elements from a selector object.
Specified by:
values in interface VariableInt

createVariable

public VariableInt createVariable()

addValue

public java.lang.Object addValue(java.lang.Object rhs,
                                 boolean inPlace)
Method for operator + overloading.
Specified by:
addValue in interface Addable

subtractValue

public java.lang.Object subtractValue(java.lang.Object rhs,
                                      boolean inPlace)
Method for operator - overloading.
Specified by:
subtractValue in interface Subtractable

multiplyValue

public java.lang.Object multiplyValue(java.lang.Object rhs,
                                      boolean inPlace)
Method for operator * overloading.
Specified by:
multiplyValue in interface Multiplicable

divideValue

public java.lang.Object divideValue(java.lang.Object rhs,
                                    boolean inPlace)
Method for operator / overloading.
Specified by:
divideValue in interface Divisable

mathOperation

public java.lang.Object mathOperation(java.lang.Object rhs,
                                      boolean inPlace,
                                      int op)
General work-horse method for doing mathematical operations. Dispatches to the appropriate method based on the class of rhs.
Parameters:
rhs - right hand side of the binary operation that can be a number or another vector. Other types are currently rejected.
inPlace - whether to copy the vector and do the operations on the copy or to change the values in this instance.
op - value indicating which mathematical operation to perform. See MathOperable

mathOperation

public vector mathOperation(double v,
                            int op)
Iterate over the elements of this vector, performing the mathematical operation identified by op given the right hand side of the operation as v

elementMathOp

protected java.lang.Object elementMathOp(java.lang.Object el,
                                         double v,
                                         int op)
Internal method for performing the low-level math operation on the element el and right hand side v given the operation type op
Parameters:
el - element of this vector which is the first element of the binary mathematical operation.
v - second term in binary mathematical operation
op - type of mathematical operation to perform.

createElement

public java.lang.Object createElement(double orig)
Create a new element to be added to this vector using the default class of the elements. Works only for number-based vectors.

createElement

public java.lang.Object createElement(double orig,
                                      java.lang.Object el)
Create a new element for the vector using the first argument as the value and the second argument as a template which should be mimiced, if possible. There are problems with this obviously for non-number based vectors, e.g. character.

mathOperation

public java.lang.Object mathOperation(vector v,
                                      int op)
General method for perform a mathematical operation with this object as the left hand side and the first argument v as the right hand side. The particular operation is specified as a symbolic constant op. See MathOperable.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

elementToString

public java.lang.String elementToString(java.lang.Object el)

separator

public java.lang.String separator()

addElement

public int addElement(java.lang.Object el)

add

public void add(double value,
                int which)
Specified by:
add in interface VariableInt

add

public void add(java.lang.Object value,
                int which)
Specified by:
add in interface VariableInt

read

public int read(java.io.InputStream stream)

read

public int read(java.io.Reader stream)
Specified by:
read in interface VariableInt