jjdh API

jjdh.java.math
Class Index2D

java.lang.Object
  extended by jjdh.java.math.Index2D
All Implemented Interfaces:
Serializable, Cloneable, Comparable<Index2D>

public final class Index2D
extends Object
implements Serializable, Cloneable, Comparable<Index2D>

The Class Index2D models a position of the form (row, column) in a 2-dimensional coordinate system.

Version:
02.10.2004
Author:
Dennis Heidsiek
See Also:
Serialized Form

Field Summary
private  int column
          The column of this position.
private  int row
          The row of this position.
private static long serialVersionUID
           
 
Constructor Summary
Index2D()
          Initializes this Position2D with the values (row, column) = (0, 0).
Index2D(int row, int column)
          Initializes this Position2D with the given values.
 
Method Summary
 Object clone()
          Creates and returns a real, deep copy of this object.
 int compareTo(Index2D other)
          Compares some other Position2D with this one for order.
 boolean equals(Object obj)
          Indicates wheather some other Position2D/code> is "equal to" this one.
 int getColumn()
          Returns the Column of this position.
 Index2D getDeferred(int changeRow, int changeColumn)
          Creates and returns a new Position2D which is deferred by the given values in relation to this Position2D.
 int getRow()
          Returns the Row of this position.
 int hashCode()
          Calculates a hash code value for this Position2D.
static int hashCode(int a, int b)
          Calculates a hash code value for the two given ints.
static int taxiDistance(Index2D pos1, Index2D pos2)
          Calculates the taxi - distance between the two given Positions.
static int taxiDistance(int pos1Row, int pos1Col, int pos2Row, int pos2Col)
          Calculates the taxi - distance between the two given Positions.
 String toString()
          Returns a textual representation of this position.
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
See Also:
Constant Field Values

row

private final int row
The row of this position.


column

private final int column
The column of this position.

Constructor Detail

Index2D

public Index2D()
Initializes this Position2D with the values (row, column) = (0, 0).


Index2D

public Index2D(int row,
               int column)
Initializes this Position2D with the given values.

Parameters:
row - the Row of this position.
column - the Column of this position.
Method Detail

clone

public Object clone()
Creates and returns a real, deep copy of this object.

Overrides:
clone in class Object
Returns:
a real, deep clone of this instance.

getRow

public final int getRow()
Returns the Row of this position.

Returns:
the the Row of this position.

getColumn

public final int getColumn()
Returns the Column of this position.

Returns:
the the Column of this position.

taxiDistance

public static final int taxiDistance(int pos1Row,
                                     int pos1Col,
                                     int pos2Row,
                                     int pos2Col)
Calculates the taxi - distance between the two given Positions.

Note: The taxi - metric is also called as Manhattan - metric.

Parameters:
pos1Row - the row of the fist Position.
pos1Col - the col of the fist Position.
pos2Row - the row of the second Position.
pos2Col - the col of the second Position.
Returns:
the taxi - distance between the two given Positions.

taxiDistance

public static final int taxiDistance(Index2D pos1,
                                     Index2D pos2)
Calculates the taxi - distance between the two given Positions.

Note: The taxi - metric is also called as Manhattan - metric.

Parameters:
pos1 - the fist Position.
pos2 - the second Position.
Returns:
the taxi - distance between the two given Positions.

getDeferred

public final Index2D getDeferred(int changeRow,
                                 int changeColumn)
Creates and returns a new Position2D which is deferred by the given values in relation to this Position2D.

Parameters:
changeRow - the deviant of the Row.
changeColumn - the derivant of the Column.
Returns:
the deferred Position2D.

toString

public final String toString()
Returns a textual representation of this position.

The result is of the form (row, column), so that the String contains no line breaks.

Overrides:
toString in class Object
Returns:
a textual representation of this position.

compareTo

public final int compareTo(Index2D other)
Compares some other Position2D with this one for order.

Specified by:
compareTo in interface Comparable<Index2D>
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

hashCode

public static final int hashCode(int a,
                                 int b)
Calculates a hash code value for the two given ints.

The method is not commutative, that means the chronological order of the arguments is relevant for the result. Furthermore, this method is injective for values a, b < 250.

Mathematically, this method is a conversion of Cantor's diagonal technique.

Parameters:
a - the fist int.
b - the second int.
Returns:
the hash code value for the two given ints.

hashCode

public final int hashCode()
Calculates a hash code value for this Position2D.

Overrides:
hashCode in class Object
Returns:
the hash code value for this Position2D.
See Also:
hashCode(int a, int b)

equals

public final boolean equals(Object obj)
Indicates wheather some other Position2D/code> is "equal to" this one.

Note: Two 2-dimensional positions should be detected as "equal" if they cover the same content, and not only if they are the same object.

Overrides:
equals in class Object
Parameters:
obj - the reference object with which to compare.
Returns:
true if this object covers the same content as the obj argument; false otherwise.

jjdh API

Copyright © 2006 Jonas Jacobi and Dennis Heidsiek. All Rights Reserved.