SUPER CLASE
//SECCION DE CONVERTIDOR INFORMACION A UNA LISTA DE DATOS X EPISODIO
System.out.println("----------------------------------------TPO 5 DE EPISODIOS-------------------------------------------------------");
List<DatosDeEpisodio> datosXepisodios = temporadas.stream()
//cada elemento que se encuetra en la temporada sera convertida en un listado de episodios
.flatMap(t -> t.episodios().stream())
// conervertir todo en una listado muteable, es decir, se puede ir añadiendo elemento si asi se prefiere
.collect(Collectors.toList());
//top de lista de los mejores 5 episodios
datosXepisodios.stream()
.filter(e-> !e.puntuacion().equalsIgnoreCase("N/A"))
.sorted(Comparator.comparing(DatosDeEpisodio::puntuacion).reversed())
.limit(5) // limite de 5
.forEach(System.out::println);//imprime el listado
System.out.println("--------------------------------DATOS A UNA LISTA DE EPISODIOS------------------------------------------------");
//SECCION DE CONVERTiR LOS DATOS A UNA LISTA DE EPISODIOS
List<EPISODIO> episodios = temporadas.stream()
.flatMap(t -> t.episodios().stream()
.map(d -> new EPISODIO(t.Temporada(),d)) )
.collect(Collectors.toList());
episodios.forEach(System.out::println);
//BUSQUEDA DE EPISODIOS POR AÑOS DE LANZAMIENTO
System.out.println("ESCRIBE EL AÑO DEL EPISODIO QUE DESEA BUSCAR");
var fechaXepisodio =teclado.nextLine();
teclado.nextLine();
LocalDate fechaDeBusqueda = LocalDate.of(Integer.parseInt(fechaXepisodio), 1, 2);
//fecha de lanzamiento
DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy ");
episodios.stream()
.filter(e ->e.getFechaDeLanzamiento()!= null && e.getFechaDeLanzamiento().isAfter(fechaDeBusqueda))
.forEach(e -> System.out.println(
"temporada" + e.getTemporada() +
"episodio" + e.getTitulo() +
"fecha de lamzamiento" + e.getFechaDeLanzamiento().format(dtf)
));
}
}
CLASE HIJA EPISODIO
package com.oasb.Screen_Macht.Modelo;
import java.time.LocalDate;
import java.time.format.DateTimeParseException;
public class EPISODIO {
private Integer temporada ;
private String titulo ;
private Integer numeroDeEpisodios ;
private Double puntuacion ;
private LocalDate fechaDeLanzamiento ;
//gets and sets
public Integer getTemporada() {
return temporada;
}
public void setTemporada(Integer temporada) {
this.temporada = temporada;
}
public String getTitulo() {
return titulo;
}
public void setTitulo(String titulo) {
this.titulo = titulo;
}
public Integer getNumeroDeEpisodios() {
return numeroDeEpisodios;
}
public void setNumeroDeEpisodios(Integer numeroDeEpisodios) {
this.numeroDeEpisodios = numeroDeEpisodios;
}
public Double getPuntuacion() {
return puntuacion;
}
public void setPuntuacion(Double puntuacion) {
this.puntuacion = puntuacion;
}
public LocalDate getFechaDeLanzamiento() {
return fechaDeLanzamiento;
}
public void setFechaDeLanzamiento(LocalDate fechaDeLanzamiento) {
this.fechaDeLanzamiento = fechaDeLanzamiento;
}
@Override
public String toString() {
return
"temporada: " + temporada +
", titulo: '" + titulo + '\'' +
", numeroDeEpisodios: " + numeroDeEpisodios +
", fechaDeLanzamiento: " + fechaDeLanzamiento +
", puntuacion: " + puntuacion ;
}
//constructor
public EPISODIO(Integer numero, DatosDeEpisodio d ) {
this.temporada = numero;
this.titulo = d. titulo();
this.numeroDeEpisodios = d.numeroDeEpisodio();
try{
this.puntuacion = Double.valueOf(d.puntuacion());
}catch (NumberFormatException e){
this.puntuacion = 0.0;
}
try{
this.fechaDeLanzamiento = LocalDate.parse(d. fechaDeLanzamiento());
}catch (DateTimeParseException e){
this.fechaDeLanzamiento = null;
}
}
}