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

java.lang.Object
  extended by org.openmali.vecmath2.TupleNi<T>
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
Tuple2i, Tuple3i, Tuple4i

public abstract class TupleNi<T extends TupleNi<T>>
extends java.lang.Object
implements java.io.Externalizable

A simple N-dimensional tuple implementation. Inspired by Kenji Hiranabe's implementation

See Also:
Serialized Form

Field Summary
protected  boolean[] isDirty
           
protected  int N
           
protected  int roTrick
           
protected  int[] values
           
 
Constructor Summary
protected TupleNi(boolean readOnly, int n)
          Creates a new TupleNi instance.
protected TupleNi(boolean readOnly, int[] values, boolean[] isDirty, int n, boolean copy)
          Creates a new TupleNi instance.
protected TupleNi(boolean readOnly, int[] values, int n)
          Creates a new TupleNf instance.
protected TupleNi(boolean readOnly, TupleNi<?> that)
          Creates a new TupleNi instance.
  TupleNi(int n)
          Creates a new TupleNi instance.
  TupleNi(int[] values, int n)
          Creates a new TupleNi instance.
  TupleNi(TupleNi<?> that)
          Creates a new TupleNi instance.
 
Method Summary
 T absolute()
          Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.
 T absolute(T tuple)
          Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.
 T add(T tuple2)
          Sets the value of this tuple to the vector sum of itself and tuple t1.
 T add(T tuple1, T tuple2)
          Sets the value of this tuple to the vector sum of tuples t1 and t2.
abstract  T asReadOnly()
           
 T clamp(int min, int max)
          Clamps this tuple to the range [min, max].
 T clamp(int min, int max, T tuple)
          Clamps the tuple parameter to the range [min, max] and places the values into this tuple.
 T clampMax(int max)
          Clamps the maximum value of this tuple to the max parameter.
 T clampMax(int max, T tuple)
          Clamps the maximum value of the tuple parameter to the max parameter and places the values into this tuple.
 T clampMin(int min)
          Clamps the minimum value of this tuple to the min parameter.
 T clampMin(int min, T tuple)
          Clamps the minimum value of the tuple parameter to the min parameter and places the values into this tuple.
 int deserialize(int pos, byte[] buffer)
          Deserializes this instanc'es data from the byte array.
 boolean equals(java.lang.Object tuple2)
          Returns true if the Object t1 is of type Tuple3f and all of the data members of t1 are equal to the corresponding data members in this Tuple2f.
 boolean equals(T t2)
          Returns true if all of the data members of GVector vector1 are equal to the corresponding data members in this GVector.
 T get(int[] buffer)
          Writes all values of this Tuple to the specified buffer.
 T get(int[] buffer, int offset)
          Writes all values of this Tuple to the specified buffer.
 T get(T buffer)
          Writes all values of this Tuple to the specified buffer Tuple.
abstract  T getReadOnly()
           
protected  int getSerializationBufferSize()
           
 int getSize()
           
 int getValue(int i)
           
abstract  int hashCode()
          Returns a hash number based on the data values in this object.
 boolean isDirty()
           
 boolean isReadOnly()
           
 T negate()
          Negates the value of this vector in place.
 T negate(T tuple)
          Sets the value of this tuple to the negation of tuple that.
 void readExternal(java.io.ObjectInput in)
           
 T scale(int factor)
          Sets the value of this tuple to the scalar multiplication of itself.
 T scale(int factor, T tuple)
          Sets the value of this tuple to the scalar multiplication of tuple t1.
 T scaleAdd(int factor, T tuple2)
          Sets the value of this tuple to the scalar multiplication of itself and then adds tuple t1 (this = s*this + t1).
 T scaleAdd(int factor, T tuple1, T tuple2)
          Sets the value of this tuple to the scalar multiplication of tuple t1 and then adds tuple t2 (this = s*t1 + t2).
 int serialize(int pos, byte[] buffer)
          Serializes this instanc'es data into the byte array.
 T set(int[] values)
          Sets all values of this Tuple to the specified ones.
 T set(int[] values, int offset)
          Sets all values of this Tuple to the specified ones.
 T set(T tuple)
          Sets all three values of this Tuple to the specified ones.
 boolean setClean()
          Marks this tuple non-dirty.
 T setValue(int i, int v)
          Sets the value of the i-th element of this tuple.
 T setZero()
          Sets all components to zero.
 T sub(T tuple2)
          Sets the value of this tuple to the vector difference of itself and tuple t1 (this = this - t1).
 T sub(T tuple1, T tuple2)
          Sets the value of this tuple to the vector difference of tuple t1 and t2 (this = t1 - t2).
