Skip to content

Commit 81ed962

Browse files
committed
Adapta as entidades Serie, Episodio, Ator para cada inserção, exclusão ou alteração para atualizar a ListaInvertida correspondente.
1 parent 1d52f31 commit 81ed962

File tree

4 files changed

+38
-30
lines changed

4 files changed

+38
-30
lines changed

tp03/src/data/ArchiveActor.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44
import tp03.src.models.Actor;
55
import tp03.src.storage.indexes.*;
66
import tp03.src.storage.structures.*;
7+
import tp03.src.storage.structures.ListaInvertida.ElementoLista;
8+
import tp03.src.storage.structures.ListaInvertida.ListaInvertida;
79

810
/**
911
* Classe responsável pela manipulação dos dados de atores,
1012
* incluindo operações CRUD e indexação por nome.
1113
*/
1214
public class ArchiveActor extends Archive<Actor> {
13-
14-
/** Índice indireto baseado no nome da ator. */
15-
ArchiveTreeB<PairNameID> indiceIndiretoNome;
15+
/** Índice invertido baseado no nome do ator. */
16+
ListaInvertida listaInvertidaNome;
1617

1718
/**
1819
* Construtor padrão que inicializa o arquivo e o índice indireto de nomes.
@@ -23,8 +24,9 @@ public ArchiveActor() throws Exception {
2324

2425
super("atores", Actor.class.getConstructor());
2526

26-
indiceIndiretoNome = new ArchiveTreeB<>(
27-
PairNameID.class.getConstructor(), 5, "tp03/files/atores/indiceNome.db");
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
2830
}
2931

3032
/**
@@ -37,7 +39,9 @@ public ArchiveActor() throws Exception {
3739
@Override
3840
public int create(Actor a) throws Exception {
3941
int id = super.create(a);
40-
indiceIndiretoNome.create(new PairNameID(a.getName(), id));
42+
43+
ElementoLista elemento = new ElementoLista(id, 1.0f);
44+
listaInvertidaNome.create(a.getName(), elemento);
4145
return id;
4246
}
4347

@@ -87,7 +91,7 @@ public boolean delete(int id) throws Exception {
8791
Actor a = super.read(id);
8892
if (a != null) {
8993
if (super.delete(id)) {
90-
return indiceIndiretoNome.delete(new PairNameID(a.getName(), id));
94+
return listaInvertidaNome.delete(a.getName(), id);
9195
}
9296
}
9397
return false;
@@ -104,10 +108,11 @@ public boolean delete(int id) throws Exception {
104108
public boolean update(Actor atorUpdate) throws Exception {
105109
Actor a = read(atorUpdate.getId()); // na superclasse
106110
if (a != null) {
111+
ElementoLista elemento = new ElementoLista(a.getId(), 1.0f);
107112
if (super.update(atorUpdate)) {
108113
if (!a.getName().equals(atorUpdate.getName())) {
109-
indiceIndiretoNome.delete(new PairNameID(a.getName(), a.getId()));
110-
indiceIndiretoNome.create(new PairNameID(atorUpdate.getName(), atorUpdate.getId()));
114+
listaInvertidaNome.delete(a.getName(), a.getId());
115+
listaInvertidaNome.create(atorUpdate.getName(), elemento);
111116
}
112117
return true;
113118
}

tp03/src/data/ArchiveEpisode.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55
import tp03.src.models.Episode;
66
import tp03.src.storage.indexes.*;
77
import tp03.src.storage.structures.*;
8+
import tp03.src.storage.structures.ListaInvertida.ElementoLista;
9+
import tp03.src.storage.structures.ListaInvertida.ListaInvertida;
810

911
/**
1012
* Classe responsável pela manipulação dos episódios,
1113
* incluindo persistência, leitura e gerenciamento de índices.
1214
*/
1315
public class ArchiveEpisode extends Archive<Episode> {
14-
15-
/** Índice indireto baseado no nome do episódio. */
16-
ArchiveTreeB<PairNameID> indiceIndiretoNome;
16+
ListaInvertida listaInvertidaNome;
1717

1818
/** Índice indireto relacionando o ID do episódio com o ID da série (chave estrangeira). */
1919
ArchiveTreeB<PairIDFK> relacao1N;
@@ -27,8 +27,9 @@ public ArchiveEpisode() throws Exception {
2727

2828
super("episodios", Episode.class.getConstructor());
2929

30-
indiceIndiretoNome = new ArchiveTreeB<>(
31-
PairNameID.class.getConstructor(), 5, "tp03/files/episodios/indiceNome.db");
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
3233

3334
relacao1N = new ArchiveTreeB<>(PairIDFK.class.getConstructor(), 5, "tp03/files/episodios/relacao1N.db");
3435
}
@@ -43,7 +44,8 @@ public ArchiveEpisode() throws Exception {
4344
@Override
4445
public int create(Episode e) throws Exception {
4546
int id = super.create(e);
46-
indiceIndiretoNome.create(new PairNameID(e.getName(), id));
47+
ElementoLista elemento = new ElementoLista(id, 1.0f);
48+
listaInvertidaNome.create(e.getName(), elemento);
4749
System.out.println(e.getId());
4850
relacao1N.create(new PairIDFK(e.getFkSerie(), e.getId()));
4951
return id;
@@ -158,7 +160,7 @@ public boolean delete(int id) throws Exception {
158160
Episode e = super.read(id);
159161
if (e != null) {
160162
if (super.delete(id)) {
161-
return indiceIndiretoNome.delete(new PairNameID(e.getName(), id)) && relacao1N.delete(new PairIDFK(e.getId(), e.getFkSerie()));
163+
return listaInvertidaNome.delete(e.getName(), id) && relacao1N.delete(new PairIDFK(e.getId(), e.getFkSerie()));
162164
}
163165
}
164166
return false;
@@ -175,11 +177,12 @@ public boolean delete(int id) throws Exception {
175177
public boolean update(Episode novaEpisodio) throws Exception {
176178
Episode e = read(novaEpisodio.getId()); // na superclasse
177179
if (e != null) {
180+
ElementoLista elemento = new ElementoLista(e.getId(), 1.0f);
178181
if (super.update(novaEpisodio)) {
179182
if (!e.getName().equals(novaEpisodio.getName())) {
180-
indiceIndiretoNome.delete(new PairNameID(e.getName(), e.getId()));
183+
listaInvertidaNome.delete(e.getName(), e.getId());
181184
relacao1N.delete(new PairIDFK(e.getFkSerie(), e.getId()));
182-
indiceIndiretoNome.create(new PairNameID(novaEpisodio.getName(), novaEpisodio.getId()));
185+
listaInvertidaNome.create(novaEpisodio.getName(), elemento);
183186
relacao1N.create(new PairIDFK(e.getFkSerie(), e.getId()));
184187
}
185188
return true;

tp03/src/data/ArchiveSeries.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
import tp03.src.models.Series;
55
import tp03.src.storage.indexes.*;
66
import tp03.src.storage.structures.*;
7+
import tp03.src.storage.structures.ListaInvertida.ElementoLista;
8+
import tp03.src.storage.structures.ListaInvertida.ListaInvertida;
79

810
/**
911
* Classe responsável pela manipulação dos dados de séries,
1012
* incluindo operações CRUD e indexação por nome.
1113
*/
1214
public class ArchiveSeries extends Archive<Series> {
13-
14-
/** Índice indireto baseado no nome da série. */
15-
ArchiveTreeB<PairNameID> indiceIndiretoNome;
15+
ListaInvertida listaInvertidaNome;
1616

1717
/**
1818
* Construtor padrão que inicializa o arquivo e o índice indireto de nomes.
@@ -23,8 +23,9 @@ public ArchiveSeries() throws Exception {
2323

2424
super("series", Series.class.getConstructor());
2525

26-
indiceIndiretoNome = new ArchiveTreeB<>(
27-
PairNameID.class.getConstructor(), 5, "tp03/files/series/indiceNome.db");
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
2829
}
2930

3031
/**
@@ -42,7 +43,8 @@ public int create(Series s) throws Exception {
4243
throw new Exception("Série com o mesmo nome já existe.");
4344
}
4445
int id = super.create(s);
45-
indiceIndiretoNome.create(new PairNameID(s.getName(), id));
46+
ElementoLista elemento = new ElementoLista(id, 1.0f);
47+
listaInvertidaNome.create(s.getName(), elemento);
4648
return id;
4749
}
4850

@@ -92,7 +94,7 @@ public boolean delete(int id) throws Exception {
9294
Series s = super.read(id);
9395
if (s != null) {
9496
if (super.delete(id)) {
95-
return indiceIndiretoNome.delete(new PairNameID(s.getName(), id));
97+
return listaInvertidaNome.delete(s.getName(), id);
9698
}
9799
}
98100
return false;
@@ -109,10 +111,11 @@ public boolean delete(int id) throws Exception {
109111
public boolean update(Series novaSerie) throws Exception {
110112
Series s = read(novaSerie.getId()); // na superclasse
111113
if (s != null) {
114+
ElementoLista elemento = new ElementoLista(s.getId(), 1.0f);
112115
if (super.update(novaSerie)) {
113116
if (!s.getName().equals(novaSerie.getName())) {
114-
indiceIndiretoNome.delete(new PairNameID(s.getName(), s.getId()));
115-
indiceIndiretoNome.create(new PairNameID(novaSerie.getName(), novaSerie.getId()));
117+
listaInvertidaNome.delete(s.getName(), s.getId());
118+
listaInvertidaNome.create(novaSerie.getName(), elemento);
116119
}
117120
return true;
118121
}

tp03/src/storage/structures/ListaInvertida/Buscador.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package tp03.src.storage.structures.ListaInvertida;
22

33
import java.util.*;
4-
import tp03.src.storage.structures.ListaInvertida.ElementoLista;
5-
import tp03.src.storage.structures.ListaInvertida.ListaInvertida;
6-
import tp03.src.storage.structures.ListaInvertida.ListaInvertidaUtils;
74

85
public class Buscador {
96

0 commit comments

Comments
 (0)