Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Comparable;
- import java.text.DecimalFormat;
- import java.util.Objects;
- @SuppressWarnings("rawtypes")
- public class Videos implements Comparable{
- DecimalFormat df = new DecimalFormat("#.00");
- private String id;
- private String titulo;
- private String creador;
- private float duracion;
- public Videos() {
- }
- public Videos (String id, String titulo, String creador , float duracion){
- this.id = id;
- this.titulo = titulo;
- this.creador = creador;
- this.duracion = duracion;
- }
- @Override
- public String toString() {
- return "Video [id=" + id + ", titulo=" + titulo + ", creador=" + creador + ", duracion=" + df.format(getDuracion()) + "]"+"\n";
- }
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getTitulo() {
- return titulo;
- }
- public void setTitulo(String titulo) {
- this.titulo = titulo;
- }
- public String getCreador() {
- return creador;
- }
- public void setCreador(String creador) {
- this.creador = creador;
- }
- public float getDuracion() {
- return duracion;
- }
- public void setDuracion(float duracion) {
- this.duracion = duracion;
- }
- public boolean equals(Object obj) {
- if (this==obj)return true;
- if (obj==null)return false;
- if (getClass() != obj.getClass())return false;
- final Videos otro = (Videos) obj;
- if (!Objects.equals(this.id, otro.getId()))return false;
- return true;
- }
- public int compareTo(Object o) {
- Videos vid = (Videos) o;
- if(this.duracion<vid.getDuracion()) return -1;
- if(this.duracion>vid.getDuracion()) return 1;
- return 0;
- }
- public int compareTitulo(Object o) {
- Videos vid = (Videos) o;
- int titulo1 = 0,titulo2 = 0;
- for(char c: this.titulo.toCharArray()) {
- titulo1 += c;
- }
- for(char c: vid.titulo.toCharArray()) {
- titulo2 += c;
- }
- if(titulo1<titulo2) return -1;
- if(titulo1>titulo2) return 1;
- return 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment