|
|
@ -14,54 +14,54 @@ import java.util.Optional; |
|
|
|
@Repository |
|
|
|
public class LolDaoImplMemory implements LolDao { |
|
|
|
|
|
|
|
public List<Lol> lol = new ArrayList<>(); |
|
|
|
public List<Lol> lols = new ArrayList<>(); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private AppConfig appConfig; |
|
|
|
|
|
|
|
@PostConstruct |
|
|
|
public void init() { |
|
|
|
lol = UtilLolFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator()); |
|
|
|
lols = UtilLolFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator()); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void buscarPorID(long id) { |
|
|
|
Optional<Lol> result = lol.stream().filter(lol -> lol.getId() == id).findFirst(); |
|
|
|
Optional<Lol> result = lols.stream().filter(lol -> lol.getId() == id).findFirst(); |
|
|
|
System.out.println(result.orElse(null)); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public Collection<Lol> mostrarTodos() { |
|
|
|
return lol; |
|
|
|
return lols; |
|
|
|
} |
|
|
|
|
|
|
|
public void insertarPersonaje(Lol videogame) { |
|
|
|
lol.add(videogame); |
|
|
|
public void insertarPersonaje(Lol lol) { |
|
|
|
lols.add(lol); |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void editarPersonaje(Lol videogame) { |
|
|
|
int i = getIndexOf(videogame.getId()); |
|
|
|
public void editarPersonaje(Lol lol) { |
|
|
|
int i = getIndexOf(lol.getId()); |
|
|
|
if(i != -1) { |
|
|
|
lol.set(i, videogame); |
|
|
|
lols.set(i, lol); |
|
|
|
} |
|
|
|
} |
|
|
|
@Override |
|
|
|
public void eliminarPersonaje(long id) { |
|
|
|
int i = getIndexOf(id); |
|
|
|
if(i != -1) { |
|
|
|
lol.remove(i); |
|
|
|
lols.remove(i); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void mostrarCantidadPersonajes() { |
|
|
|
System.out.println(lol.size()); |
|
|
|
System.out.println(lols.size()); |
|
|
|
} |
|
|
|
|
|
|
|
private int getIndexOf(long id) { |
|
|
|
boolean founds = false; |
|
|
|
int i = 0; |
|
|
|
|
|
|
|
while(!founds && i < lol.size()) { |
|
|
|
if(lol.get(i).getId() == id) { |
|
|
|
while(!founds && i < lols.size()) { |
|
|
|
if(lols.get(i).getId() == id) { |
|
|
|
founds = true; |
|
|
|
} else { |
|
|
|
i++; |
|
|
|