-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathElemento.java
More file actions
50 lines (40 loc) · 1.15 KB
/
Elemento.java
File metadata and controls
50 lines (40 loc) · 1.15 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
package Trabalho1;
public class Elemento<C extends Comparable<C>, V> implements Comparable<Elemento> {
private C chave;
private V valor;
public Elemento(C chave, V valor){
setValor(valor);
setChave(chave);
}
public Integer compararChaves(C chave){
return this.chave.compareTo(chave);
}
public C getChave() { return chave; }
public void setChave(C chave) {
if(chave == null){
throw new IllegalArgumentException();
}
this.chave = chave;
}
public V getValor() { return valor; }
public void setValor(V valor) {
if(valor == null) {
throw new IllegalArgumentException();
}
this.valor = valor;
}
public Elemento criarElemento(C chave, V valor){
return new Elemento<C, V>(chave,valor);
}
@Override
public String toString() {
return "Elemento{" +
" " + chave +
" " + valor +
'}';
}
@Override
public int compareTo(Elemento o) {
return this.compararChaves((C) o.getChave());
}
}