com.rubecula.jquantity
Class Dimensions

java.lang.Object
  |
  +--com.rubecula.jquantity.Dimensions

public class Dimensions
extends java.lang.Object

The public class Dimensions represents pure dimensional information - no scaling or other information.

This class needs work.

Version:
$Revision: 1.1 $
Author:
Robin Hillyard

Constructor Summary
protected Dimensions()
          Empty constructor for Dimensions
protected Dimensions(Dimensions that)
           
protected Dimensions(int dimension)
           
protected Dimensions(long[] dimensions)
          General constructor for Dimensions
 
Method Summary
 boolean equals(Dimensions other)
          Tests whether the dimensions are actually equal.
(package private)  long GCD(long a, long b)
           
static int GetDimensionFromHashCode(int hashCode, int index)
           
static Dimensions GetDimensionsFromHashCode(int hashCode)
           
 int hashCode()
          This method generates a hash code of up to 30-bits for this object.
(package private)  Dimensions intersect(Dimensions that)
          Method to intersect two dimensions objects.
 boolean isEqual(Dimensions other)
          Return true if the Dimensions are equivalent.
(package private)  boolean isNumber()
           
static void main(java.lang.String[] args)
           
(package private)  Dimensions minus()
           
(package private)  int norm()
           
(package private)  void normalize()
           
(package private)  Dimensions productScalar(Rational power)
           
(package private)  Dimensions scale(int factor)
           
(package private)  Dimensions sum(Dimensions that)
           
 java.lang.String toString()
           
(package private)  java.lang.String toString(int index)
          Method to yield a string representation of the index(th) dimension (or null if dimension 0).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Dimensions

protected Dimensions(long[] dimensions)
              throws JQuantityException
General constructor for Dimensions

Parameters:
dimensions - an array of dimension values in the order defined by: the first element is the divisor; followed by dimensions in length,mass,time, etc.
Throws:
JQuantityException

Dimensions

protected Dimensions()
Empty constructor for Dimensions


Dimensions

protected Dimensions(int dimension)

Dimensions

protected Dimensions(Dimensions that)
Method Detail

productScalar

final Dimensions productScalar(Rational power)

scale

final Dimensions scale(int factor)

sum

final Dimensions sum(Dimensions that)

minus

final Dimensions minus()

isNumber

final boolean isNumber()

hashCode

public final int hashCode()
This method generates a hash code of up to 30-bits for this object. Each element of dimensions is represented 2s-complement in either four bits (elements 1-2), three bits (elements 0, 3-7), or two bits (elements 8-9). Element 0 is the left-most. If there are more than 10 elements, or if any element cannot fit, the value 0 (all zeros) is returned.

Overrides:
hashCode in class java.lang.Object
Returns:
the hash code for this object.

GetDimensionFromHashCode

public static int GetDimensionFromHashCode(int hashCode,
                                           int index)

GetDimensionsFromHashCode

public static Dimensions GetDimensionsFromHashCode(int hashCode)
                                            throws JQuantityException
JQuantityException

normalize

final void normalize()

equals

public boolean equals(Dimensions other)
Tests whether the dimensions are actually equal. This isn't a very useful test since it's equivalence that we really care about. See isEqual(Dimensions)

Parameters:
other - Dimensions: the dimensions to compare with.
Returns:
boolean: true if the this and other are equal.

isEqual

public boolean isEqual(Dimensions other)
Return true if the Dimensions are equivalent.

Parameters:
other - Dimensions: the dimensions to comare with.
Returns:
boolean: true if this and other are equal.

toString

final java.lang.String toString(int index)
                         throws JQuantityException
Method to yield a string representation of the index(th) dimension (or null if dimension 0).

Parameters:
index - the position of the dimension where index >= 1.
Returns:
a string of the form "number" or "number/number".
Throws:
JQuantityException

toString

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

GCD

final long GCD(long a,
               long b)
        throws JQuantityException
JQuantityException

intersect

final Dimensions intersect(Dimensions that)
Method to intersect two dimensions objects. Intersection is defined thus: for each dimension, the smaller of the values for this and that; if either this or that has a zero for a dimension, then the result will have a zero

Parameters:
that - the intersecting object.
Returns:
the intersection of the two dimensions objects.

norm

final int norm()

main

public static void main(java.lang.String[] args)