49 lines
1.1 KiB
Java
49 lines
1.1 KiB
Java
package com.rubenvandeven.emotionhero;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.google.gson.reflect.TypeToken;
|
|
|
|
import java.lang.reflect.Array;
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Date;
|
|
|
|
/**
|
|
* Created by ruben on 19/08/16.
|
|
*/
|
|
|
|
public class Highscores extends ArrayList<Highscore>{
|
|
|
|
|
|
public static Highscores fromJson(String json) {
|
|
Gson gson = new Gson();
|
|
return gson.fromJson(json, Highscores.class);
|
|
}
|
|
|
|
public String toJson() {
|
|
Gson gson = new Gson();
|
|
return gson.toJson(this);
|
|
}
|
|
|
|
/**
|
|
* Get the n highest scores
|
|
*/
|
|
public ArrayList<Highscore> getTopN(int n) {
|
|
Collections.sort(this, new Comparator<Highscore>() {
|
|
@Override
|
|
public int compare(Highscore score1, Highscore score2)
|
|
{
|
|
return score1.score < score2.score ? -1 : score1.score == score2.score ? 0 : 1;
|
|
}
|
|
});
|
|
return this;
|
|
}
|
|
|
|
// public ArrayList<Highscore> getLastN(int n) {
|
|
//
|
|
// }
|
|
|
|
|
|
}
|