org.openmali.vecmath2
Class TupleNd<T extends TupleNd<T>>

java.lang.Object
  extended by org.openmali.vecmath2.TupleNd<T>
Type Parameters:
T - the generic parameter for coefficients
Direct Known Subclasses:
Tuple2d, Tuple3d

public abstract class TupleNd<T extends TupleNd<T>>
extends java.lang.Object

This is a base-class for all double tuples like Tuple2d, Tuple3d, VectorNd, etc.


Field Summary
protected  boolean[] isDirty
           
protected  int roTrick
           
protected  double[] values
           
 
Constructor Summary
protected TupleNd(boolean readOnly, double[] values, boolean[] isDirty, int n, boolean copy)
          Creates a new TupleNd instance.
protected TupleNd(boolean readOnly, double[] values, int n)
          Creates a new TupleNd instance.
protected TupleNd(boolean readOnly, int n)
          Creates a new TupleNd instance.
protected TupleNd(boolean readOnly, TupleNd<?> that)
          Creates a new Tuple3d instance.
  TupleNd(double[] values, int n)
          Creates a new TupleNd instance.
  TupleNd(int n)
          Creates a new TupleNd instance.
  TupleNd(TupleNd<?> that)
          Creates a new Tuple3d instance.
 
Method Summary
 T absolute()
          
 T absolute(T tuple)
          
 T add(T tuple2)
          
 T add(T tuple1, T tuple2)
          
 T addValue(int i, double v)
          
abstract  T asReadOnly()
           
 T clamp(double min, double max)
          
 T clamp(double min, double max, T tuple)
          
 T clampMax(double max)
          
 T clampMax(double max, T tuple)
          
 T clampMin(double min)
          
 T clampMin(double min, T tuple)
          
 int deserialize(int pos, byte[] buffer)
          Deserializes this instanc'es data from the byte array.
 T div(double v)
          
 T divValue(int i, double v)
          
 boolean epsilonEquals(T v2, double epsilon)
          
 boolean equals(java.lang.Object o)
          
 boolean equals(T v2)
          Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.
 T fill(double f)
          
 void get(double[] buffer)
          
 void get(TupleNd<?> buffer)
          
abstract  T getReadOnly()
           
protected  int getSerializationBufferSize()
           
 int getSize()
          
 double getValue(int i)
          
 int hashCode()
          Returns a hash number based on the data values in this object.
 void interpolate(T t2, double alpha)
          
 void interpolate(T t1, T t2, double alpha)
          
 boolean isDirty()
          
 boolean isReadOnly()
          
 T mul(double v)
          
 T mulValue(int i, double v)
          
 T negate()
          
 T negate(T tuple)
          
 void readExternal(java.io.ObjectInput in)
           
 T round(int decPlaces)
          
 T round(T tuple, int decPlaces)
          
 T scale(double factor)
          
 T scale(double factor, T tuple)
          
 T scaleAdd(double factor, T tuple2)
          
 T scaleAdd(double factor, T tuple1, T tuple2)
          
 int serialize(int pos, byte[] buffer)
          Serializes this instanc'es data into the byte array.
 T set(double[] values)
          
 T set(TupleNd<?> tuple)
          
 boolean setClean()
          
 T setValue(int i, double v)
          
 T setZero()
          
 T sub(T tuple2)
          
 T sub(T tuple1, T tuple2)
          
 T subValue(int i, double v)
          
 java.lang.String toString()
          Returns a string that contains the values of this Vector.
 void writeExternal(java.io.ObjectOutput out)
           
 java.nio.DoubleBuffer writeToBuffer(java.nio.DoubleBuffer buffer)
          Writes the contents of this tuple to a doubleBuffer.
static java.nio.DoubleBuffer writeToBuffer(TupleNd<?>[] tuples, java.nio.DoubleBuffer buffer)
          Writes the contents of this tuple to a doubleBuffer.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

values

protected final double[] values

roTrick

protected final int roTrick

isDirty

protected final boolean[] isDirty
Constructor Detail

TupleNd

protected TupleNd(boolean readOnly,
                  int n)
Creates a new TupleNd instance.

Parameters:
readOnly -
n - the number of elements

TupleNd

protected TupleNd(boolean readOnly,
                  double[] values,
                  boolean[] isDirty,
                  int n,
                  boolean copy)
Creates a new TupleNd instance.

Parameters:
readOnly -
values - the values array (must be at least size 3)
isDirty - the isDirty-value
n - the number of elements
copy - copy the array?

TupleNd

protected TupleNd(boolean readOnly,
                  double[] values,
                  int n)
Creates a new TupleNd instance.

Parameters:
readOnly -
values - the values array (must be at least size n)
n - the number of elements to copy

TupleNd

protected TupleNd(boolean readOnly,
                  TupleNd<?> that)
Creates a new Tuple3d instance.

