136 lines
2.8 KiB
Java
136 lines
2.8 KiB
Java
package chocobar.bpl;
|
|
|
|
import java.util.*;
|
|
|
|
public class BreakPointList extends Vector{
|
|
/**
|
|
* Constructeur par defaut
|
|
**/
|
|
public BreakPointList(){
|
|
super();
|
|
}
|
|
|
|
/**
|
|
* Constructeur a partir d'un autre objet de meme type
|
|
**/
|
|
public BreakPointList(BreakPointList old){
|
|
super();
|
|
for (int i=0;i<old.size();i++){
|
|
super.add(old.elementAt(i));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Fonction qui verifie si le carre (x, y) est encore plein
|
|
* ou deja troue
|
|
**/
|
|
//PROFILED
|
|
public boolean isBroken(IntPoint current){
|
|
int cX=current.getX();
|
|
int cY=current.getY();
|
|
IntPoint p=null;
|
|
for(int i=0;i<this.size();i++){
|
|
p=(IntPoint)super.elementAt(i);
|
|
if ((p.getX()<=cX) && (p.getY()<=cY)){ return true; }
|
|
}
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Fonction qui ajoute un breakpoint a cet objet si possible
|
|
**/
|
|
public void add(IntPoint current){
|
|
IntPoint p;
|
|
Iterator i=this.iterator();
|
|
|
|
int cX=current.getX();
|
|
int cY=current.getY();
|
|
int pX=0; int pY=0;
|
|
while (i.hasNext()){
|
|
p=(IntPoint)i.next();
|
|
pX=p.getX(); pY=p.getY();
|
|
if ( ((cX<pX)&&(cY<=pY) )
|
|
|| ((cX<=pX && (cY<pY)))){
|
|
// on "mange" l'ancien point
|
|
i.remove();
|
|
}
|
|
}
|
|
// we sort new point before insertion depending on the y coord.
|
|
int comp_idx;
|
|
int this_size=this.size();
|
|
if (this_size==0){
|
|
super.add(current);
|
|
} else {
|
|
boolean done=false; // pour savoir si on doit inserer a la fin
|
|
IntPoint comp=null;
|
|
i=this.iterator();
|
|
while(i.hasNext()){
|
|
comp=(IntPoint)i.next();
|
|
if (comp.getY() < cY){
|
|
// current is lower than cur, we have to insert it
|
|
// before indefOf(cur).
|
|
comp_idx=this.indexOf(comp);
|
|
super.insertElementAt(current,comp_idx);
|
|
done=true;
|
|
break;
|
|
}
|
|
}
|
|
if (!done){
|
|
super.insertElementAt(current, this_size);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Return a string corresponding to the current BreakPointList
|
|
**/
|
|
public String toString(){
|
|
IntPoint p;
|
|
StringBuffer s=new StringBuffer();
|
|
s.append("[");
|
|
Iterator i=this.iterator();
|
|
while (i.hasNext()){
|
|
p=(IntPoint)i.next();
|
|
s.append("(");
|
|
s.append(p);
|
|
s.append(") ");
|
|
}
|
|
s.append("]");
|
|
return s.toString();
|
|
}
|
|
|
|
/**
|
|
* Test the equality between two BreakPointLists
|
|
**/
|
|
public boolean equals(BreakPointList comp){
|
|
if (comp==null){
|
|
return false;
|
|
// everybody is null
|
|
} else {
|
|
int bpsize=this.size();
|
|
if (bpsize==comp.size()){
|
|
IntPoint p=null;
|
|
IntPoint q=null;
|
|
for (int i=0;i<bpsize;i++){
|
|
p=(IntPoint)this.elementAt(i);
|
|
q=(IntPoint)comp.elementAt(i);
|
|
if (!p.equals(q)){ return false; }
|
|
}
|
|
return true;
|
|
} else {
|
|
// breakpoint lists do not have the same size...
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Distance between two dinstinct breakpoint lists.
|
|
**/
|
|
/*
|
|
public int distance(BreakPointList other){
|
|
// TODO (using the code of onePlus if possible)!
|
|
return 0;
|
|
}
|
|
*/
|
|
}
|