Browse Source

Avances

master
Cristobal Bernal Mayordomo 2 years ago
parent
commit
cc964b28f0
8 changed files with 64 additions and 82 deletions
  1. +9
    -8
      src/main/java/com/cristobalbernal/loladvisor/dao/LolDaoImplMemory.java
  2. +3
    -2
      src/main/java/com/cristobalbernal/loladvisor/dao/UtilLolFileReader.java
  3. +8
    -35
      src/main/java/com/cristobalbernal/loladvisor/model/Lol.java
  4. +4
    -3
      src/main/java/com/cristobalbernal/loladvisor/service/LolQueryService.java
  5. +15
    -15
      src/main/java/com/cristobalbernal/loladvisor/service/LolQueryServices.java
  6. +7
    -1
      src/main/java/com/cristobalbernal/loladvisor/service/LolService.java
  7. +2
    -2
      src/main/resources/application.properties
  8. +16
    -16
      src/main/resources/bbdd.csv

+ 9
- 8
src/main/java/com/cristobalbernal/loladvisor/dao/LolDaoImplMemory.java View File

@ -4,6 +4,7 @@ import com.cristobalbernal.loladvisor.config.AppConfig;
import com.cristobalbernal.loladvisor.model.Lol; import com.cristobalbernal.loladvisor.model.Lol;
import org.springframework.stereotype.Repository; import org.springframework.stereotype.Repository;
import javax.annotation.PostConstruct;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.List; import java.util.List;
@ -14,10 +15,9 @@ public class LolDaoImplMemory implements LolDao{
public List<Lol> lols = new ArrayList<>(); public List<Lol> lols = new ArrayList<>();
private AppConfig config;
private AppConfig appConfig;
public void init() { public void init() {
lols = UtilLolFileReader.readFile(config.getFile(),config.getSeparator(),config.getListSeparator());
lols = UtilLolFileReader.readFile(appConfig.getFile(), appConfig.getSeparator(), appConfig.getListSeparator());
} }
@ -46,9 +46,9 @@ public class LolDaoImplMemory implements LolDao{
@Override @Override
public void edit(Lol lol) { public void edit(Lol lol) {
int index = getIndexOf(lol.getId());
if(index != -1)
lols.set(index, lol);
int i = getIndexOf(lol.getId());
if(i != -1)
lols.set(i, lol);
} }
@Override @Override
@ -63,10 +63,11 @@ public class LolDaoImplMemory implements LolDao{
int index = 0; int index = 0;
while(!encontrado && index < lols.size()) { while(!encontrado && index < lols.size()) {
if(lols.get(index).getId() == id)
if(lols.get(index).getId() == id){
encontrado = true; encontrado = true;
else
} else{
index++; index++;
}
} }
return (encontrado) ? index : -1; return (encontrado) ? index : -1;
} }


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

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


+ 8
- 35
src/main/java/com/cristobalbernal/loladvisor/model/Lol.java View File

@ -7,12 +7,14 @@ public class Lol {
private String nombre; private String nombre;
private List<String> rol; private List<String> rol;
private String dificultad; private String dificultad;
private String genero;
public Lol(long id, String nombre, List<String> rol, String 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.dificultad = dificultad; this.dificultad = dificultad;
this.genero = genero;
} }
public long getId() { public long getId() {
@ -22,9 +24,6 @@ public class Lol {
public String getNombre() { public String getNombre() {
return nombre; return nombre;
} }
public String getDificultad() { public String getDificultad() {
return dificultad; return dificultad;
} }
@ -49,40 +48,13 @@ public class Lol {
this.dificultad = dificultad; this.dificultad = dificultad;
} }
@Override
public int hashCode() {
return super.hashCode();
public String getGenero() {
return genero;
} }
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Lol other = (Lol) obj;
if (dificultad == null) {
if (other.dificultad != null)
return false;
} else if (!dificultad.equals(other.dificultad))
return false;
if (id != other.id)
return false;
if (nombre == null) {
if (other.nombre != null)
return false;
} else if (!nombre.equals(other.nombre))
return false;
if (rol == null) {
if (other.rol != null)
return false;
} else if (!rol.equals(other.rol))
return false;
return true;
public void setGenero(String genero) {
this.genero = genero;
} }
@Override @Override
public String toString() { public String toString() {
return "Lol{" + return "Lol{" +
@ -90,6 +62,7 @@ public class Lol {
", nombre='" + nombre + '\'' + ", nombre='" + nombre + '\'' +
", rol=" + rol + ", rol=" + rol +
", dificultad='" + dificultad + '\'' + ", dificultad='" + dificultad + '\'' +
", genero='" + genero + '\'' +
'}'; '}';
} }
} }

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

@ -5,8 +5,9 @@ import com.cristobalbernal.loladvisor.model.Lol;
import java.util.Collection; import java.util.Collection;
public interface LolQueryService { public interface LolQueryService {
public LolQueryService exec();
public LolQueryService anyDificultad(String... dificultad);
public LolQueryService anyRol(String... rol);
public Collection<Lol> exec();
public LolQueryService anyGenre(String... genres);
public LolQueryService allGenres(String... genres);
public LolQueryService titleContains(String title);
} }

+ 15
- 15
src/main/java/com/cristobalbernal/loladvisor/service/LolQueryServices.java View File

@ -2,10 +2,10 @@ package com.cristobalbernal.loladvisor.service;
import com.cristobalbernal.loladvisor.dao.LolDao; import com.cristobalbernal.loladvisor.dao.LolDao;
import com.cristobalbernal.loladvisor.model.Lol; import com.cristobalbernal.loladvisor.model.Lol;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collection;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -16,32 +16,32 @@ public class LolQueryServices implements LolQueryService {
private Predicate<Lol> predicate; private Predicate<Lol> predicate;
public void init(){
predicate = null;
}
@Override @Override
public LolQueryService exec() {
return (LolQueryService) dao.findAll()
public Collection<Lol> exec() {
return dao.findAll()
.stream() .stream()
.filter(predicate) .filter(predicate)
.collect(Collectors.toList()); .collect(Collectors.toList());
}
@Override
public LolQueryService anyGenre(String... genres) {
Predicate<Lol> pAnyGenre = (vg -> Arrays.stream(genres).anyMatch(vg.getNombre()::contains));
predicate = (predicate == null) ? pAnyGenre : predicate.and(pAnyGenre);
return this;
} }
@Override @Override
public LolQueryService anyDificultad(String... dificultad) {
Predicate<Lol> lolPredicate = (lol -> Arrays.stream(dificultad).anyMatch(lol.getNombre()::contains));
predicate = (predicate == null) ? lolPredicate : predicate.and(lolPredicate);
public LolQueryService allGenres(String... genres) {
Predicate<Lol> pAllGenre = (vg -> Arrays.stream(genres).allMatch(vg.getNombre()::contains));
predicate = (predicate == null) ? pAllGenre : predicate.and(pAllGenre);
return this; return this;
} }
@Override @Override
public LolQueryService anyRol(String... rol) {
Predicate<Lol> pAllGenres = (lol -> Arrays.stream(rol).allMatch(lol.getRol()::contains));
predicate = (predicate == null) ? pAllGenres : predicate.and(pAllGenres);
public LolQueryService titleContains(String title) {
Predicate<Lol> pTitleContains = (vg -> vg.getNombre().toLowerCase().contains(title.toLowerCase()));
predicate = (predicate == null) ? pTitleContains : predicate.and(pTitleContains);
return this; return this;
} }
} }

