import java.util.*; public class Recording implements Comparable { private final int year; private final String artist; private final String title; private final String type; private final Set genre; public Recording(String title, String artist, int year, String type, Set genre) { this.title = title; this.year = year; this.artist = artist; this.type = type; this.genre = genre; } public String getArtist() { return artist; } public Collection 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 getArtistCmp(){ return new ArtistCmp(); } public static Comparator getTitleCmp(){ return Comparator.comparing(Recording::getTitle); } public static Comparator getYearCmp(){ return Comparator.comparing(Recording::getYear); } private static class ArtistCmp implements Comparator{ public int compare(Recording r1, Recording r2) { return r1.getArtist().compareTo(r2.getArtist()); } } }