com.hedgehog.utility
Class TripleInteger

java.lang.Object
  extended by com.hedgehog.HObject
      extended by com.hedgehog.utility.TripleInteger
All Implemented Interfaces:
java.lang.Comparable, java.util.Comparator

public class TripleInteger
extends HObject
implements java.util.Comparator, java.lang.Comparable

Title: TripleInteger - a triple specifically for fundamental type int.

Description: Stores a triple of ints. Triple specifically for type int, since it is so frequently used it saves repeatedly having to work through HInteger.

Copyright: Copyright (c) Hedgehog Software 2007-2009.

Company: Hedgehog Software

Since:
1.0
Version:
1.1

Field Summary
protected  int mp
          Triple value p.
protected  int mq
          Triple value q.
protected  int mr
          Triple value r.
 
Fields inherited from class com.hedgehog.HObject
mID, mName
 
Constructor Summary
TripleInteger()
          Default constructor.
TripleInteger(int p, int q, int r)
          Constructor.
TripleInteger(int p, int q, int r, boolean sortedIncreasing)
          Constructor.
TripleInteger(TripleInteger object)
          Copy constructor.
 
Method Summary
 int compare(java.lang.Object obj1, java.lang.Object obj2)
          Overrides the Comparator.compare() method.
 int compareTo(java.lang.Object obj)
          Overrides the Comparable.compareTo() method.
 java.util.Vector<PairInteger> cyclicPairs()
          Returns a vector of cyclic pairs; ie (p,q), (q,r) and (r,p).
 boolean equals(java.lang.Object object)
          Compares the specified object to this object.
 int getP()
          Returns value p.
 int getQ()
          Returns value q.
 int getR()
          Returns value r.
 int hashCode()
          Returns the hash code for this triple; ie:
 int intermediateValue()
          Returns the intermediate value.
 boolean isDecreasingSequence(boolean useEquality)
          Tests whether or not this triple's values form a decreasing sequence.
 boolean isElement(int v)
          Tests whether or not the specified value is an element of this triple.
 boolean isIncreasingSequence(boolean useEquality)
          Tests whether or not this triple's values form an increasing sequence.
 boolean isSameSet(TripleInteger tri)
          Tests whether or not the specified triple hasa the same integer set as this triple, even though the ordering may differ.
 boolean isSameTriple(int p, int q, int r)
          Tests whether or not the specified triple values are identical to this triple.
 boolean isSameTriple(TripleInteger triple)
          Tests whether or not the specified triple object has identical values to this triple.
 boolean isSameTripleValues()
          Tests whether or not all values of this triple are equivalent.
 boolean isSorted(boolean increasingOrder)
          Tests whether or not this triple's values are sorted.
 int maxValue()
          Returns the maximum value.
 int minValue()
          Returns the minimum value.
 int other(int v0, int v1)
          Returns the other triple value not equal to the specified triple values.
 java.util.Vector<HInteger> others(int v)
          Returns the other triple values not equal to the specified triple value.
 void reverse()
          Reverses the values of this triple (p,q,r) so that the triple becomes (r,q,p), noting that q remains unaltered.
 boolean sameCyclicSequence(TripleInteger triple, boolean bothDirections)
          Tests whether or not the specified triple has a cyclic sequence that matches this triple.
 void set(int new_p, int new_q, int new_r)
          Sets all 3 values of this triple.
 void setP(int new_p)
          Assigns a new value to p.
 void setQ(int new_q)
          Assigns a new value to q.
 void setR(int new_r)
          Assigns a new value to r.
 void sort(boolean increasingOrder)
          Orders this triple in either an increasing or decreasing sequence.
 java.lang.String toString()
          A String representation of this TripleInteger object.
 
Methods inherited from class com.hedgehog.HObject
clone, copy, getID, getName, hasID, hasName, setID, setName
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

mp

protected int mp
Triple value p.


mq

protected int mq
Triple value q.


mr

protected int mr
Triple value r.

Constructor Detail

TripleInteger

public TripleInteger()
Default constructor. Sets all triple objects to 0.


TripleInteger

public TripleInteger(int p,
                     int q,
                     int r)
Constructor. Sets the (p,q,r) triple to the specified values.

Parameters:
p - Triple value p.
q - Triple value q.
r - Triple value r;

TripleInteger

public TripleInteger(int p,
                     int q,
                     int r,
                     boolean sortedIncreasing)
Constructor. Sets the (p,q,r) triple to the specified sorted values.

Parameters:
p - Triple value p.
q - Triple value q.
r - Triple value r;
sortedIncreasing - Specifies whether the triple is to be sorted in increasing (true) order or decreasing (false) order.

TripleInteger

public TripleInteger(TripleInteger object)
Copy constructor.

Parameters:
object - Object to copy.
Method Detail

getP

public int getP()
Returns value p.

Returns:
Value p.

getQ

public int getQ()
Returns value q.

Returns:
Value q.

getR

public int getR()
Returns value r.

Returns:
Value r.

compare

public int compare(java.lang.Object obj1,
                   java.lang.Object obj2)
Overrides the Comparator.compare() method. An object is assumed to be less than another object if any of the triple values of obj1 are less than obj2, and similarly for >.

Specified by:
compare in interface java.util.Comparator
Overrides:
compare in class HObject
Parameters:
obj1 - Object 1.
obj2 - Object 2.
Returns:
0 if obj1==obj2, -1 if obj1obj2.

compareTo

public int compareTo(java.lang.Object obj)
Overrides the Comparable.compareTo() method.

Specified by:
compareTo in interface java.lang.Comparable
Overrides:
compareTo in class HObject
Parameters:
obj - Object to compare against this object.
Returns:
0 if this==obj, -1 if thisobj.