+ 7
- 1
src/main/java/com/cristobalbernal/loladvisor/service/LolService.java View File

@ -2,10 +2,16 @@ package com.cristobalbernal.loladvisor.service;
import com.cristobalbernal.loladvisor.dao.LolDao; import com.cristobalbernal.loladvisor.dao.LolDao;
import java.util.Collection;
public class LolService { public class LolService {
LolDao filmDao; LolDao filmDao;
LolQueryService queryService; LolQueryService queryService;
public Collection<String> findAllGenres(){
return null;
}
} }

+ 2
- 2
src/main/resources/application.properties View File

@ -1,3 +1,3 @@
file.path=classpath:bbdd.csv file.path=classpath:bbdd.csv
file.csv.separator=;
file.csv.list_separator=,
file.csv.separator=,
file.csv.list_separator=-

+ 16
- 16
src/main/resources/bbdd.csv View File

@ -1,16 +1,16 @@
id;name;rol;dificultad
1;Ahri;Asesina;Media
2;Atrox;Luchador;Media
3;Brand;Mago;Media
4;Ezreal;Tirador;Media
5;Alistar;Apoyo;Media
6;Amumu;Tanques;Baja
7;Akali;Asesina;Media
8;Fiora;Asesina;Baja
9;Veigar;Mago;Media
10;Kaisa;Tirador;Media
11;Karma;Apoyo;Baja
12;Ksante;Tanques;Dificil
13;Diana;Asesina;Media
14;Ekko;Asesino;Dificil
15;Elise;Asesina;Dificil
id,name,rol,dificultad,genero
1,Ahri,Asesina-Mago,Media,Mujer
2,Atrox,Luchador-Asesino,Media,Hombre
3,Brand,Mago-Apoyo,Media,Hombre
4,Ezreal,Tirador-Asesino,Media,Hombre
5,Alistar,Apoyo-Tanque,Media,Hombre
6,Amumu,Tanques-Apoyo,Baja,Hombre
7,Akali,Asesina-Luchador,Media,Mujer
8,Fiora,Asesina-Tanque,Baja,Mujer
9,Veigar,Mago-Apoyo,Media,Hombre
10,Kaisa,Tirador-Asesina,Media,Mujer
11,Karma,Apoyo-Mago,Baja,Mujer
12,Ksante,Tanques-Luchador,Dificil,Hombre
13,Diana,Asesina-Luchador,Media,Mujer
14,Ekko,Asesino-Apoyo,Dificil,Hombre
15,Elise,Asesina-Mago,Dificil,Mujer

Loading…
Cancel
Save