From f5a42ac00b68fadc2b6bc05f85780388955113ce Mon Sep 17 00:00:00 2001 From: misaochan Date: Fri, 25 Dec 2015 17:53:12 +1300 Subject: [PATCH] Got categorySet to work categorySet now stores a unique copy of each category found in the query --- .../free/nrw/commons/upload/MwVolleyApi.java | 48 +++++++------------ 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java b/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java index 0ea09f203..470974347 100644 --- a/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java +++ b/commons/src/main/java/fr/free/nrw/commons/upload/MwVolleyApi.java @@ -20,8 +20,6 @@ import com.google.gson.GsonBuilder; import java.io.UnsupportedEncodingException; import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Set; public class MwVolleyApi { @@ -29,13 +27,13 @@ public class MwVolleyApi { private static final Gson GSON = new GsonBuilder().create(); private Context context; - protected HashSet categorySet; + protected static HashSet categorySet; public MwVolleyApi(Context context) { this.context = context; + categorySet = new HashSet(); } - public void request(String coords) { String apiUrl = buildUrl(coords); @@ -75,7 +73,6 @@ public class MwVolleyApi { return builder.toString(); } - private synchronized RequestQueue getQueue() { return getQueue(context); } @@ -122,12 +119,10 @@ public class MwVolleyApi { return Response.success(queryResponse, cacheEntry(response)); } - private Cache.Entry cacheEntry(NetworkResponse response) { return HttpHeaderParser.parseCacheHeaders(response); } - private String parseString(NetworkResponse response) { try { return new String(response.data, HttpHeaderParser.parseCharset(response.headers)); @@ -137,28 +132,27 @@ public class MwVolleyApi { } } - private class QueryResponse { + private static class QueryResponse { private Query query = new Query(); private Page page; - public QueryResponse() { - + private String printSet() { + if (categorySet == null || categorySet.isEmpty()) { + return "No collection of categories"; + } + else { + return categorySet.toString(); + } } - @Override public String toString() { - return "query=" + query.toString() + "\n" //page.printSet() - ; + return "query=" + query.toString() + "\n" + printSet(); } } - private class Query { + private static class Query { private Page [] pages; - public Query() { - - } - @Override public String toString() { StringBuilder builder = new StringBuilder("pages=" + "\n"); @@ -168,7 +162,6 @@ public class MwVolleyApi { } builder.replace(builder.length() - 1, builder.length(), ""); - if (categorySet == null || categorySet.isEmpty()) { Log.d("Set", "No category set"); } @@ -181,7 +174,7 @@ public class MwVolleyApi { } } - private class Page { + private static class Page { private int pageid; private int ns; private String title; @@ -190,18 +183,9 @@ public class MwVolleyApi { - private String printSet() { - if (categorySet == null || categorySet.isEmpty()) { - return "No collection of categories"; - } - else { - return categorySet.toString(); - } - } - @Override public String toString() { - categorySet = new HashSet(); + StringBuilder builder = new StringBuilder("PAGEID=" + pageid + " ns=" + ns + " title=" + title + "\n" + " CATEGORIES= "); if (categories == null || categories.length == 0) { @@ -211,8 +195,10 @@ public class MwVolleyApi { for (Category category : categories) { builder.append(category.toString()); builder.append("\n"); - if (category != null && category.toString() != null && category.toString() != "") { + if (category != null) { categorySet.add(category.toString()); + Log.d("Set", "category added: " + category.toString()); + Log.d("Set", categorySet.toString()); } } }