equals

public boolean equals(java.lang.Object object)
Compares the specified object to this object. Compares the (p,q,r) triples of both objects and they must match identically for the objects to be equal.

Specified by:
equals in interface java.util.Comparator
Overrides:
equals in class HObject
Parameters:
object - Object to compare against this object.
Returns:
Logical-true if the specified object is equal to this object.

hashCode

public int hashCode()
Returns the hash code for this triple; ie:
        long bits = (long)mp;
        bits ^= mq * 31;
        bits ^= mr * 31;
        long hash = bits ^ (bits>>32);
        return (int)hash;
 

Overrides:
hashCode in class HObject
Returns:
This triple's hash code.

toString

public java.lang.String toString()
A String representation of this TripleInteger object.

Overrides:
toString in class java.lang.Object
Returns:
A String representation of this TripleInteger object.

setP

public void setP(int new_p)
Assigns a new value to p.

Parameters:
new_p - New p value.

setQ

public void setQ(int new_q)
Assigns a new value to q.

Parameters:
new_q - New q value.

setR

public void setR(int new_r)
Assigns a new value to r.

Parameters:
new_r - New r value.

set

public void set(int new_p,
                int new_q,
                int new_r)
Sets all 3 values of this triple.

Parameters:
new_p - New p value.
new_q - New q value.
new_r - New r value.

reverse

public void reverse()
Reverses the values of this triple (p,q,r) so that the triple becomes (r,q,p), noting that q remains unaltered.


sameCyclicSequence

public boolean sameCyclicSequence(TripleInteger triple,
                                  boolean bothDirections)
Tests whether or not the specified triple has a cyclic sequence that matches this triple. If this triple is denoted by t0(p,q,r) and the specified triple by t1(p',q',r') then it compares t0(p,q,r) against the 3 unique combinations of t1 of (p',q',r'), (r',p',q') and (q',r',p').

Parameters:
triple - Triple to compare this triple.
bothDirections - Specfies whether or not both directions of the specified triple are to be compared. If true then triple is reversed and the cyclic comparison repeated.
Returns:
Logical-true if the specified triple has a cyclic sequence that matches this triple.

minValue

public int minValue()
Returns the minimum value.

Returns:
The minimum value.

maxValue

public int maxValue()
Returns the maximum value.

Returns:
The maximum value.

intermediateValue

public int intermediateValue()
Returns the intermediate value.

Returns:
The intermediate value.

sort

public void sort(boolean increasingOrder)
Orders this triple in either an increasing or decreasing sequence.

Parameters:
increasingOrder - Specifies whether the ordeing should be increasing (true) or decreasing (false).

isSorted

public boolean isSorted(boolean increasingOrder)
Tests whether or not this triple's values are sorted.

Parameters:
increasingOrder - Specifies whether the values to be tested in increasing (true) order or decreasing (false) order.
Returns:
Logical-true if this triple's values are sorted, else logical-false.

cyclicPairs

public java.util.Vector<PairInteger> cyclicPairs()
Returns a vector of cyclic pairs; ie (p,q), (q,r) and (r,p).

Returns:
Vector of unique cyclic pairs.

other

public int other(int v0,
                 int v1)
          throws java.lang.IllegalArgumentException
Returns the other triple value not equal to the specified triple values.

Parameters:
v0 - Element value.
v1 - Element value.
Returns:
Triple vaue not equal to v0 and v1.
Throws:
java.lang.IllegalArgumentException - Thrown if v0 or v1 is not an element value of this triple.

others

public java.util.Vector<HInteger> others(int v)
                                  throws java.lang.IllegalArgumentException
Returns the other triple values not equal to the specified triple value.

Parameters:
v - Triple element value.
Returns:
Vector of other triple values not equal to v.
Throws:
java.lang.IllegalArgumentException - Thrown if v is not an element value of this triple.

isElement

public boolean isElement(int v)
Tests whether or not the specified value is an element of this triple.

Parameters:
v - Value to test.
Returns:
Logical-true if v is an element vaue of this triple, else logical-false.

isSameTriple

public boolean isSameTriple(int p,
                            int q,
                            int r)
Tests whether or not the specified triple values are identical to this triple.

Parameters:
p - Triple value p.
q - Triple value q.
r - Triple value r.
Returns:
Logical-true if the specified triple (p,q,r) is identical to this triple, else logical-false.

isSameTriple

public boolean isSameTriple(TripleInteger triple)
Tests whether or not the specified triple object has identical values to this triple.

Parameters:
triple - Triple to compare.
Returns:
Logical-true if the specified triple is identical to this triple, else logical-false.

isSameSet

public boolean isSameSet(TripleInteger tri)
Tests whether or not the specified triple hasa the same integer set as this triple, even though the ordering may differ.

Parameters:
tri - Other triple.
Returns:
Logical-true if the specified triple has the same integer set as this triple, else logical-false.

isSameTripleValues

public boolean isSameTripleValues()
Tests whether or not all values of this triple are equivalent.

Returns:
Logical-true if all values of this triple are equivalent, else logical-false.

isIncreasingSequence

public boolean isIncreasingSequence(boolean useEquality)
Tests whether or not this triple's values form an increasing sequence.

Parameters:
useEquality - Specifies whether or not to use the >= operator or just > when comparing the values.
Returns:
Logical-true if this triple's values form an increasing sequence, else logical-false.

isDecreasingSequence

public boolean isDecreasingSequence(boolean useEquality)
Tests whether or not this triple's values form a decreasing sequence.

Parameters:
useEquality - Specifies whether or not to use the <= operator or just < when comparing the values.
Returns:
Logical-true if this triple's values form an decreasing sequence, else logical-false.