com.rubecula.units
Class Dimensions

java.lang.Object
  extended bycom.rubecula.units.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.

// TODO figure if this class is Mutable or not. // TODO make it implement Comparable and Mutable and Auditable (Arithmetical? - no). // TODO work through the source code ensuring compliance with conventions.

Version:
$Revision: 1.3 $
Author:
Robin Hillyard

Field Summary
private  long[] _Dimensions
          Private instance field consisting of an array of longs in which to store the dimension values.
private static int $MaxHashDims
           
static java.lang.String[] $S_DIM_CODES
          Letter codes for each of the dimensions.
static java.lang.String[] $S_DIM_IDS
          String identifiers for each of the dimensions.
 
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
private static long _gcd(long a, long b)
           
 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)
           
 int getDimensions()
           
static Dimensions GetDimensionsFromHashCode(int hashCode)
           
 Rational getPower(int dimension)
           
 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)
           
private  void show(java.lang.String tag)
           
(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
 

Field Detail

$MaxHashDims

private static final int $MaxHashDims
See Also:
Constant Field Values

_Dimensions

private long[] _Dimensions
Private instance field consisting of an array of longs in which to store the dimension values. The first element is the divisor; the following are the dimensions in length,mass,time, etc. Given that I've finally made this into a separate class I could store the divisor separately - but there's no particular advantage now, other than elegance.


$S_DIM_IDS

public static final java.lang.String[] $S_DIM_IDS
String identifiers for each of the dimensions. The order of these must match the definitions in SiUnit


$S_DIM_CODES

public static final java.lang.String[] $S_DIM_CODES
Letter codes for each of the dimensions. The order of these must match the definitions in SiUnit

Constructor Detail

Dimensions

protected Dimensions(long[] dimensions)
              throws UnitsException
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:
UnitsException

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.

Returns:
the hash code for this object.

GetDimensionFromHashCode

public static int GetDimensionFromHashCode(int hashCode,
                                           int index)

GetDimensionsFromHashCode

public static Dimensions GetDimensionsFromHashCode(int hashCode)
                                            throws UnitsException
Throws:
UnitsException

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 UnitsException
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:
UnitsException

toString

public final java.lang.String toString()

_gcd

private static final long _gcd(long a,
                               long b)

GCD

final long GCD(long a,
               long b)
        throws UnitsException
Throws:
UnitsException

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

show

private void show(java.lang.String tag)

main

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

getDimensions

public int getDimensions()

getPower

public Rational getPower(int dimension)