Menu

[r16]: / trunk / src / MyTableCollection.java  Maximize  Restore  History

Download this file

180 lines (110 with data), 2.7 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
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());
}
}
}