60 lines
1.5 KiB
Java
60 lines
1.5 KiB
Java
package chocobar.bpl;
|
|
|
|
import java.util.HashMap;
|
|
|
|
public class ChocoBarSetNode {
|
|
private ChocoBar chocobar;
|
|
private int id;
|
|
private HashMap subtree;
|
|
|
|
public ChocoBarSetNode(){
|
|
this.chocobar=null;
|
|
this.id=-1;
|
|
this.subtree=new HashMap();
|
|
}
|
|
public ChocoBarSetNode add(ChocoBar extCB,int pos,int nid){
|
|
if (pos==extCB.brkPtLst.size()){
|
|
//ca se passe dans l'etat courant
|
|
this.id=nid;
|
|
this.chocobar=extCB;
|
|
return this;
|
|
} else {
|
|
//ca se passe dans le fils..
|
|
IntPoint bp=(IntPoint)extCB.brkPtLst.elementAt(pos);
|
|
if (this.subtree.containsKey(bp)){
|
|
ChocoBarSetNode subnode=(ChocoBarSetNode)this.subtree.get(bp);
|
|
return subnode.add(extCB,pos+1,nid);
|
|
} else {
|
|
ChocoBarSetNode ncbs=new ChocoBarSetNode();
|
|
this.subtree.put(bp,ncbs);
|
|
return ncbs.add(extCB,pos+1,nid);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ChocoBarSetNode getSimilar(ChocoBar extCB, int pos){
|
|
if (pos==extCB.brkPtLst.size()){
|
|
//c'est l'état courant
|
|
if (this.chocobar==null){
|
|
return null;
|
|
} else {
|
|
return this;
|
|
}
|
|
} else {
|
|
//ca se passe dans le fils..
|
|
IntPoint bp=(IntPoint)extCB.brkPtLst.elementAt(pos);
|
|
if (this.subtree.containsKey(bp)){
|
|
ChocoBarSetNode subnode=(ChocoBarSetNode)this.subtree.get(bp);
|
|
return subnode.getSimilar(extCB,pos+1);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|
|
|
|
public void setId(int nid){ this.id=nid; }
|
|
public int getId(){ return this.id; }
|
|
public ChocoBar getChocoBar(){ return this.chocobar; }
|
|
public HashMap getSubTree(){ return this.subtree; }
|
|
}
|