import java.util.*;
/**
*
*/
/**
* @author uisleandro
*
*/
public class MyTableCollection {
private List<MyTable> tabelas = null;
private double size = 0D;
public Iterator<MyTable> iterator(){
return this.tabelas.iterator();
}
/**
* @param table
*/
public void add(MyTable table) {
this.size += table.getWeight() * table.getSize();
this.tabelas.add(table);
}
/**
* @param table
*/
public void customAdd(MyTable table) {
Iterator<MyTable> it = this.iterator();
this.size += table.getWeight() * table.getSize();
//vou precisar de um indice de arvore ou hash
//para selecionar cada item.. ???
//se não aponta para ninguem sobe
if(table.getFkNames().size() == 0){
this.tabelas.add(0, table);
return;
}
int index = 0;
while(it.hasNext()){
MyTable o = it.next();
index++;
//se é apontado, fica antes do primeiro que apontar
if(o.pointsTo(table)){
index--;
break;
}
}
//se não é apontado.. fica no final, podendo apontar para os priximos que chegarem..
this.tabelas.add(index, table);
return;
}
public MyTable get(String tableName){
Iterator<MyTable> it = this.iterator();
while(it.hasNext()){
MyTable table = it.next();
if(tableName.equalsIgnoreCase(table.toString())){
return table;
}
}
return null;
}
public Double calculate(){
return this.size;
}
public MyTableCollection(){
tabelas = new LinkedList<MyTable>();
}
/**
* @param args
*/
public static void main(String[] args) {
MyTableCollection tabelas = new MyTableCollection();
MyTable a = null;
//*
a = new MyTable("AAAc");
a.addColumn("teste", new MyFKColumn("BBB", "xxs"));
tabelas.add(a);
//*/
//*
a = new MyTable("AAaB");
a.addColumn("teste", new MyFKColumn("BBB", "xxs"));
tabelas.add(a);
//*/
//*
a = new MyTable("BBB");
a.addColumn("teste", new MyFKColumn("AAC", "xxs"));
tabelas.add(a);
//*/
//ordem alfabetica..
//*
a = new MyTable("AA");
a.addColumn("teste", new MyFKColumn("AAaB", "xxs"));
tabelas.add(a);
//*/
//*
a = new MyTable("AAc");
tabelas.add(a);
//*/
//*
a = new MyTable("AAca");
tabelas.add(a);
//*/
//*
a = new MyTable("AAcd");
a.addColumn("teste", new MyFKColumn("AAAc", "xxs"));
tabelas.add(a);
//*/
Iterator<MyTable> it = tabelas.iterator();
while(it.hasNext()){
System.out.println(it.next());
}
}
}