-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathElemento.java
More file actions
114 lines (86 loc) · 2.45 KB
/
Elemento.java
File metadata and controls
114 lines (86 loc) · 2.45 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
import java.util.ArrayList;
public class Elemento {
private int idade, id;
private String nome;
private Elemento raiz;
private ArrayList <Elemento> filhos;
private int numFilhos;
private ArrayList <Elemento> netos;
private int numNetos;
// Acessores
public Elemento getRaiz() {
return raiz;
}
public void setRaiz(Elemento raiz) {
this.raiz = raiz;
}
public int getIdade() {
return idade;
}
public void setIdade(int idade) {
this.idade = idade;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public ArrayList <Elemento> getFilhos() {
return filhos;
}
public void setFilhos(ArrayList <Elemento> filhos) {
this.filhos = filhos;
}
public void setNumFilhos(int numFilhos) {
this.numFilhos = numFilhos;
}
public ArrayList <Elemento> getNetos() {
return netos;
}
public void setNetos(ArrayList <Elemento> netos) {
this.netos = netos;
}
public void setNumNetos(int numNetos) {
this.numNetos = numNetos;
}
// Construtor
public Elemento (int idadeElemento, String nomeElemento) {
this.nome = nomeElemento;
this.idade = idadeElemento;
}
public Elemento () {
}
@Override
public String toString() {
return "[nome=" + nome + ", idade=" + idade + "]";
}
public Elemento getElementoFilhos(int id){
return getElementoRecursiveFilhos(raiz,id);
}
Elemento getElementoRecursiveFilhos(Elemento elemento, int indexDoArrayListFilho){
if(elemento.getId() == id) return elemento;
for(Elemento filho : elemento.getFilhos()){
Elemento temp = getElementoRecursiveFilhos(filho,indexDoArrayListFilho);
if(temp != null && temp.getId() == indexDoArrayListFilho) return filho;
}
return null;
}
public Elemento getElementoNetos(int id) {
return getElementoRecursiveNetos(raiz, id);
}
private Elemento getElementoRecursiveNetos(Elemento elemento, int indexDoArrayListNeto){
if(elemento.getId() == id) return elemento;
for(Elemento netos : elemento.getNetos()){
Elemento temp = getElementoRecursiveNetos(netos,indexDoArrayListNeto);
if(temp != null && temp.getId() == indexDoArrayListNeto) return netos;
}
return null;
}
}