11
11
import com.google.gson.JsonParser;
13
13
public class JsonChannelParser {
15
public final static String FULL_RELEASE = "full";
16
public final static String DELTA_RELEASE = "delta";
18
public enum ReleaseType {
23
// JSON supporting classes
40
* Gather info on all available releases on server
41
* @param jsonStr string holding json data
42
* @param filter type of releases to add to the list
45
static public List<Image> getAvailableReleases(String jsonStr, ReleaseType filter) {
46
LinkedList<Image> releases = new LinkedList<Image>();
48
JsonObject index = new JsonParser().parse(jsonStr).getAsJsonObject();
49
JsonArray images = index.get("images").getAsJsonArray();
50
int size = images.size();
52
for(int j = 0; j < size; j++) {
53
Image image = new Gson().fromJson(images.get(j), Image.class);
54
ReleaseType type = ReleaseType.UNKNOWN;
55
if (FULL_RELEASE.equals(image.type)) {
56
type = ReleaseType.FULL;
57
} else if (DELTA_RELEASE.equals(image.type)) {
58
type = ReleaseType.DELTA;
65
Collections.sort(releases, imageComparator());
69
public static Comparator<Image> imageComparator() {
70
Comparator<Image> imageComparator = new Comparator<Image>(){
72
public int compare(Image o1, Image o2) {
73
return o2.version - o1.version;
76
return imageComparator;
79
public static Comparator<File> fileComparator() {
80
Comparator<File> imageComparator = new Comparator<File>(){
82
public int compare(File f1, File f2) {
83
return f1.order - f2.order;
86
return imageComparator;
15
public final static String FULL_RELEASE = "full";
16
public final static String DELTA_RELEASE = "delta";
18
public enum ReleaseType {
23
// JSON supporting classes
40
* Gather info on all available releases on server
41
* @param jsonStr string holding json data
42
* @param filter type of releases to add to the list
45
static public List<Image> getAvailableReleases(String jsonStr, ReleaseType filter) {
46
LinkedList<Image> releases = new LinkedList<Image>();
48
JsonObject index = new JsonParser().parse(jsonStr).getAsJsonObject();
49
JsonArray images = index.get("images").getAsJsonArray();
50
int size = images.size();
52
for(int j = 0; j < size; j++) {
53
Image image = new Gson().fromJson(images.get(j), Image.class);
54
ReleaseType type = ReleaseType.UNKNOWN;
55
if (FULL_RELEASE.equals(image.type)) {
56
type = ReleaseType.FULL;
57
} else if (DELTA_RELEASE.equals(image.type)) {
58
type = ReleaseType.DELTA;
65
Collections.sort(releases, imageComparator());
69
public static Comparator<Image> imageComparator() {
70
Comparator<Image> imageComparator = new Comparator<Image>(){
72
public int compare(Image o1, Image o2) {
73
return o2.version - o1.version;
76
return imageComparator;
79
public static Comparator<File> fileComparator() {
80
Comparator<File> imageComparator = new Comparator<File>(){
82
public int compare(File f1, File f2) {
83
return f1.order - f2.order;
86
return imageComparator;