I'm trying to sort a list of music by revelance corresponding to a list of criteria.
public class Music implements Comparable<CriteriaList> {
private String genre, artist, album, titre, price, note;
// getters, setters
public int compareTo(CriteriaList list) {
boolean title, album, genre, artist, note;
title = !list.getTitle().isEmpty() && this.getTitre().equals(list.getTitle());
album = !list.getAlbum().isEmpty() && this.getAlbum().equals(list.getAlbum());
genre = !list.getGenre().isEmpty() && this.getGenre().equals(list.getGenre());
artist = !list.getArtist().isEmpty() && this.getArtist().equals(list.getArtist());
note = !list.getNote().isEmpty() && (Integer.parseInt(this.getNote()) >= Integer.parseInt(list.getNote()));
return ((title ? 1 : 0) + (album ? 1 : 0) + (genre ? 1 : 0) + (artist ? 1 : 0) + (note ? 1 : 0));
}
}
My function compareTo return the number of fields which match to the criteria list and test if input are not empty.
public class MusicProvider extends Agent {
public List<Music> getMusicsByCL(CriteriaList list) {
ArrayList<Music> res = new ArrayList<Music>();
int[] revelanceTab = new int[res.size()];
int i = 0, revelance;
for (Music music : musicListAvailable) {
revelance = music.compareTo(list);
if (revelance > 1) {
res.add(music);
revelanceTab[++i] = revelance;
}
}
// sort res with revelanceTab
return res;
}
}
Here I want to retrieve musics with a minimun revelance of 1 and sort them by revelance. How can I do that ?