com.rubecula.jquantity
Class OneMatrix

java.lang.Object
  extended bycom.rubecula.util.Item
      extended bycom.rubecula.jquantity.Compound
          extended bycom.rubecula.jquantity.OneMatrix
All Implemented Interfaces:
Auditable, java.lang.Cloneable, java.lang.Comparable, CompoundModel, Divisible, Identifiable, Millable, Mutable, Nameable, Normalizable, Presentable, java.io.Serializable
Direct Known Subclasses:
Row

public abstract class OneMatrix
extends Compound

Class to model a fixed-size one-dimensional matrix (normally called a Vector) but given the name OneMatrix to avoid confusion with Vector.

Since:
V_0_4
Version:
$Revision: 1.2 $
Author:
Robin Hillyard
See Also:
Serialized Form

Field Summary
private  BaseNumber[] _Elements
           
 
Fields inherited from class com.rubecula.jquantity.Compound
 
Fields inherited from class com.rubecula.util.Item
JQUANTITY_TEST
 
Constructor Summary
OneMatrix(BaseNumber[] elements)
           
OneMatrix(int length)
           
 
Method Summary
 Divisible factored(double factor)
          Method to yield the quotient of this divided by factor, and return it as the result.
 int[] getDimensions()
          Method to get the maximumum indices for each dimension.
 BaseNumber getElement(int i)
          Method to get the ith element of this OneMatrix.
 BaseNumber getElement(int[] indices)
          Method to get the value of the element specified by the indices given.
 Divisible inverse()
          Method to yield the reciprocal of this and return it as the result.
 boolean isNormal()
          Method to determine if this instance is already normalized.
 int length()
           
 void normalize()
          MUTATING instance method to normalize this object.
 Divisible quotient(BaseNumber divisor)
          Method to divide this by divisor and return the quotient as the result.
 void setElement(int[] indices, BaseNumber element)
          Method to set the value of the element specified by the indices given.
 
Methods inherited from class com.rubecula.jquantity.Compound
audit, getIdentifier, isMutable, main, makePresentableInstance, present, setConstant, setIdentifier
 
Methods inherited from class com.rubecula.util.Item
audit, audit, compareTo, Debug, getClassNameShort, getType, IsDebug, present, SetDebug, test, test, toString, Wrap
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.rubecula.util.Auditable
audit, audit
 

Field Detail

_Elements

private final BaseNumber[] _Elements
Constructor Detail

OneMatrix

public OneMatrix(BaseNumber[] elements)
Parameters:
elements - the elements which will comprise this OneMatrix.

OneMatrix

public OneMatrix(int length)
Parameters:
length - the number of elements to be contained in this OneMatrix.
Method Detail

getElement

public BaseNumber getElement(int[] indices)
Description copied from interface: CompoundModel
Method to get the value of the element specified by the indices given.

Parameters:
indices - an array of integers giving the indices in the 0th, 1st, ... (n-1)th dimensions of the Compound, respectively.
Returns:
the value of element [i,j,k,...] where the i,j,k,... are given in the array indices.

getDimensions

public int[] getDimensions()
Description copied from interface: CompoundModel
Method to get the maximumum indices for each dimension.

Returns:
an array of integers giving the max value for the 0th, 1st, ... (n-1)th dimensions of the Compound, respectively.

length

public int length()

setElement

public void setElement(int[] indices,
                       BaseNumber element)
Description copied from interface: CompoundModel
Method to set the value of the element specified by the indices given.

Parameters:
indices - an array of integers giving the indices in the 0th, 1st, ... (n-1)th dimensions of the Compound, respectively.

inverse

public Divisible inverse()
Description copied from interface: Divisible
Method to yield the reciprocal of this and return it as the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class.

Returns:
the reciprocal of this.

quotient

public Divisible quotient(BaseNumber divisor)
                   throws InvalidOperandException
Description copied from interface: Divisible
Method to divide this by divisor and return the quotient as the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class.
NOTE: This method is dangerous as it is possible that the divisor is a non-pure number such as a Value. Instead of using this method, it is better to use inverse and then product.

Parameters:
divisor - the number to multiply by this.
Returns:
the quotient of this divided by divisor.
Throws:
InvalidOperandException - operands are not compatible for the quotient operation. // TODO Fix it so that this method is safe (see above).

factored

public Divisible factored(double factor)
Description copied from interface: Divisible
Method to yield the quotient of this divided by factor, and return it as the result.
NOTE: it is a requirement of this method that the class of the result is the same as the class of this so that the result can be safely cast to the original class.

Parameters:
factor - the scale factor.
Returns:
the quotient of this divided by factor.

normalize

public void normalize()
Description copied from interface: Normalizable
MUTATING instance method to normalize this object. Repeated applications of this method on an object should have no effect. The effective value of this object before and after normalization must be the same.


isNormal

public boolean isNormal()
Description copied from interface: Normalizable
Method to determine if this instance is already normalized.

Returns:
true if this object is already normalized.

getElement

public BaseNumber getElement(int i)
Method to get the ith element of this OneMatrix.

Parameters:
i - the index of the desired element (0 <= i < length).
Returns:
the value of the ith element.