Browse Source

Mejora del codigo.

master
Cristobal Bernal Mayordomo 2 years ago
parent
commit
cb0b6f4d43
8 changed files with 69 additions and 18 deletions
  1. +16
    -0
      src/main/java/com/cristobalbernal/loladvisor/LolAdvisorRunApp.java
  2. +5
    -4
      src/main/java/com/cristobalbernal/loladvisor/dao/LolDao.java
  3. +15
    -10
      src/main/java/com/cristobalbernal/loladvisor/dao/LolDaoImplMemory.java
  4. +1
    -1
      src/main/java/com/cristobalbernal/loladvisor/dao/UtilLolFileReader.java
  5. +13
    -3
      src/main/java/com/cristobalbernal/loladvisor/model/Lol.java
  6. +3
    -0
      src/main/java/com/cristobalbernal/loladvisor/service/LolQueryService.java
  7. +13
    -0
      src/main/java/com/cristobalbernal/loladvisor/service/LolQueryServiceImpl.java
  8. +3
    -0
      src/main/java/com/cristobalbernal/loladvisor/service/LolService.java

+ 16
- 0
src/main/java/com/cristobalbernal/loladvisor/LolAdvisorRunApp.java View File

@ -1,4 +1,5 @@
package com.cristobalbernal.loladvisor; package com.cristobalbernal.loladvisor;
import com.cristobalbernal.loladvisor.dao.LolDaoImplMemory;
import com.cristobalbernal.loladvisor.model.Lol; import com.cristobalbernal.loladvisor.model.Lol;
import com.cristobalbernal.loladvisor.service.LolQueryService; import com.cristobalbernal.loladvisor.service.LolQueryService;
import com.cristobalbernal.loladvisor.service.LolService; import com.cristobalbernal.loladvisor.service.LolService;
@ -15,6 +16,7 @@ public class LolAdvisorRunApp {
private LolService videogameService; private LolService videogameService;
@Autowired @Autowired
private LolQueryService lolQueryService; private LolQueryService lolQueryService;
private LolDaoImplMemory daoImplMemory;
@Autowired @Autowired
private LolAdvisorHelp help; private LolAdvisorHelp help;
@ -62,6 +64,20 @@ public class LolAdvisorRunApp {
case "-t": case "-t":
lolQueryService.titleContains(argumento[1]); lolQueryService.titleContains(argumento[1]);
break; break;
case "-l":
daoImplMemory.findAll();
break;
case "-c":
daoImplMemory.mostrarCantidadPersonajes();
break;
case "-p":
daoImplMemory.buscarPorID(Integer.parseInt(argumento[1]));
break;
case "-df":
lolQueryService.mostrarPorDificultada(argumento[1].split(","));
break;
default: error = true; default: error = true;
System.out.println("Error de sintaxis"); System.out.println("Error de sintaxis");
System.out.println(help.getHelp()); System.out.println(help.getHelp());


+ 5
- 4
src/main/java/com/cristobalbernal/loladvisor/dao/LolDao.java View File

@ -4,9 +4,10 @@ import com.cristobalbernal.loladvisor.model.Lol;
import java.util.Collection; import java.util.Collection;
public interface LolDao { public interface LolDao {
public Lol findById(long id);
public void buscarPorID(long id);
public Collection<Lol> findAll(); public Collection<Lol> findAll();
public void insert(Lol videogame);
public void edit(Lol videogame);
public void delete(long id);
public void insertarPersonaje(Lol videogame);
public void editarPersonaje(Lol videogame);
public void eliminarPersonaje(long id);
public void mostrarCantidadPersonajes();
} }

+ 15
- 10
src/main/java/com/cristobalbernal/loladvisor/dao/LolDaoImplMemory.java View File

@ -23,34 +23,39 @@ public class LolDaoImplMemory implements LolDao {
public void init() { public void init() {
lol = UtilLolFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator()); lol = UtilLolFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator());
} }
public Lol findById(long id) {
@Override
public void buscarPorID(long id) {
Optional<Lol> result = lol.stream().filter(lol -> lol.getId() == id).findFirst(); Optional<Lol> result = lol.stream().filter(lol -> lol.getId() == id).findFirst();
return result.orElse(null);
System.out.println(result.orElse(null));
} }
@Override
public Collection<Lol> findAll() { public Collection<Lol> findAll() {
return lol; return lol;
} }
public void insert(Lol videogame) {
public void insertarPersonaje(Lol videogame) {
lol.add(videogame); lol.add(videogame);
} }
public void edit(Lol videogame) {
@Override
public void editarPersonaje(Lol videogame) {
int i = getIndexOf(videogame.getId()); int i = getIndexOf(videogame.getId());
if(i != -1) { if(i != -1) {
lol.set(i, videogame); lol.set(i, videogame);
} }
} }
public void delete(long id) {
@Override
public void eliminarPersonaje(long id) {
int i = getIndexOf(id); int i = getIndexOf(id);
if(i != -1) { if(i != -1) {
lol.remove(i); lol.remove(i);
} }
} }
@Override
public void mostrarCantidadPersonajes() {
System.out.println(lol.size());
}
private int getIndexOf(long id) { private int getIndexOf(long id) {
boolean founds = false; boolean founds = false;
int i = 0; int i = 0;


+ 1
- 1
src/main/java/com/cristobalbernal/loladvisor/dao/UtilLolFileReader.java View File

@ -20,7 +20,7 @@ public class UtilLolFileReader {
.map(line -> { .map(line -> {
String[] values = line.split(separator); String[] values = line.split(separator);
return new Lol(Long.parseLong(values[0]), values[1], return new Lol(Long.parseLong(values[0]), values[1],
Arrays.asList(values[3].split(listSeparator)), values[4]);
Arrays.asList(values[2].split(listSeparator)),values[3], values[4]);
}).collect(Collectors.toList()); }).collect(Collectors.toList());
// @formatter:on // @formatter:on


+ 13
- 3
src/main/java/com/cristobalbernal/loladvisor/model/Lol.java View File

@ -6,15 +6,25 @@ public class Lol {
private long id; private long id;
private String nombre; private String nombre;
private List<String> rol; private List<String> rol;
private String dificultad;
private String genero; private String genero;
public Lol() {} public Lol() {}
public Lol(long id, String nombre, List<String> rol, String plataformas) {
public String getDificultad() {
return dificultad;
}
public void setDificultad(String dificultad) {
this.dificultad = dificultad;
}
public Lol(long id, String nombre, List<String> rol, String dificultad, String genero) {
this.id = id; this.id = id;
this.nombre = nombre; this.nombre = nombre;
this.rol = rol; this.rol = rol;
this.genero = plataformas;
this.dificultad = dificultad;
this.genero = genero;
} }
public long getId() { public long getId() {
@ -51,7 +61,7 @@ public class Lol {
@Override @Override
public String toString() { public String toString() {
return "Videogame [id=" + id + ", nombre=" + nombre + ", Rol=" return "Videogame [id=" + id + ", nombre=" + nombre + ", Rol="
+ rol.toString() + ", plataformas=" + genero + "]";
+ rol.toString() + ", plataformas=" + genero + ", dificultada= " + dificultad +"]";
} }


+ 3
- 0
src/main/java/com/cristobalbernal/loladvisor/service/LolQueryService.java View File

@ -8,4 +8,7 @@ public interface LolQueryService {
public LolQueryService anyName(String... name); public LolQueryService anyName(String... name);
public LolQueryService allName(String... name); public LolQueryService allName(String... name);
public LolQueryService titleContains(String title); public LolQueryService titleContains(String title);
public LolQueryService mostrarPorDificultada(String... dificultad);
public LolQueryService mostrarPorGenero(String... genero);
} }

+ 13
- 0
src/main/java/com/cristobalbernal/loladvisor/service/LolQueryServiceImpl.java View File

@ -54,4 +54,17 @@ public class LolQueryServiceImpl implements LolQueryService {
return this; return this;
} }
@Override
public LolQueryService mostrarPorDificultada(String... dificultad) {
Predicate<Lol> pAnyGenre = (lol -> Arrays.stream(dificultad).anyMatch(lol.getDificultad()::contains));
predicate = (predicate == null) ? pAnyGenre : predicate.and(pAnyGenre);
return this;
}
@Override
public LolQueryService mostrarPorGenero(String... genero) {
Predicate<Lol> pAnyGenre = (lol -> Arrays.stream(genero).anyMatch(lol.getGenero()::contains));
predicate = (predicate == null) ? pAnyGenre : predicate.and(pAnyGenre);
return this;
}
} }

+ 3
- 0
src/main/java/com/cristobalbernal/loladvisor/service/LolService.java View File

@ -40,6 +40,9 @@ public class LolService {
public Collection<Lol> findByAllGenres(String... genres) { public Collection<Lol> findByAllGenres(String... genres) {
return queryService.allName(genres).exec(); return queryService.allName(genres).exec();
} }
public Collection<Lol> buscarPorDifucultad(String... dificultada){
return null;
}
public Collection<Lol> findByTitleContains(String title) { public Collection<Lol> findByTitleContains(String title) {
return queryService.titleContains(title).exec(); return queryService.titleContains(title).exec();


Loading…
Cancel
Save