Untitled
unknown
plain_text
3 years ago
4.6 kB
9
Indexable
package fp.shows;
import java.time.Duration;
import java.time.LocalDate;
import java.time.Period;
import java.time.chrono.ChronoPeriod;
import java.time.temporal.TemporalAmount;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import fp.common.Puntuacion;
import fp.utiles.Checkers;
public class Serie implements Comparable<Serie> {
private LocalDate fechaEstreno;
private String nombre;
private Integer temporadas;
private Integer episodios;
private Integer ranking;
private List<String> actores;
private Double calificacion;
private List<String> directores;
private List<String> paises;
private Genero genero;
private Puntuacion puntuacion;
//constructor 1.
public Serie(LocalDate fechaEstreno, String nombre, Integer temporadas, Integer episodios, Integer ranking,
List<String> actores, Double calificacion, List<String> directores, List<String> paises, Genero genero,
Puntuacion puntuacion) {
super();
Checkers.checkNoNull(nombre);//Restriccion 1
Checkers.check("La serie no puede tener 0 episodios", episodios>0.);//Restriccion 2
this.fechaEstreno = fechaEstreno;
this.nombre = nombre;
this.temporadas = temporadas;
this.episodios = episodios;
this.ranking = ranking;
this.actores = new ArrayList<>(actores);
this.calificacion = calificacion;
this.directores = new ArrayList<>(directores);
this.paises = new ArrayList<>(paises);
this.genero = genero;
this.puntuacion = puntuacion;
}
//Constructor 2
public Serie( String nombre, Integer temporadas,Integer episodios,Integer ranking,Double calificacion,Genero genero,Double puntos,Integer numeroCriticas) {
super();
Checkers.checkNoNull(nombre); //Restriccion 1
Checkers.check("Episodios no validos", episodios>0.);//Restriccion 2
this.fechaEstreno = LocalDate.now();
this.nombre = nombre;
this.temporadas = temporadas;
this.episodios = episodios;
this.ranking = ranking;
this.actores = new ArrayList<>();
this.calificacion = calificacion;
this.directores = new ArrayList<>();
this.paises = new ArrayList<>();
this.genero = genero;
this.puntuacion = new Puntuacion(puntos,numeroCriticas);
}
//Getters y setters
public Double getCalificacion() {
return calificacion;
}
public void setCalificacion(Double calificacion) {
this.calificacion = calificacion;
}
public LocalDate getFechaEstreno() {
return fechaEstreno;
}
public String getNombre() {
return nombre;
}
public Integer getTemporadas() {
return temporadas;
}
public Integer getEpisodios() {
return episodios;
}
public Integer getRanking() {
return ranking;
}
public List<String> getActores() {
return new ArrayList<>(actores);
}
public List<String> getDirectores() {
return new ArrayList<>(directores);
}
public List<String> getPaises() {
return new ArrayList<>(paises);
}
public Genero getGenero() {
return genero;
}
public Puntuacion getPuntuacion() {
return puntuacion;
}
//propiedad derivada
public Boolean esNovedad( ) {
boolean res =false;
LocalDate hoy = LocalDate.now();
Period dias =fechaEstreno.until(hoy);
if (dias.getDays() < 30) {
res=true;
}
return res;
}
//Formato cadena
@Override
public String toString() {
return "Serie [fechaEstreno=" + fechaEstreno + ", nombre=" + nombre + ", temporadas=" + temporadas
+ ", episodios=" + episodios + ", ranking=" + ranking + ", actores=" + actores + ", calificacion="
+ calificacion + ", directores=" + directores + ", paises=" + paises + ", genero=" + genero
+ ", puntuacion=" + puntuacion + "]";
}
//Criterio de igualdad
@Override
public int hashCode() {
return Objects.hash(fechaEstreno, genero, nombre);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Serie other = (Serie) obj;
return Objects.equals(fechaEstreno, other.fechaEstreno) && genero == other.genero
&& Objects.equals(nombre, other.nombre);
}
//Criterio de orden natural
public int compareTo(Serie o) {
int res = getNombre().compareTo(o.getNombre());
if (res == 0) {
res = getGenero().compareTo(getGenero());
}if(res==0) {
res= getFechaEstreno().compareTo(getFechaEstreno());
}
return res;
}
}
Editor is loading...