m1.chocobarlite/src/chocobar/bpl/IntPoint.java
2009-05-01 08:07:06 +00:00

68 lines
1.2 KiB
Java

package chocobar.bpl;
public class IntPoint implements Comparable {
int x;
int y;
int hash=-1;
/**
* Constructeur d'un IntPoint a partir de deux entiers
**/
public IntPoint(int x, int y){
this.x=x;
this.y=y;
}
/**
* Fonction qui renvoie la valeur de x de cet objet
**/
public int getX(){
return this.x;
}
/**
* Fonction qui renvoie la valeur de y de cet objet
**/
public int getY(){
return this.y;
}
/**
* Fonction qui renvoie la representation de cet objet en
* String
**/
public String toString(){
return (new String(x+", "+y));
}
public int hashCode(){
// on numérote les couples (p,q) dans l'ordre des diagonales
// cf cours denombrabilité...
if (this.hash<0){
int s=this.x+this.y;
this.hash=(s)*(s+1)+this.y+this.y;
}
return this.hash;
}
public boolean equals(Object o){
if(!(o instanceof IntPoint)) { return false; }
IntPoint p=(IntPoint)o;
return ((this.x==p.x)&&(this.y==p.y));
}
public int compareTo(Object o){
if(!(o instanceof IntPoint)) { throw new ClassCastException(); }
IntPoint p=(IntPoint)o;
int comp=0;
if (this.equals(p)){
return 0;
} else {
if ((this.x<=p.x) && (this.y<=p.y)){
return 1;
}
}
return -1;
}
}