G
Gelöschtes Mitglied 62813
Gast
Wie kann man den Code am besten kürzen?
Java:
public class AlbumComparator implements Comparator<AudioFile> {
public int compare(AudioFile af1, AudioFile af2) {
if (af1 == null || af2 == null) {
throw new NullPointerException("Ein Objekt existiert nicht!");
}
else if (af1 instanceof TaggedFile && af2 instanceof TaggedFile) {
TaggedFile tf1 = (TaggedFile) af1;
TaggedFile tf2 = (TaggedFile) af2;
String alb1 = tf1.getAlbum();
String alb2 = tf2.getAlbum();
if (alb1 == null && alb2 == null) {
return 0;
}
else if (alb1 != null && alb2 == null) {
return 1;
}
else if (alb1 == null && alb2 != null) {
return -1;
}
else {
return alb1.compareTo(alb2);
}
}
else if (af1 instanceof TaggedFile && !(af2 instanceof TaggedFile)) {
return 1;
}
else if (!(af1 instanceof TaggedFile) && af2 instanceof TaggedFile) {
return -1;
}
else {
return 0;
}
}
}