abstract  java.lang.String toString()
          Returns a string that contains the values of this Tuple2f.
 void writeExternal(java.io.ObjectOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

N

protected final int N

values

protected final int[] values

roTrick

protected final int roTrick

isDirty

protected final boolean[] isDirty
Constructor Detail

TupleNi

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

Parameters:
readOnly -
n - the number of elements

TupleNi

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

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

TupleNi

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

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

TupleNi

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

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

TupleNi

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

Parameters:
n - the number of elements

TupleNi

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

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

TupleNi

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

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

isReadOnly

public final boolean isReadOnly()
Returns:
Is this tuple a read-only one?

setClean

public final boolean setClean()
Marks this tuple non-dirty. Any value-manipulation will mark it dirty again.

Returns:
the old value

isDirty

public final boolean isDirty()
Returns:
This tuple's dirty-flag

getSize

public final int getSize()
Returns:
this Tuple's size().

setValue

public final T setValue(int i,
                        int v)
Sets the value of the i-th element of this tuple.

Parameters:
i -
v -
Returns:
itself

getValue

public final int getValue(int i)
Returns:
the value of the i-th element of this tuple.

set

public final T set(int[] values,
                   int offset)
Sets all values of this Tuple to the specified ones.

Parameters:
values - the values array (must be at least size 3)
offset - the offset int the (source) values array
Returns:
itself

set

public final T set(int[] values)
Sets all values of this Tuple to the specified ones.

Parameters:
values - the values array (must be at least size 3)
Returns:
itself

set

public final T set(T tuple)
Sets all three values of this Tuple to the specified ones.

Parameters:
tuple - the tuple to be copied
Returns:
itself

get

public final T get(int[] buffer,
                   int offset)
Writes all values of this Tuple to the specified buffer.

Parameters:
buffer - the buffer array to write the values to
offset - the offset in the (target) buffer array
Returns:
itself

get

public final T get(int[] buffer)
Writes all values of this Tuple to the specified buffer.

Parameters:
buffer - the buffer array to write the values to
Returns:
itself

get

public final T get(T buffer)
Writes all values of this Tuple to the specified buffer Tuple.

Parameters:
buffer - the buffer Tuple to write the values to
Returns:
itself

setZero

public final T setZero()
Sets all components to zero.

Returns:
itself

negate

public final T negate(T tuple)
Sets the value of this tuple to the negation of tuple that.

Parameters:
tuple - the source vector
Returns:
itself

negate

public final T negate()
Negates the value of this vector in place.

Returns:
itself

absolute

public final T absolute()
Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.

Returns:
itself

absolute

public final T absolute(T tuple)
Sets each component of the tuple parameter to its absolute value and places the modified values into this tuple.

Parameters:
tuple - the source tuple, which will not be modified
Returns:
itself

add

public final T add(T tuple1,
                   T tuple2)
Sets the value of this tuple to the vector sum of tuples t1 and t2.

Parameters:
tuple1 - the first tuple
tuple2 - the second tuple
Returns:
itself

add

public final T add(T tuple2)
Sets the value of this tuple to the vector sum of itself and tuple t1.

Parameters:
tuple2 - the other tuple
Returns:
itself

sub

public final T sub(T tuple1,
                   T tuple2)
Sets the value of this tuple to the vector difference of tuple t1 and t2 (this = t1 - t2).

Parameters:
tuple1 - the first tuple
tuple2 - the second tuple
Returns:
itself

sub

public final T sub(T tuple2)
Sets the value of this tuple to the vector difference of itself and tuple t1 (this = this - t1).

Parameters:
tuple2 - the other tuple
Returns:
itself

scale

public final T scale(int factor,
                     T tuple)
Sets the value of this tuple to the scalar multiplication of tuple t1.

Parameters:
factor - the scalar value
tuple - the source tuple
Returns:
itself

scale

public final T scale(int factor)
Sets the value of this tuple to the scalar multiplication of itself.

Parameters:
factor - the scalar value
Returns:
itself

scaleAdd

public final T scaleAdd(int factor,
                        T tuple1,
                        T tuple2)
Sets the value of this tuple to the scalar multiplication of tuple t1 and then adds tuple t2 (this = s*t1 + t2).

Parameters:
factor - the scalar value
tuple1 - the tuple to be multipled
tuple2 - the tuple to be added
Returns:
itself

scaleAdd

public final T scaleAdd(int factor,
                        T tuple2)
Sets the value of this tuple to the scalar multiplication of itself and then adds tuple t1 (this = s*this + t1).

Parameters:
factor - the scalar value
tuple2 - the tuple to be added
Returns:
itself

clampMin

public final T clampMin(int min)
Clamps the minimum value of this tuple to the min parameter.

Parameters:
min - the lowest value in this tuple after clamping
Returns:
itself

clampMax

public final T clampMax(int max)
Clamps the maximum value of this tuple to the max parameter.

Parameters:
max - the highest value in the tuple after clamping
Returns:
itself

clamp

public final T clamp(int min,
                     int max)
Clamps this tuple to the range [min, max].

Parameters:
min - the lowest value in this tuple after clamping
max - the highest value in this tuple after clamping
Returns:
itself

clamp

public final T clamp(int min,
                     int max,
                     T tuple)
Clamps the tuple parameter to the range [min, max] and places the values into this tuple.

Parameters:
min - the lowest value in the tuple after clamping
max - the highest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

clampMin

public final T clampMin(int min,
                        T tuple)
Clamps the minimum value of the tuple parameter to the min parameter and places the values into this tuple.

Parameters:
min - the lowest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

clampMax

public final T clampMax(int max,
                        T tuple)
Clamps the maximum value of the tuple parameter to the max parameter and places the values into this tuple.

Parameters:
max - the highest value in the tuple after clamping
tuple - the source tuple, which will not be modified
Returns:
itself

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

hashCode

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

Overrides:
hashCode in class java.lang.Object

equals

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

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

equals

public boolean equals(java.lang.Object tuple2)
Returns true if the Object t1 is of type Tuple3f and all of the data members of t1 are equal to the corresponding data members in this Tuple2f.

Overrides:
equals in class java.lang.Object
Parameters:
tuple2 - the Object with which the comparison is made
Returns:
true or false

toString

public abstract java.lang.String toString()
Returns a string that contains the values of this Tuple2f. The form is (x, y).

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
Specified by:
writeExternal in interface java.io.Externalizable
Throws:
java.io.IOException

readExternal

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