Parameters:
readOnly -
that - the TupleNd to copy the values from

TupleNd

public TupleNd(int n)
Creates a new TupleNd instance.

Parameters:
n - the number of elements

TupleNd

public TupleNd(double[] values,
               int n)
Creates a new TupleNd instance.

Parameters:
values - the values array (must be at least size n)
n - the number of elements to copy

TupleNd

public TupleNd(TupleNd<?> that)
Creates a new Tuple3d instance.

Parameters:
that - the TupleNd to copy the values from
Method Detail

isReadOnly

public final boolean isReadOnly()


setClean

public final boolean setClean()


isDirty

public final boolean isDirty()


getSize

public final int getSize()


setValue

public final T setValue(int i,
                        double v)


getValue

public final double getValue(int i)


writeToBuffer

public final java.nio.DoubleBuffer writeToBuffer(java.nio.DoubleBuffer buffer)
Writes the contents of this tuple to a doubleBuffer.
The buffer is automatically cleared (before) and flipped (after).

Parameters:
buffer -

writeToBuffer

public static final java.nio.DoubleBuffer writeToBuffer(TupleNd<?>[] tuples,
                                                        java.nio.DoubleBuffer buffer)
Writes the contents of this tuple to a doubleBuffer.
The buffer is automatically cleared (before) and flipped (after).

Parameters:
buffer -

fill

public final T fill(double f)


addValue

public final T addValue(int i,
                        double v)


subValue

public final T subValue(int i,
                        double v)


mulValue

public final T mulValue(int i,
                        double v)


mul

public final T mul(double v)


divValue

public final T divValue(int i,
                        double v)


div

public final T div(double v)


set

public T set(double[] values)


set

public final T set(TupleNd<?> tuple)


get

public void get(double[] buffer)


get

public final void get(TupleNd<?> buffer)


setZero

public final T setZero()


negate

public final T negate()


negate

public final T negate(T tuple)


absolute

public final T absolute()


absolute

public final T absolute(T tuple)


add

public final T add(T tuple1,
                   T tuple2)


add

public final T add(T tuple2)


sub

public final T sub(T tuple1,
                   T tuple2)


sub

public final T sub(T tuple2)


scale

public final T scale(double factor,
                     T tuple)


scale

public final T scale(double factor)


scaleAdd

public final T scaleAdd(double factor,
                        T tuple1,
                        T tuple2)


scaleAdd

public final T scaleAdd(double factor,
                        T tuple2)


clampMin

public final T clampMin(double min)


clampMax

public final T clampMax(double max)


clamp

public final T clamp(double min,
                     double max)


clamp

public final T clamp(double min,
                     double max,
                     T tuple)


clampMin

public final T clampMin(double min,
                        T tuple)


clampMax

public final T clampMax(double max,
                        T tuple)


round

public final T round(T tuple,
                     int decPlaces)


round

public final T round(int decPlaces)


interpolate

public void interpolate(T t2,
                        double alpha)


interpolate

public final void interpolate(T t1,
                              T t2,
                              double alpha)


asReadOnly

public abstract T asReadOnly()
Returns:
a new instance sharing the values array with this instance. The new instance is read-only. Changes to this instance will be reflected in the new read-only-instance.
See Also:
getReadOnly()

getReadOnly

public abstract T getReadOnly()
Returns:
a single instance sharing the values array with this instance (one unique instance per 'master-instance'). The instance is read-only. Changes to this instance will be reflected in the read-only-instance.
See Also:
asReadOnly()

equals

public boolean equals(T v2)
Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.

Parameters:
v2 - The vector with which the comparison is made.
Returns:
true or false

equals

public boolean equals(java.lang.Object o)

Overrides:
equals in class java.lang.Object

epsilonEquals

public boolean epsilonEquals(T v2,
                             double epsilon)


hashCode

public int hashCode()
Returns a hash number based on the data values in this object. Two different GMatrix objects with identical data values (ie, returns true for equals(GMatrix) ) will return the same hash number. Two objects with different data members may return the same hash value, although this is not likely.

Overrides:
hashCode in class java.lang.Object
Returns:
the integer hash value

toString

public java.lang.String toString()
Returns a string that contains the values of this Vector.

Overrides:
toString in class java.lang.Object
Returns:
the String representation

serialize

public int serialize(int pos,
                     byte[] buffer)
Serializes this instanc'es data into the byte array.

Parameters:
pos -
buffer -
Returns:
the incremented position

deserialize

public int deserialize(int pos,
                       byte[] buffer)
Deserializes this instanc'es data from the byte array.

Parameters:
pos -
buffer -
Returns:
the incremented position

getSerializationBufferSize

protected int getSerializationBufferSize()
Returns:
the necessary size for a serialization byte array.

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Throws:
java.io.IOException
java.lang.ClassNotFoundException