package MusicLandscape.util.comparators;
import MusicLandscape.entities.Track;
import java.util.Comparator;package MusicLandscape.util.comparators;
import MusicLandscape.entities.Track;
import java.util.Comparator;Comparators are quite simple, they only need to implement the
compare(T t1, T t2) method that compares two objects of the
type T.
/**
* Encapsulates the concept of comparing two tracks by writer.
*
* @author Jonas Altrock (ew20b126@technikum-wien.at)
* @version 1
* @since ExerciseSheet05
*/
public class WriterComparator implements Comparator<Track> {
/**
* Compares two tracks by writer.<br>
* The natural ordering of artists is used.
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return a negative integer, zero, or a positive integer as the
* first argument is less than, equal to, or greater than the
* second.
* @throws NullPointerException if an argument is null and this
* comparator does not permit null arguments
* @throws ClassCastException if the arguments' types prevent them from
* being compared by this comparator.
*/
@Override
public int compare(Track o1, Track o2) {We delegate to Artist.compareTo, which we can do because
we implement the Comparable interface there.
return o1.getWriter().compareTo(o2.getWriter());
}
/**
* the string representation is "by writer" (without quotes)
*
* @return a string representation of the object.
*/
@Override
public String toString() {
return "by writer";
}
}