|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.columbia.cs.coms4701.geometry.AbstractVector<T>
public abstract class AbstractVector<T extends java.lang.Number>
Abstract base class for n-dimensional vectors in a module (i.e. commutative ring, e.g. doubles, integers, complex numbers)
This base class supplies most of the essential functionality; however, subclasses must implement the #add and #multiply methods, due to annoying "features" of the Number abstract class
Field Summary | |
---|---|
protected java.util.ArrayList<T> |
components
|
protected static int |
PRIME
|
Fields inherited from interface edu.columbia.cs.coms4701.geometry.GeometricVector |
---|
X_DIM, Y_DIM, Z_DIM |
Constructor Summary | |
---|---|
AbstractVector(int dimension)
Constructs a new vector of the given dimension. |
Method Summary | |
---|---|
abstract GeometricVector<T> |
add(GeometricVector<T> theVector)
add returns a *new* vector, equal to the vector sum of this vector and the argument. |
protected void |
checkDimension(int theDimension)
Used to check the legality of a dimension argument. |
protected void |
checkEqualOrSmallerDimensionVector(GeometricVector<T> theVector)
Used to check the legality of a vector argument. |
boolean |
equals(java.lang.Object obj)
Two vectors are considered equal if they have the same dimension and corresponding components in each dimension are equal. |
T |
getComponent(int theDimension)
Returns the component in the specified dimension. |
abstract T[] |
getComponents()
Returns the components as an array |
int |
getDimension()
Return the dimension of this vector. |
double |
getLength()
Returns the length (norm) of this vector as a double. |
int |
hashCode()
Implementing classes should override hashCode() to synchronize with equals() |
java.util.Iterator<T> |
iterator()
Returns an iterator over the components of the vector. |
abstract GeometricVector<T> |
multiply(T theScalar)
multiply returns a *new* vector, equal to the scalar multiple of this vector and the argument. |
java.lang.String |
toString()
Implementing classes should override toString() to produce a simple string representation, e.g. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected static int PRIME
protected java.util.ArrayList<T extends java.lang.Number> components
Constructor Detail |
---|
public AbstractVector(int dimension)
Subclasses *must* override this constructor to initialize the contents of the components (e.g. to zero).
Subclasses must also provide a variable-length argument constructor that initializes components to provided values
dimension
- Method Detail |
---|
public abstract GeometricVector<T> add(GeometricVector<T> theVector)
Performs a component-by-component addition
add
in interface GeometricVector<T extends java.lang.Number>
theVector
- the vector to add, which must be of equal or lesser dimension
public abstract GeometricVector<T> multiply(T theScalar)
Performs a component-by-component scalar multiplication
multiply
in interface GeometricVector<T extends java.lang.Number>
theScalar
- the scalar to multiply by (may be < 1, or indeed < 0)public java.util.Iterator<T> iterator()
iterator
in interface GeometricVector<T extends java.lang.Number>
iterator
in interface java.lang.Iterable<T extends java.lang.Number>
public boolean equals(java.lang.Object obj)
equals
in interface GeometricVector<T extends java.lang.Number>
equals
in class java.lang.Object
obj
-
public int hashCode()
GeometricVector
hashCode
in interface GeometricVector<T extends java.lang.Number>
hashCode
in class java.lang.Object
public double getLength()
getLength
in interface GeometricVector<T extends java.lang.Number>
public int getDimension()
getDimension
in interface GeometricVector<T extends java.lang.Number>
public T getComponent(int theDimension)
getComponent
in interface GeometricVector<T extends java.lang.Number>
theDimension
- specifies which component to retrievepublic abstract T[] getComponents()
getComponents
in interface GeometricVector<T extends java.lang.Number>
protected void checkDimension(int theDimension)
java.lang.IllegalArgumentException
protected void checkEqualOrSmallerDimensionVector(GeometricVector<T> theVector)
java.lang.IllegalArgumentException
public java.lang.String toString()
GeometricVector
toString
in interface GeometricVector<T extends java.lang.Number>
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |