90 lines
1.9 KiB
Java
90 lines
1.9 KiB
Java
import java.util.*;
|
|
|
|
public class Recording implements Comparable<Recording> {
|
|
private final int year;
|
|
private final String artist;
|
|
private final String title;
|
|
private final String type;
|
|
private final Set<String> genre;
|
|
|
|
public Recording(String title, String artist, int year, String type, Set<String> genre) {
|
|
this.title = title;
|
|
this.year = year;
|
|
this.artist = artist;
|
|
this.type = type;
|
|
this.genre = genre;
|
|
}
|
|
|
|
public String getArtist() {
|
|
return artist;
|
|
}
|
|
|
|
public Collection<String> getGenre() {
|
|
return genre;
|
|
}
|
|
|
|
public String getTitle() {
|
|
return title;
|
|
}
|
|
|
|
public String getType() {
|
|
return type;
|
|
}
|
|
|
|
public int getYear() {
|
|
return year;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return String.format("{ %s | %s | %s | %d | %s }", artist, title, genre, year, type);
|
|
}
|
|
|
|
@Override
|
|
public boolean equals(Object other) {
|
|
if (this == other) {
|
|
return true;
|
|
}
|
|
else if (other instanceof Recording){
|
|
Recording r = (Recording) other;
|
|
|
|
return title.equals(r.title) && artist.equals(r.getArtist()) && year == r.getYear();
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
//public int compareTo(Recording other) {
|
|
|
|
//if (artist.compareTo(other.getArtist()) != 0) {
|
|
//return artist.compareTo(other.getArtist());
|
|
//} else if (title.compareTo(other.getTitle()) != 0) {
|
|
//return title.compareTo(other.getTitle());
|
|
//} else {
|
|
//return year - other.getYear();
|
|
//}
|
|
//}
|
|
|
|
@Override
|
|
public int hashCode() {
|
|
return Objects.hash(title, artist, year);
|
|
}
|
|
|
|
public static Comparator<Recording> getArtistCmp(){
|
|
return new ArtistCmp();
|
|
}
|
|
|
|
public static Comparator<Recording> getTitleCmp(){
|
|
return Comparator.comparing(Recording::getTitle);
|
|
}
|
|
|
|
public static Comparator<Recording> getYearCmp(){
|
|
return Comparator.comparing(Recording::getYear);
|
|
}
|
|
|
|
private static class ArtistCmp implements Comparator<Recording>{
|
|
public int compare(Recording r1, Recording r2) {
|
|
return r1.getArtist().compareTo(r2.getArtist());
|
|
}
|
|
}
|
|
} |