-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayTddCode
More file actions
72 lines (54 loc) · 1.24 KB
/
ArrayTddCode
File metadata and controls
72 lines (54 loc) · 1.24 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
package prArrayAsociativo;
import java.util.ArrayList;
import java.util.List;
//import javax.swing.text.html.HTMLDocument.Iterator;
public class ArrayAsociativo <T,Z>{
private List<T> arrayKeys;
private List<Z> arrayObjets;
private int size;
private int currentsize;
public ArrayAsociativo (int a) {
arrayKeys= new ArrayList<T>();
arrayObjets= new ArrayList<Z>();
size=a;
currentsize=0;
}
public void put(T i, Z j) {
// TODO Auto-generated method stub
if(currentsize+1 >size){
throw new ArrayException();
}else if(arrayKeys.contains(i)){
throw new ArrayException();
}else{
arrayKeys.add(currentsize,i);
arrayObjets.add(currentsize,j);
currentsize++;
}
}
public Z get(T i) {
int index =0;
Z res=null;
for(T t :arrayKeys){
if(t.equals(i)){
res=arrayObjets.get(index);
}
index++;
}
return res;
// TODO Auto-generated method stub
}
public boolean isempty() {
// TODO Auto-generated method stub
return currentsize==0;
}
public void remove(T i) {
// TODO Auto-generated method stub
int index=0;
boolean found1=arrayObjets.remove(get(i));
boolean found2 =arrayKeys.remove(i);
if(!(found1||found2)){
throw new ArrayException();
}
currentsize--;
}
}