Skip to content

Commit 48f8d49

Browse files
committed
fix: readicionando o indice indireto
1 parent 81ed962 commit 48f8d49

File tree

5 files changed

+55
-50
lines changed

5 files changed

+55
-50
lines changed

tp03/src/controller/ControllerSeries.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,6 @@ private void listActorsBySerie() {
676676
System.out.println("-----------------------------------");
677677
if (actor != null) {
678678
System.out.println("Nome: " + actor.getName());
679-
System.out.println("ID: " + actor.getId());
680679
} else {
681680
System.out.println("Erro: Ator com ID " + idActor + " não encontrado."); // Debug statement
682681
}

tp03/src/data/ArchiveActor.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,20 @@
1212
* incluindo operações CRUD e indexação por nome.
1313
*/
1414
public class ArchiveActor extends Archive<Actor> {
15-
/** Índice invertido baseado no nome do ator. */
16-
ListaInvertida listaInvertidaNome;
15+
private ListaInvertida listaInvertida;
16+
/** Índice indireto baseado no nome da ator. */
17+
ArchiveTreeB<PairNameID> indiceIndiretoNome;
1718

1819
/**
1920
* Construtor padrão que inicializa o arquivo e o índice indireto de nomes.
2021
*
2122
* @throws Exception se ocorrer erro durante a criação do arquivo ou índice.
2223
*/
2324
public ArchiveActor() throws Exception {
24-
2525
super("atores", Actor.class.getConstructor());
26-
27-
listaInvertidaNome = new ListaInvertida(5,
28-
"tp03/files/atores/blocos.listainv.db", // caminho do índice invertido
29-
"tp03/files/atores/dicionario.listainv.db"); // opcional: mapeia termos
26+
indiceIndiretoNome = new ArchiveTreeB<>(
27+
PairNameID.class.getConstructor(), 5, "tp03/files/atores/indiceNome.db");
28+
listaInvertida = new ListaInvertida(10, "tp03/files/atores/listaInvertidaDicionario.db", "tp03/files/atores/listaInvertidaBlocos.db");
3029
}
3130

3231
/**
@@ -39,12 +38,12 @@ public ArchiveActor() throws Exception {
3938
@Override
4039
public int create(Actor a) throws Exception {
4140
int id = super.create(a);
42-
43-
ElementoLista elemento = new ElementoLista(id, 1.0f);
44-
listaInvertidaNome.create(a.getName(), elemento);
41+
indiceIndiretoNome.create(new PairNameID(a.getName(), id));
42+
listaInvertida.create(a.getName(), new ElementoLista(id, 1)); // Adiciona o ator na ListaInvertida
4543
return id;
4644
}
4745

46+
4847
/**
4948
* Lê todas as ators com o nome especificado.
5049
*
@@ -91,7 +90,9 @@ public boolean delete(int id) throws Exception {
9190
Actor a = super.read(id);
9291
if (a != null) {
9392
if (super.delete(id)) {
94-
return listaInvertidaNome.delete(a.getName(), id);
93+
indiceIndiretoNome.delete(new PairNameID(a.getName(), id));
94+
listaInvertida.delete(a.getName(), id); // Remove o ator da ListaInvertida
95+
return true;
9596
}
9697
}
9798
return false;
@@ -106,19 +107,19 @@ public boolean delete(int id) throws Exception {
106107
*/
107108
@Override
108109
public boolean update(Actor atorUpdate) throws Exception {
109-
Actor a = read(atorUpdate.getId()); // na superclasse
110+
Actor a = read(atorUpdate.getId());
110111
if (a != null) {
111-
ElementoLista elemento = new ElementoLista(a.getId(), 1.0f);
112112
if (super.update(atorUpdate)) {
113113
if (!a.getName().equals(atorUpdate.getName())) {
114-
listaInvertidaNome.delete(a.getName(), a.getId());
115-
listaInvertidaNome.create(atorUpdate.getName(), elemento);
114+
indiceIndiretoNome.delete(new PairNameID(a.getName(), a.getId()));
115+
indiceIndiretoNome.create(new PairNameID(atorUpdate.getName(), atorUpdate.getId()));
116+
listaInvertida.delete(a.getName(), a.getId()); // Remove o nome antigo da ListaInvertida
117+
listaInvertida.create(atorUpdate.getName(), new ElementoLista(atorUpdate.getId(), 1)); // Adiciona o nome atualizado
116118
}
117119
return true;
118120
}
119121
}
120122
return false;
121123
}
122-
123124
}
124125

tp03/src/data/ArchiveEpisode.java

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
* incluindo persistência, leitura e gerenciamento de índices.
1414
*/
1515
public class ArchiveEpisode extends Archive<Episode> {
16-
ListaInvertida listaInvertidaNome;
16+
private ListaInvertida listaInvertida;
17+
/** Índice indireto baseado no nome do episódio. */
18+
ArchiveTreeB<PairNameID> indiceIndiretoNome;
1719

1820
/** Índice indireto relacionando o ID do episódio com o ID da série (chave estrangeira). */
1921
ArchiveTreeB<PairIDFK> relacao1N;
@@ -24,14 +26,11 @@ public class ArchiveEpisode extends Archive<Episode> {
2426
* @throws Exception caso ocorra falha na criação dos arquivos ou índices.
2527
*/
2628
public ArchiveEpisode() throws Exception {
27-
2829
super("episodios", Episode.class.getConstructor());
29-
30-
listaInvertidaNome = new ListaInvertida(5,
31-
"tp03/files/episodios/blocos.listainv.db", // caminho do índice invertido
32-
"tp03/files/episodios/dicionario.listainv.db"); // opcional: mapeia termos
33-
30+
indiceIndiretoNome = new ArchiveTreeB<>(
31+
PairNameID.class.getConstructor(), 5, "tp03/files/episodios/indiceNome.db");
3432
relacao1N = new ArchiveTreeB<>(PairIDFK.class.getConstructor(), 5, "tp03/files/episodios/relacao1N.db");
33+
listaInvertida = new ListaInvertida(10, "tp03/files/episodios/listaInvertidaDicionario.db", "tp03/files/episodios/listaInvertidaBlocos.db");
3534
}
3635

3736
/**
@@ -44,10 +43,9 @@ public ArchiveEpisode() throws Exception {
4443
@Override
4544
public int create(Episode e) throws Exception {
4645
int id = super.create(e);
47-
ElementoLista elemento = new ElementoLista(id, 1.0f);
48-
listaInvertidaNome.create(e.getName(), elemento);
49-
System.out.println(e.getId());
46+
indiceIndiretoNome.create(new PairNameID(e.getName(), id));
5047
relacao1N.create(new PairIDFK(e.getFkSerie(), e.getId()));
48+
listaInvertida.create(e.getName(), new ElementoLista(id, 1)); // Adiciona o episódio na ListaInvertida
5149
return id;
5250
}
5351

@@ -160,7 +158,10 @@ public boolean delete(int id) throws Exception {
160158
Episode e = super.read(id);
161159
if (e != null) {
162160
if (super.delete(id)) {
163-
return listaInvertidaNome.delete(e.getName(), id) && relacao1N.delete(new PairIDFK(e.getId(), e.getFkSerie()));
161+
indiceIndiretoNome.delete(new PairNameID(e.getName(), id));
162+
relacao1N.delete(new PairIDFK(e.getFkSerie(), e.getId()));
163+
listaInvertida.delete(e.getName(), id); // Remove o episódio da ListaInvertida
164+
return true;
164165
}
165166
}
166167
return false;
@@ -175,20 +176,20 @@ public boolean delete(int id) throws Exception {
175176
*/
176177
@Override
177178
public boolean update(Episode novaEpisodio) throws Exception {
178-
Episode e = read(novaEpisodio.getId()); // na superclasse
179+
Episode e = read(novaEpisodio.getId());
179180
if (e != null) {
180-
ElementoLista elemento = new ElementoLista(e.getId(), 1.0f);
181181
if (super.update(novaEpisodio)) {
182182
if (!e.getName().equals(novaEpisodio.getName())) {
183-
listaInvertidaNome.delete(e.getName(), e.getId());
183+
indiceIndiretoNome.delete(new PairNameID(e.getName(), e.getId()));
184184
relacao1N.delete(new PairIDFK(e.getFkSerie(), e.getId()));
185-
listaInvertidaNome.create(novaEpisodio.getName(), elemento);
185+
listaInvertida.delete(e.getName(), e.getId()); // Remove o nome antigo da ListaInvertida
186+
indiceIndiretoNome.create(new PairNameID(novaEpisodio.getName(), novaEpisodio.getId()));
186187
relacao1N.create(new PairIDFK(e.getFkSerie(), e.getId()));
188+
listaInvertida.create(novaEpisodio.getName(), new ElementoLista(novaEpisodio.getId(), 1)); // Adiciona o nome atualizado
187189
}
188190
return true;
189191
}
190192
}
191193
return false;
192194
}
193-
194195
}

tp03/src/data/ArchiveSeries.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
* incluindo operações CRUD e indexação por nome.
1313
*/
1414
public class ArchiveSeries extends Archive<Series> {
15-
ListaInvertida listaInvertidaNome;
15+
private ListaInvertida listaInvertida;
16+
/** Índice indireto baseado no nome da série. */
17+
ArchiveTreeB<PairNameID> indiceIndiretoNome;
1618

1719
/**
1820
* Construtor padrão que inicializa o arquivo e o índice indireto de nomes.
@@ -23,9 +25,9 @@ public ArchiveSeries() throws Exception {
2325

2426
super("series", Series.class.getConstructor());
2527

26-
listaInvertidaNome = new ListaInvertida(5,
27-
"tp03/files/series/blocos.listainv.db", // caminho do índice invertido
28-
"tp03/files/series/dicionario.listainv.db"); // opcional: mapeia termos
28+
indiceIndiretoNome = new ArchiveTreeB<>(
29+
PairNameID.class.getConstructor(), 5, "tp03/files/series/indiceNome.db");
30+
listaInvertida = new ListaInvertida(10, "tp03/files/series/listaInvertidaDicionario.db", "tp03/files/series/listaInvertidaBlocos.db");
2931
}
3032

3133
/**
@@ -37,14 +39,14 @@ public ArchiveSeries() throws Exception {
3739
*/
3840
@Override
3941
public int create(Series s) throws Exception {
40-
// Check if a series with the same name already exists
42+
// Verifica se já existe uma série com o mesmo nome
4143
Series[] existingSeries = readNome(s.getName());
4244
if (existingSeries != null && existingSeries.length > 0) {
4345
throw new Exception("Série com o mesmo nome já existe.");
4446
}
4547
int id = super.create(s);
46-
ElementoLista elemento = new ElementoLista(id, 1.0f);
47-
listaInvertidaNome.create(s.getName(), elemento);
48+
indiceIndiretoNome.create(new PairNameID(s.getName(), id));
49+
listaInvertida.create(s.getName(), new ElementoLista(id, 1)); // Adiciona a série na ListaInvertida
4850
return id;
4951
}
5052

@@ -94,7 +96,9 @@ public boolean delete(int id) throws Exception {
9496
Series s = super.read(id);
9597
if (s != null) {
9698
if (super.delete(id)) {
97-
return listaInvertidaNome.delete(s.getName(), id);
99+
indiceIndiretoNome.delete(new PairNameID(s.getName(), id));
100+
listaInvertida.delete(s.getName(), id); // Remove a série da ListaInvertida
101+
return true;
98102
}
99103
}
100104
return false;
@@ -109,19 +113,19 @@ public boolean delete(int id) throws Exception {
109113
*/
110114
@Override
111115
public boolean update(Series novaSerie) throws Exception {
112-
Series s = read(novaSerie.getId()); // na superclasse
116+
Series s = read(novaSerie.getId());
113117
if (s != null) {
114-
ElementoLista elemento = new ElementoLista(s.getId(), 1.0f);
115118
if (super.update(novaSerie)) {
116119
if (!s.getName().equals(novaSerie.getName())) {
117-
listaInvertidaNome.delete(s.getName(), s.getId());
118-
listaInvertidaNome.create(novaSerie.getName(), elemento);
120+
indiceIndiretoNome.delete(new PairNameID(s.getName(), s.getId()));
121+
indiceIndiretoNome.create(new PairNameID(novaSerie.getName(), novaSerie.getId()));
122+
listaInvertida.delete(s.getName(), s.getId()); // Remove o nome antigo da ListaInvertida
123+
listaInvertida.create(novaSerie.getName(), new ElementoLista(novaSerie.getId(), 1)); // Adiciona o nome atualizado
119124
}
120125
return true;
121126
}
122127
}
123128
return false;
124129
}
125-
126130
}
127131

tp03/src/view/ViewEpisode.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,16 @@ public int obterTemporada() {
125125
* @return Data de lançamento em {@link LocalDate}, ou {@code null} se a entrada for vazia.
126126
*/
127127
public LocalDate obterDataLancamento() {
128-
System.out.println("Inserir Data de Lançamento: ");
128+
System.out.println("Data de Lançamento: ");
129129
while (true) {
130130
try {
131-
System.out.print("......Dia (1-31): ");
131+
System.out.print("Dia (1-31): ");
132132
int dia = Integer.parseInt(console.nextLine().trim());
133133

134-
System.out.print("......Mês (1-12): ");
134+
System.out.print("Mês (1-12): ");
135135
int mes = Integer.parseInt(console.nextLine().trim());
136136

137-
System.out.print("......Ano (ex: 2024): ");
137+
System.out.print("Ano (ex: 2024): ");
138138
int ano = Integer.parseInt(console.nextLine().trim());
139139

140140
// Tentativa de criação válida da data

0 commit comments

Comments
 (0)