From 92e4f004e65aa6fa5cc47ef1137a71083506c33d Mon Sep 17 00:00:00 2001 From: John Carlson Date: Tue, 11 Apr 2017 23:45:10 -0500 Subject: [PATCH 1/7] Remove unused method in ParseHttpClient --- .../main/java/com/parse/ParseHttpClient.java | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-) diff --git a/Parse/src/main/java/com/parse/ParseHttpClient.java b/Parse/src/main/java/com/parse/ParseHttpClient.java index 2592c6bb1..2d8b3cb48 100644 --- a/Parse/src/main/java/com/parse/ParseHttpClient.java +++ b/Parse/src/main/java/com/parse/ParseHttpClient.java @@ -17,7 +17,6 @@ import java.io.IOException; import java.io.InputStream; import java.util.HashMap; -import java.util.List; import java.util.Map; import okhttp3.Call; @@ -78,7 +77,7 @@ public final ParseHttpResponse execute(ParseHttpRequest request) throws IOExcept return executeInternal(request); } - ParseHttpResponse executeInternal(ParseHttpRequest parseRequest) throws IOException { + private ParseHttpResponse executeInternal(ParseHttpRequest parseRequest) throws IOException { Request okHttpRequest = getRequest(parseRequest); Call okHttpCall = okHttpClient.newCall(okHttpRequest); @@ -174,44 +173,6 @@ Request getRequest(ParseHttpRequest parseRequest) throws IOException { return okHttpRequestBuilder.build(); } - private ParseHttpRequest getParseHttpRequest(Request okHttpRequest) { - ParseHttpRequest.Builder parseRequestBuilder = new ParseHttpRequest.Builder(); - // Set method - switch (okHttpRequest.method()) { - case OKHTTP_GET: - parseRequestBuilder.setMethod(ParseHttpRequest.Method.GET); - break; - case OKHTTP_DELETE: - parseRequestBuilder.setMethod(ParseHttpRequest.Method.DELETE); - break; - case OKHTTP_POST: - parseRequestBuilder.setMethod(ParseHttpRequest.Method.POST); - break; - case OKHTTP_PUT: - parseRequestBuilder.setMethod(ParseHttpRequest.Method.PUT); - break; - default: - // This should never happen - throw new IllegalArgumentException( - "Invalid http method " + okHttpRequest.method()); - } - - // Set url - parseRequestBuilder.setUrl(okHttpRequest.url().toString()); - - // Set Header - for (Map.Entry> entry : okHttpRequest.headers().toMultimap().entrySet()) { - parseRequestBuilder.addHeader(entry.getKey(), entry.getValue().get(0)); - } - - // Set Body - ParseOkHttpRequestBody okHttpBody = (ParseOkHttpRequestBody) okHttpRequest.body(); - if (okHttpBody != null) { - parseRequestBuilder.setBody(okHttpBody.getParseHttpBody()); - } - return parseRequestBuilder.build(); - } - private static class ParseOkHttpRequestBody extends RequestBody { private ParseHttpBody parseBody; From 345b922b8eb4f54cab914d801be44ad88fe84ec8 Mon Sep 17 00:00:00 2001 From: John Carlson Date: Tue, 11 Apr 2017 23:45:44 -0500 Subject: [PATCH 2/7] Remove redundant access modifiers on interfaces --- Parse/src/main/java/com/parse/ConfigCallback.java | 2 +- Parse/src/main/java/com/parse/CountCallback.java | 2 +- Parse/src/main/java/com/parse/DeleteCallback.java | 2 +- Parse/src/main/java/com/parse/FindCallback.java | 2 +- Parse/src/main/java/com/parse/FunctionCallback.java | 2 +- Parse/src/main/java/com/parse/GetCallback.java | 2 +- Parse/src/main/java/com/parse/GetDataCallback.java | 2 +- Parse/src/main/java/com/parse/GetDataStreamCallback.java | 2 +- Parse/src/main/java/com/parse/GetFileCallback.java | 2 +- Parse/src/main/java/com/parse/LocationCallback.java | 2 +- Parse/src/main/java/com/parse/LogInCallback.java | 2 +- Parse/src/main/java/com/parse/LogOutCallback.java | 2 +- Parse/src/main/java/com/parse/ParseCallback1.java | 2 +- Parse/src/main/java/com/parse/ParseCallback2.java | 2 +- Parse/src/main/java/com/parse/ParseQueryController.java | 6 +++--- Parse/src/main/java/com/parse/ProgressCallback.java | 2 +- Parse/src/main/java/com/parse/RefreshCallback.java | 2 +- .../main/java/com/parse/RequestPasswordResetCallback.java | 2 +- Parse/src/main/java/com/parse/SaveCallback.java | 2 +- Parse/src/main/java/com/parse/SendCallback.java | 2 +- Parse/src/main/java/com/parse/SignUpCallback.java | 2 +- 21 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Parse/src/main/java/com/parse/ConfigCallback.java b/Parse/src/main/java/com/parse/ConfigCallback.java index 90827a783..2a84d4f50 100644 --- a/Parse/src/main/java/com/parse/ConfigCallback.java +++ b/Parse/src/main/java/com/parse/ConfigCallback.java @@ -40,5 +40,5 @@ public interface ConfigCallback extends ParseCallback2 { * The exception raised by the delete, or {@code null} if it succeeded. */ @Override - public void done(ParseException e); + void done(ParseException e); } diff --git a/Parse/src/main/java/com/parse/FindCallback.java b/Parse/src/main/java/com/parse/FindCallback.java index 8a1ad87c4..a5ebff394 100644 --- a/Parse/src/main/java/com/parse/FindCallback.java +++ b/Parse/src/main/java/com/parse/FindCallback.java @@ -45,5 +45,5 @@ public interface FindCallback extends ParseCallback2 objects, ParseException e); + void done(List objects, ParseException e); } diff --git a/Parse/src/main/java/com/parse/FunctionCallback.java b/Parse/src/main/java/com/parse/FunctionCallback.java index 5e6fcaa0b..7a6269341 100644 --- a/Parse/src/main/java/com/parse/FunctionCallback.java +++ b/Parse/src/main/java/com/parse/FunctionCallback.java @@ -45,5 +45,5 @@ public interface FunctionCallback extends ParseCallback2 { * The exception raised by the cloud call, or {@code null} if it succeeded. */ @Override - public void done(T object, ParseException e); + void done(T object, ParseException e); } diff --git a/Parse/src/main/java/com/parse/GetCallback.java b/Parse/src/main/java/com/parse/GetCallback.java index a1cc00bdb..cc3207121 100644 --- a/Parse/src/main/java/com/parse/GetCallback.java +++ b/Parse/src/main/java/com/parse/GetCallback.java @@ -43,5 +43,5 @@ public interface GetCallback extends ParseCallback2 * The exception raised by the fetch, or {@code null} if it succeeded. */ @Override - public void done(byte[] data, ParseException e); + void done(byte[] data, ParseException e); } diff --git a/Parse/src/main/java/com/parse/GetDataStreamCallback.java b/Parse/src/main/java/com/parse/GetDataStreamCallback.java index aee829ba6..cfdd8598a 100644 --- a/Parse/src/main/java/com/parse/GetDataStreamCallback.java +++ b/Parse/src/main/java/com/parse/GetDataStreamCallback.java @@ -37,5 +37,5 @@ public interface GetDataStreamCallback extends ParseCallback2 { * The exception raised by the fetch, or {@code null} if it succeeded. */ @Override - public void done(File file, ParseException e); + void done(File file, ParseException e); } diff --git a/Parse/src/main/java/com/parse/LocationCallback.java b/Parse/src/main/java/com/parse/LocationCallback.java index ce18f0fda..ef6d1f62f 100644 --- a/Parse/src/main/java/com/parse/LocationCallback.java +++ b/Parse/src/main/java/com/parse/LocationCallback.java @@ -44,5 +44,5 @@ public interface LocationCallback extends ParseCallback2 * The exception raised by the login, or {@code null} if it succeeded. */ @Override - public void done(ParseUser user, ParseException e); + void done(ParseUser user, ParseException e); } diff --git a/Parse/src/main/java/com/parse/LogOutCallback.java b/Parse/src/main/java/com/parse/LogOutCallback.java index eea7f9f84..7c7a8f79c 100644 --- a/Parse/src/main/java/com/parse/LogOutCallback.java +++ b/Parse/src/main/java/com/parse/LogOutCallback.java @@ -39,5 +39,5 @@ public interface LogOutCallback extends ParseCallback1 { * The exception raised by the log out, or {@code null} if it succeeded. */ @Override - public void done(ParseException e); + void done(ParseException e); } diff --git a/Parse/src/main/java/com/parse/ParseCallback1.java b/Parse/src/main/java/com/parse/ParseCallback1.java index bd71ab1b9..61c9a688d 100644 --- a/Parse/src/main/java/com/parse/ParseCallback1.java +++ b/Parse/src/main/java/com/parse/ParseCallback1.java @@ -25,5 +25,5 @@ * @param t * Generally an {@link Throwable} that was thrown by the operation, if there was any. */ - public void done(T t); + void done(T t); } diff --git a/Parse/src/main/java/com/parse/ParseCallback2.java b/Parse/src/main/java/com/parse/ParseCallback2.java index 4ad1b43e6..9b142078b 100644 --- a/Parse/src/main/java/com/parse/ParseCallback2.java +++ b/Parse/src/main/java/com/parse/ParseCallback2.java @@ -28,5 +28,5 @@ * @param t2 * Generally an {@link Throwable} that was thrown by the operation, if there was any. */ - public void done(T1 t1, T2 t2); + void done(T1 t1, T2 t2); } diff --git a/Parse/src/main/java/com/parse/ParseQueryController.java b/Parse/src/main/java/com/parse/ParseQueryController.java index 991cd05d4..3b5849c6e 100644 --- a/Parse/src/main/java/com/parse/ParseQueryController.java +++ b/Parse/src/main/java/com/parse/ParseQueryController.java @@ -24,7 +24,7 @@ * @param cancellationToken Cancellation token. * @return A {@link Task} that resolves to the results of the find. */ - public Task> findAsync(ParseQuery.State state, ParseUser user, + Task> findAsync(ParseQuery.State state, ParseUser user, Task cancellationToken); /** @@ -34,7 +34,7 @@ public Task> findAsync(ParseQuery.State state * @param cancellationToken Cancellation token. * @return A {@link Task} that resolves to the results of the count. */ - public Task countAsync(ParseQuery.State state, ParseUser user, + Task countAsync(ParseQuery.State state, ParseUser user, Task cancellationToken); /** @@ -46,6 +46,6 @@ public Task countAsync(ParseQuery.State stat * there is at least one result or {@link ParseException#OBJECT_NOT_FOUND} if there are no * results. */ - public Task getFirstAsync(ParseQuery.State state, ParseUser user, + Task getFirstAsync(ParseQuery.State state, ParseUser user, Task cancellationToken); } diff --git a/Parse/src/main/java/com/parse/ProgressCallback.java b/Parse/src/main/java/com/parse/ProgressCallback.java index 67ea45d9e..18f760ce4 100644 --- a/Parse/src/main/java/com/parse/ProgressCallback.java +++ b/Parse/src/main/java/com/parse/ProgressCallback.java @@ -20,5 +20,5 @@ public interface ProgressCallback { /** * Override this function with your desired callback. */ - public void done(Integer percentDone); + void done(Integer percentDone); } diff --git a/Parse/src/main/java/com/parse/RefreshCallback.java b/Parse/src/main/java/com/parse/RefreshCallback.java index 7e932c853..75612286d 100644 --- a/Parse/src/main/java/com/parse/RefreshCallback.java +++ b/Parse/src/main/java/com/parse/RefreshCallback.java @@ -43,5 +43,5 @@ public interface RefreshCallback extends ParseCallback2 { * The exception raised by the save, or {@code null} if it succeeded. */ @Override - public void done(ParseException e); + void done(ParseException e); } diff --git a/Parse/src/main/java/com/parse/SendCallback.java b/Parse/src/main/java/com/parse/SendCallback.java index ec48080b4..afe2ecd7c 100644 --- a/Parse/src/main/java/com/parse/SendCallback.java +++ b/Parse/src/main/java/com/parse/SendCallback.java @@ -43,5 +43,5 @@ public interface SendCallback extends ParseCallback1 { * The exception raised by the send, or {@code null} if it succeeded. */ @Override - public void done(ParseException e); + void done(ParseException e); } diff --git a/Parse/src/main/java/com/parse/SignUpCallback.java b/Parse/src/main/java/com/parse/SignUpCallback.java index 0b2fb5e3f..6f3cd7c10 100644 --- a/Parse/src/main/java/com/parse/SignUpCallback.java +++ b/Parse/src/main/java/com/parse/SignUpCallback.java @@ -41,5 +41,5 @@ public interface SignUpCallback extends ParseCallback1 { * The exception raised by the signUp, or {@code null} if it succeeded. */ @Override - public void done(ParseException e); + void done(ParseException e); } From ea5a98ff242aaeae543222476fcc7a0c6fbd26fa Mon Sep 17 00:00:00 2001 From: John Carlson Date: Wed, 12 Apr 2017 00:22:59 -0500 Subject: [PATCH 3/7] Collapse Exceptions --- Parse/src/main/java/com/parse/Parse.java | 9 --------- Parse/src/main/java/com/parse/ParseKeyValueCache.java | 5 ----- .../main/java/com/parse/ParseRESTObjectBatchCommand.java | 4 +--- 3 files changed, 1 insertion(+), 17 deletions(-) diff --git a/Parse/src/main/java/com/parse/Parse.java b/Parse/src/main/java/com/parse/Parse.java index 077f91ef0..a66b98e0c 100644 --- a/Parse/src/main/java/com/parse/Parse.java +++ b/Parse/src/main/java/com/parse/Parse.java @@ -15,11 +15,9 @@ import android.util.Log; import java.io.File; -import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.RandomAccessFile; -import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; import java.util.HashSet; @@ -545,8 +543,6 @@ static void checkCacheApplicationId() { f.close(); String diskApplicationId = new String(bytes, "UTF-8"); matches = diskApplicationId.equals(applicationId); - } catch (FileNotFoundException e) { - // Well, it existed a minute ago. Let's assume it doesn't match. } catch (IOException e) { // Hmm, the applicationId file was malformed or something. Assume it // doesn't match. @@ -568,11 +564,6 @@ static void checkCacheApplicationId() { FileOutputStream out = new FileOutputStream(applicationIdFile); out.write(applicationId.getBytes("UTF-8")); out.close(); - } catch (FileNotFoundException e) { - // Nothing we can really do about it. - } catch (UnsupportedEncodingException e) { - // Nothing we can really do about it. This would mean Java doesn't - // understand UTF-8, which is unlikely. } catch (IOException e) { // Nothing we can really do about it. } diff --git a/Parse/src/main/java/com/parse/ParseKeyValueCache.java b/Parse/src/main/java/com/parse/ParseKeyValueCache.java index 70c68deb1..3441ad9da 100644 --- a/Parse/src/main/java/com/parse/ParseKeyValueCache.java +++ b/Parse/src/main/java/com/parse/ParseKeyValueCache.java @@ -12,14 +12,11 @@ import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONTokener; import java.io.File; -import java.io.FileOutputStream; import java.io.FilenameFilter; import java.io.IOException; import java.io.RandomAccessFile; -import java.io.UnsupportedEncodingException; import java.util.Arrays; import java.util.Comparator; import java.util.Date; @@ -135,8 +132,6 @@ private static File createKeyValueCacheFile(String key) { File f = createKeyValueCacheFile(key); try { ParseFileUtils.writeByteArrayToFile(f, value.getBytes("UTF-8")); - } catch (UnsupportedEncodingException e) { - // do nothing } catch (IOException e) { // do nothing } diff --git a/Parse/src/main/java/com/parse/ParseRESTObjectBatchCommand.java b/Parse/src/main/java/com/parse/ParseRESTObjectBatchCommand.java index 4ad74630f..4fcaafa96 100644 --- a/Parse/src/main/java/com/parse/ParseRESTObjectBatchCommand.java +++ b/Parse/src/main/java/com/parse/ParseRESTObjectBatchCommand.java @@ -74,9 +74,7 @@ public static List> executeBatch( requests.put(requestParameters); } parameters.put("requests", requests); - } catch (JSONException e) { - throw new RuntimeException(e); - } catch (MalformedURLException e) { + } catch (JSONException | MalformedURLException e) { throw new RuntimeException(e); } From a450535212d26df67d5e8ed961a3750ffc17f809 Mon Sep 17 00:00:00 2001 From: John Carlson Date: Wed, 12 Apr 2017 00:24:31 -0500 Subject: [PATCH 4/7] Remove redundant typing --- Parse/src/main/java/com/parse/LocationNotifier.java | 2 +- Parse/src/main/java/com/parse/LockSet.java | 4 ++-- Parse/src/main/java/com/parse/ParseCommandCache.java | 2 +- Parse/src/main/java/com/parse/ParseQuery.java | 4 ++-- Parse/src/main/java/com/parse/ParseTraverser.java | 10 +++++----- Parse/src/main/java/com/parse/PushHistory.java | 12 ++++++------ Parse/src/main/java/com/parse/WeakValueHashMap.java | 4 ++-- .../src/test/java/com/parse/ParsePushStateTest.java | 4 ++-- Parse/src/test/java/com/parse/ParseQueryTest.java | 8 ++++---- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Parse/src/main/java/com/parse/LocationNotifier.java b/Parse/src/main/java/com/parse/LocationNotifier.java index 3c87941cc..d4661cf56 100644 --- a/Parse/src/main/java/com/parse/LocationNotifier.java +++ b/Parse/src/main/java/com/parse/LocationNotifier.java @@ -60,7 +60,7 @@ /* package */ static Task getCurrentLocationAsync(Context context, long timeout, Criteria criteria) { final TaskCompletionSource tcs = new TaskCompletionSource<>(); - final Capture> timeoutFuture = new Capture>(); + final Capture> timeoutFuture = new Capture<>(); final LocationManager manager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); final LocationListener listener = new LocationListener() { diff --git a/Parse/src/main/java/com/parse/LockSet.java b/Parse/src/main/java/com/parse/LockSet.java index 29d69e09a..593990a3a 100644 --- a/Parse/src/main/java/com/parse/LockSet.java +++ b/Parse/src/main/java/com/parse/LockSet.java @@ -16,13 +16,13 @@ import java.util.concurrent.locks.Lock; /** package */ class LockSet { - private static WeakHashMap stableIds = new WeakHashMap(); + private static final WeakHashMap stableIds = new WeakHashMap<>(); private static long nextStableId = 0L; private final Set locks; public LockSet(Collection locks) { - this.locks = new TreeSet(new Comparator() { + this.locks = new TreeSet<>(new Comparator() { @Override public int compare(Lock lhs, Lock rhs) { Long lhsId = getStableId(lhs); diff --git a/Parse/src/main/java/com/parse/ParseCommandCache.java b/Parse/src/main/java/com/parse/ParseCommandCache.java index 452ea34c3..4cdf5d3d5 100644 --- a/Parse/src/main/java/com/parse/ParseCommandCache.java +++ b/Parse/src/main/java/com/parse/ParseCommandCache.java @@ -437,7 +437,7 @@ public void setConnected(boolean connected) { */ private T waitForTaskWithoutLock(Task task) throws ParseException { synchronized (lock) { - final Capture finished = new Capture(false); + final Capture finished = new Capture<>(false); task.continueWith(new Continuation() { @Override public Void then(Task task) throws Exception { diff --git a/Parse/src/main/java/com/parse/ParseQuery.java b/Parse/src/main/java/com/parse/ParseQuery.java index 9cc1b2dee..c255e1d9f 100644 --- a/Parse/src/main/java/com/parse/ParseQuery.java +++ b/Parse/src/main/java/com/parse/ParseQuery.java @@ -1314,7 +1314,7 @@ public int count() throws ParseException { * @return A {@link Task} that will be resolved when the count has completed. */ public Task countInBackground() { - State.Builder copy = new State.Builder(builder); + State.Builder copy = new State.Builder<>(builder); final State state = copy.setLimit(0).build(); return countAsync(state); } @@ -1327,7 +1327,7 @@ public Task countInBackground() { * callback.done(count, e) will be called when the count completes. */ public void countInBackground(final CountCallback callback) { - State.Builder copy = new State.Builder(builder); + State.Builder copy = new State.Builder<>(builder); final State state = copy.setLimit(0).build(); // Hack to workaround CountCallback's non-uniform signature. diff --git a/Parse/src/main/java/com/parse/ParseTraverser.java b/Parse/src/main/java/com/parse/ParseTraverser.java index c92116b6e..5a8d30f05 100644 --- a/Parse/src/main/java/com/parse/ParseTraverser.java +++ b/Parse/src/main/java/com/parse/ParseTraverser.java @@ -8,15 +8,15 @@ */ package com.parse; +import org.json.JSONArray; +import org.json.JSONException; +import org.json.JSONObject; + import java.util.IdentityHashMap; import java.util.Iterator; import java.util.List; import java.util.Map; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - /** * Subclass ParseTraverser to make an function to be run recursively on every object pointed to on * the given object. @@ -133,7 +133,7 @@ public ParseTraverser setYieldRoot(boolean newValue) { * Causes the traverser to traverse all objects pointed to by root, recursively. */ public void traverse(Object root) { - IdentityHashMap seen = new IdentityHashMap(); + IdentityHashMap seen = new IdentityHashMap<>(); traverseInternal(root, yieldRoot, seen); } } diff --git a/Parse/src/main/java/com/parse/PushHistory.java b/Parse/src/main/java/com/parse/PushHistory.java index 6980d5877..56fcd8c37 100644 --- a/Parse/src/main/java/com/parse/PushHistory.java +++ b/Parse/src/main/java/com/parse/PushHistory.java @@ -8,13 +8,13 @@ */ package com.parse; +import org.json.JSONException; +import org.json.JSONObject; + import java.util.HashSet; import java.util.Iterator; import java.util.PriorityQueue; -import org.json.JSONException; -import org.json.JSONObject; - /** * PushHistory manages a fixed-length history of pushes received. It is used by to dedup recently * received messages, as well as keep track of a last received timestamp that is included in PPNS @@ -60,8 +60,8 @@ public int compareTo(Entry other) { */ public PushHistory(int maxHistoryLength, JSONObject json) { this.maxHistoryLength = maxHistoryLength; - this.entries = new PriorityQueue(maxHistoryLength + 1); - this.pushIds = new HashSet(maxHistoryLength + 1); + this.entries = new PriorityQueue<>(maxHistoryLength + 1); + this.pushIds = new HashSet<>(maxHistoryLength + 1); this.lastTime = null; if (json != null) { @@ -69,7 +69,7 @@ public PushHistory(int maxHistoryLength, JSONObject json) { if (jsonHistory != null) { Iterator it = jsonHistory.keys(); while (it.hasNext()) { - String pushId = (String)it.next(); + String pushId = it.next(); String timestamp = jsonHistory.optString(pushId, null); if (pushId != null && timestamp != null) { diff --git a/Parse/src/main/java/com/parse/WeakValueHashMap.java b/Parse/src/main/java/com/parse/WeakValueHashMap.java index 892f5b6a5..230c519eb 100644 --- a/Parse/src/main/java/com/parse/WeakValueHashMap.java +++ b/Parse/src/main/java/com/parse/WeakValueHashMap.java @@ -18,11 +18,11 @@ private HashMap> map; public WeakValueHashMap() { - map = new HashMap>(); + map = new HashMap<>(); } public void put(K key, V value) { - map.put(key, new WeakReference(value)); + map.put(key, new WeakReference<>(value)); } /** diff --git a/Parse/src/test/java/com/parse/ParsePushStateTest.java b/Parse/src/test/java/com/parse/ParsePushStateTest.java index 34aa03542..d40aac9b8 100644 --- a/Parse/src/test/java/com/parse/ParsePushStateTest.java +++ b/Parse/src/test/java/com/parse/ParsePushStateTest.java @@ -166,7 +166,7 @@ public void testChannelSetNullChannelSet() { @Test(expected = IllegalArgumentException.class) public void testChannelSetNormalChannelSetWithNullChannel() { ParsePush.State.Builder builder = new ParsePush.State.Builder(); - Set channelSet = new HashSet<>();; + Set channelSet = new HashSet<>(); channelSet.add(null); ParsePush.State state = builder @@ -178,7 +178,7 @@ public void testChannelSetNormalChannelSetWithNullChannel() { @Test public void testChannelSetNormalChannelSet() { ParsePush.State.Builder builder = new ParsePush.State.Builder(); - Set channelSet = new HashSet<>();; + Set channelSet = new HashSet<>(); channelSet.add("foo"); channelSet.add("bar"); diff --git a/Parse/src/test/java/com/parse/ParseQueryTest.java b/Parse/src/test/java/com/parse/ParseQueryTest.java index b80547ed8..0ef99d37b 100644 --- a/Parse/src/test/java/com/parse/ParseQueryTest.java +++ b/Parse/src/test/java/com/parse/ParseQueryTest.java @@ -182,7 +182,7 @@ public void testCountLimitReset() throws ParseException { when(controller.countAsync( any(ParseQuery.State.class), any(ParseUser.class), - any(Task.class))).thenReturn(Task.forResult(0)); + any(Task.class))).thenReturn(Task.forResult(0)); final ParseQuery query = ParseQuery.getQuery("TestObject"); @@ -198,7 +198,7 @@ public void testCountWithCallbackLimitReset() throws ParseException { when(controller.countAsync( any(ParseQuery.State.class), any(ParseUser.class), - any(Task.class))).thenReturn(Task.forResult(0)); + any(Task.class))).thenReturn(Task.forResult(0)); final ParseQuery query = ParseQuery.getQuery("TestObject"); @@ -213,7 +213,7 @@ public void testCountLimit() throws ParseException { when(controller.countAsync( any(ParseQuery.State.class), any(ParseUser.class), - any(Task.class))).thenReturn(Task.forResult(0)); + any(Task.class))).thenReturn(Task.forResult(0)); ArgumentCaptor state = ArgumentCaptor.forClass(ParseQuery.State.class); @@ -230,7 +230,7 @@ public void testCountWithCallbackLimit() throws ParseException { when(controller.countAsync( any(ParseQuery.State.class), any(ParseUser.class), - any(Task.class))).thenReturn(Task.forResult(0)); + any(Task.class))).thenReturn(Task.forResult(0)); ArgumentCaptor state = ArgumentCaptor.forClass(ParseQuery.State.class); From b597a2fe1ae31cf1334b234670194b1a3603d84f Mon Sep 17 00:00:00 2001 From: John Carlson Date: Wed, 12 Apr 2017 00:25:05 -0500 Subject: [PATCH 5/7] Remove redundant casting --- Parse/src/main/java/com/parse/NotificationCompat.java | 4 ++-- Parse/src/main/java/com/parse/OfflineStore.java | 2 +- Parse/src/main/java/com/parse/ParseCountingFileHttpBody.java | 2 +- Parse/src/main/java/com/parse/ParseObject.java | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Parse/src/main/java/com/parse/NotificationCompat.java b/Parse/src/main/java/com/parse/NotificationCompat.java index fea56c095..1fa4ac9ff 100644 --- a/Parse/src/main/java/com/parse/NotificationCompat.java +++ b/Parse/src/main/java/com/parse/NotificationCompat.java @@ -314,7 +314,7 @@ public Builder setStyle(Style style) { */ @Deprecated public Notification getNotification() { - return (Notification) IMPL.build(this); + return IMPL.build(this); } /** @@ -322,7 +322,7 @@ public Notification getNotification() { * object. */ public Notification build() { - return (Notification) IMPL.build(this); + return IMPL.build(this); } protected static CharSequence limitCharSequenceLength(CharSequence cs) { diff --git a/Parse/src/main/java/com/parse/OfflineStore.java b/Parse/src/main/java/com/parse/OfflineStore.java index 38ba345fd..233a784b5 100644 --- a/Parse/src/main/java/com/parse/OfflineStore.java +++ b/Parse/src/main/java/com/parse/OfflineStore.java @@ -106,7 +106,7 @@ public Task then(Task ignore) throws Exception { } } tasks.clear(); - return Task.forResult((Void) null); + return Task.forResult(null); } } }); diff --git a/Parse/src/main/java/com/parse/ParseCountingFileHttpBody.java b/Parse/src/main/java/com/parse/ParseCountingFileHttpBody.java index 725836419..3ae984d71 100644 --- a/Parse/src/main/java/com/parse/ParseCountingFileHttpBody.java +++ b/Parse/src/main/java/com/parse/ParseCountingFileHttpBody.java @@ -36,7 +36,7 @@ public void writeTo(OutputStream output) throws IOException { throw new IllegalArgumentException("Output stream may not be null"); } - final FileInputStream fileInput = new FileInputStream(file);; + final FileInputStream fileInput = new FileInputStream(file); try { byte[] buffer = new byte[DEFAULT_CHUNK_SIZE]; int n; diff --git a/Parse/src/main/java/com/parse/ParseObject.java b/Parse/src/main/java/com/parse/ParseObject.java index 23dbd778c..8cb06c90a 100644 --- a/Parse/src/main/java/com/parse/ParseObject.java +++ b/Parse/src/main/java/com/parse/ParseObject.java @@ -1363,7 +1363,7 @@ private ParseRESTObjectCommand currentSaveEventuallyCommand( */ /* package */ Task handleSaveResultAsync( final ParseObject.State result, final ParseOperationSet operationsBeforeSave) { - Task task = Task.forResult((Void) null); + Task task = Task.forResult(null); final boolean success = result != null; synchronized (mutex) { @@ -1875,7 +1875,7 @@ public Task then(Task task) throws Exception { * Should only be called on success. */ /* package */ Task handleFetchResultAsync(final ParseObject.State result) { - Task task = Task.forResult((Void) null); + Task task = Task.forResult(null); /* * If this object is in the offline store, then we need to make sure that we pull in any dirty From f5295e25cb659aed909801761950dfbc18ed66df Mon Sep 17 00:00:00 2001 From: John Carlson Date: Wed, 12 Apr 2017 00:25:44 -0500 Subject: [PATCH 6/7] Simplify some boolean logic, access static methods via static class --- .../src/main/java/com/parse/ManifestInfo.java | 2 +- .../main/java/com/parse/ParseFileUtils.java | 18 ++++++---------- Parse/src/main/java/com/parse/PushRouter.java | 2 +- .../com/parse/ParseFileControllerTest.java | 2 +- .../test/java/com/parse/ParsePushTest.java | 21 +++++++------------ .../src/main/AndroidManifest.xml | 2 +- .../src/main/res/values/strings.xml | 1 - 7 files changed, 18 insertions(+), 30 deletions(-) diff --git a/Parse/src/main/java/com/parse/ManifestInfo.java b/Parse/src/main/java/com/parse/ManifestInfo.java index 96451570e..7862ed792 100644 --- a/Parse/src/main/java/com/parse/ManifestInfo.java +++ b/Parse/src/main/java/com/parse/ManifestInfo.java @@ -463,7 +463,7 @@ private static boolean hasAnyGcmSpecificDeclaration() { } private static boolean isGooglePlayServicesAvailable() { - return Build.VERSION.SDK_INT >= 8 && getPackageInfo("com.google.android.gsf") != null; + return getPackageInfo("com.google.android.gsf") != null; } private static ManifestCheckResult gcmSupportLevel() { diff --git a/Parse/src/main/java/com/parse/ParseFileUtils.java b/Parse/src/main/java/com/parse/ParseFileUtils.java index e5afaec35..7510b1ad5 100644 --- a/Parse/src/main/java/com/parse/ParseFileUtils.java +++ b/Parse/src/main/java/com/parse/ParseFileUtils.java @@ -92,7 +92,7 @@ public static FileInputStream openInputStream(File file) throws IOException { if (file.isDirectory()) { throw new IOException("File '" + file + "' exists but is a directory"); } - if (file.canRead() == false) { + if (!file.canRead()) { throw new IOException("File '" + file + "' cannot be read"); } } else { @@ -148,13 +148,13 @@ public static FileOutputStream openOutputStream(File file) throws IOException { if (file.isDirectory()) { throw new IOException("File '" + file + "' exists but is a directory"); } - if (file.canWrite() == false) { + if (!file.canWrite()) { throw new IOException("File '" + file + "' cannot be written to"); } } else { File parent = file.getParentFile(); - if (parent != null && parent.exists() == false) { - if (parent.mkdirs() == false) { + if (parent != null && !parent.exists()) { + if (!parent.mkdirs()) { throw new IOException("File '" + file + "' could not be created"); } } @@ -170,7 +170,6 @@ public static FileOutputStream openOutputStream(File file) throws IOException { * @param srcFile the file to be moved * @param destFile the destination file * @throws NullPointerException if source or destination is {@code null} - * @throws FileExistsException if the destination file exists * @throws IOException if source or destination is invalid * @throws IOException if an IO error occurs moving the file * @since 1.4 @@ -225,7 +224,6 @@ public static void moveFile(final File srcFile, final File destFile) throws IOEx * @throws IOException if source or destination is invalid * @throws IOException if an IO error occurs during copying * @throws IOException if the output file length is not the same as the input file length after the copy completes - * @see #copyFileToDirectory(File, File) * @see #copyFile(File, File, boolean) */ public static void copyFile(final File srcFile, final File destFile) throws IOException { @@ -255,7 +253,6 @@ public static void copyFile(final File srcFile, final File destFile) throws IOEx * @throws IOException if source or destination is invalid * @throws IOException if an IO error occurs during copying * @throws IOException if the output file length is not the same as the input file length after the copy completes - * @see #copyFileToDirectory(File, File, boolean) * @see #doCopyFile(File, File, boolean) */ public static void copyFile(final File srcFile, final File destFile, @@ -266,7 +263,7 @@ public static void copyFile(final File srcFile, final File destFile, if (destFile == null) { throw new NullPointerException("Destination must not be null"); } - if (srcFile.exists() == false) { + if (!srcFile.exists()) { throw new FileNotFoundException("Source '" + srcFile + "' does not exist"); } if (srcFile.isDirectory()) { @@ -281,7 +278,7 @@ public static void copyFile(final File srcFile, final File destFile, throw new IOException("Destination '" + parentFile + "' directory cannot be created"); } } - if (destFile.exists() && destFile.canWrite() == false) { + if (destFile.exists() && !destFile.canWrite()) { throw new IOException("Destination '" + destFile + "' exists but is read-only"); } doCopyFile(srcFile, destFile, preserveFileDate); @@ -476,9 +473,6 @@ public static void forceDelete(final File file) throws IOException { * Will not return true if there is a Symbolic Link anywhere in the path, * only if the specific file is. *

- * Note: the current implementation always returns {@code false} if the system - * is detected as Windows using {@link FilenameUtils#isSystemWindows()} - *

* For code that runs on Java 1.7 or later, use the following method instead: *
* {@code boolean java.nio.file.Files.isSymbolicLink(Path path)} diff --git a/Parse/src/main/java/com/parse/PushRouter.java b/Parse/src/main/java/com/parse/PushRouter.java index c36e7ed32..3630e8918 100644 --- a/Parse/src/main/java/com/parse/PushRouter.java +++ b/Parse/src/main/java/com/parse/PushRouter.java @@ -33,7 +33,7 @@ private static final String TAG = "com.parse.ParsePushRouter"; private static final String LEGACY_STATE_LOCATION = "pushState"; private static final String STATE_LOCATION = "push"; - private static int MAX_HISTORY_LENGTH = 10; + private static final int MAX_HISTORY_LENGTH = 10; private static PushRouter instance; public static synchronized PushRouter getInstance() { diff --git a/Parse/src/test/java/com/parse/ParseFileControllerTest.java b/Parse/src/test/java/com/parse/ParseFileControllerTest.java index 63993a1b2..4dd0eeddf 100644 --- a/Parse/src/test/java/com/parse/ParseFileControllerTest.java +++ b/Parse/src/test/java/com/parse/ParseFileControllerTest.java @@ -62,7 +62,7 @@ public void tearDown() { public TemporaryFolder temporaryFolder = new TemporaryFolder(); @Test - public void testGetCacheFile() { + public void testGetCacheFile() throws Exception { File root = temporaryFolder.getRoot(); ParseFileController controller = new ParseFileController(null, root); diff --git a/Parse/src/test/java/com/parse/ParsePushTest.java b/Parse/src/test/java/com/parse/ParsePushTest.java index 936389268..ec90ff7d1 100644 --- a/Parse/src/test/java/com/parse/ParsePushTest.java +++ b/Parse/src/test/java/com/parse/ParsePushTest.java @@ -276,8 +276,7 @@ public void testSubscribeInBackgroundSuccess() throws Exception { when(controller.subscribeInBackground(anyString())).thenReturn(Task.forResult(null)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); - ParsePush push = new ParsePush(); - ParseTaskUtils.wait(push.subscribeInBackground("test")); + ParseTaskUtils.wait(ParsePush.subscribeInBackground("test")); verify(controller, times(1)).subscribeInBackground("test"); } @@ -290,7 +289,7 @@ public void testSubscribeInBackgroundWithCallbackSuccess() throws Exception { ParsePush push = new ParsePush(); final Semaphore done = new Semaphore(0); final Capture exceptionCapture = new Capture<>(); - push.subscribeInBackground("test", new SaveCallback() { + ParsePush.subscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); @@ -309,8 +308,7 @@ public void testSubscribeInBackgroundFail() throws Exception { when(controller.subscribeInBackground(anyString())).thenReturn(Task.forError(exception)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); - ParsePush push = new ParsePush(); - Task pushTask = push.subscribeInBackground("test"); + Task pushTask = ParsePush.subscribeInBackground("test"); pushTask.waitForCompletion(); verify(controller, times(1)).subscribeInBackground("test"); assertTrue(pushTask.isFaulted()); @@ -327,7 +325,7 @@ public void testSubscribeInBackgroundWithCallbackFail() throws Exception { ParsePush push = new ParsePush(); final Semaphore done = new Semaphore(0); final Capture exceptionCapture = new Capture<>(); - push.subscribeInBackground("test", new SaveCallback() { + ParsePush.subscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); @@ -349,8 +347,7 @@ public void testUnsubscribeInBackgroundSuccess() throws Exception { when(controller.unsubscribeInBackground(anyString())).thenReturn(Task.forResult(null)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); - ParsePush push = new ParsePush(); - ParseTaskUtils.wait(push.unsubscribeInBackground("test")); + ParseTaskUtils.wait(ParsePush.unsubscribeInBackground("test")); verify(controller, times(1)).unsubscribeInBackground("test"); } @@ -360,10 +357,9 @@ public void testUnsubscribeInBackgroundWithCallbackSuccess() throws Exception { when(controller.unsubscribeInBackground(anyString())).thenReturn(Task.forResult(null)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); - ParsePush push = new ParsePush(); final Semaphore done = new Semaphore(0); final Capture exceptionCapture = new Capture<>(); - push.unsubscribeInBackground("test", new SaveCallback() { + ParsePush.unsubscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); @@ -383,8 +379,7 @@ public void testUnsubscribeInBackgroundFail() throws Exception { .thenReturn(Task.forError(exception)); ParseCorePlugins.getInstance().registerPushChannelsController(controller); - ParsePush push = new ParsePush(); - Task pushTask = push.unsubscribeInBackground("test"); + Task pushTask = ParsePush.unsubscribeInBackground("test"); pushTask.waitForCompletion(); verify(controller, times(1)).unsubscribeInBackground("test"); assertTrue(pushTask.isFaulted()); @@ -402,7 +397,7 @@ public void testUnsubscribeInBackgroundWithCallbackFail() throws Exception { ParsePush push = new ParsePush(); final Semaphore done = new Semaphore(0); final Capture exceptionCapture = new Capture<>(); - push.unsubscribeInBackground("test", new SaveCallback() { + ParsePush.unsubscribeInBackground("test", new SaveCallback() { @Override public void done(ParseException e) { exceptionCapture.set(e); diff --git a/ParseStarterProject/src/main/AndroidManifest.xml b/ParseStarterProject/src/main/AndroidManifest.xml index 4f970c0a5..bfd5c975c 100644 --- a/ParseStarterProject/src/main/AndroidManifest.xml +++ b/ParseStarterProject/src/main/AndroidManifest.xml @@ -15,7 +15,7 @@ diff --git a/ParseStarterProject/src/main/res/values/strings.xml b/ParseStarterProject/src/main/res/values/strings.xml index a54ad472d..56f753cb1 100644 --- a/ParseStarterProject/src/main/res/values/strings.xml +++ b/ParseStarterProject/src/main/res/values/strings.xml @@ -15,5 +15,4 @@ Parse Starter Project Hello World! - Settings From c400025567ce8baf639c86a1ddf2ca4f8e23e751 Mon Sep 17 00:00:00 2001 From: John Carlson Date: Wed, 12 Apr 2017 00:42:39 -0500 Subject: [PATCH 7/7] Change some access levels for ParseHttpClient --- .../main/java/com/parse/ParseHttpClient.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Parse/src/main/java/com/parse/ParseHttpClient.java b/Parse/src/main/java/com/parse/ParseHttpClient.java index 2d8b3cb48..a32707149 100644 --- a/Parse/src/main/java/com/parse/ParseHttpClient.java +++ b/Parse/src/main/java/com/parse/ParseHttpClient.java @@ -29,28 +29,26 @@ import okhttp3.ResponseBody; import okio.BufferedSink; +/** + * Internal http client which wraps an {@link OkHttpClient} + */ class ParseHttpClient { - private final static String OKHTTP_GET = "GET"; - private final static String OKHTTP_POST = "POST"; - private final static String OKHTTP_PUT = "PUT"; - private final static String OKHTTP_DELETE = "DELETE"; - - public static ParseHttpClient createClient(@Nullable OkHttpClient.Builder builder) { + static ParseHttpClient createClient(@Nullable OkHttpClient.Builder builder) { return new ParseHttpClient(builder); } private static final String MAX_CONNECTIONS_PROPERTY_NAME = "http.maxConnections"; private static final String KEEP_ALIVE_PROPERTY_NAME = "http.keepAlive"; - public static void setMaxConnections(int maxConnections) { + static void setMaxConnections(int maxConnections) { if (maxConnections <= 0) { throw new IllegalArgumentException("Max connections should be large than 0"); } System.setProperty(MAX_CONNECTIONS_PROPERTY_NAME, String.valueOf(maxConnections)); } - public static void setKeepAlive(boolean isKeepAlive) { + static void setKeepAlive(boolean isKeepAlive) { System.setProperty(KEEP_ALIVE_PROPERTY_NAME, String.valueOf(isKeepAlive)); } @@ -77,7 +75,13 @@ public final ParseHttpResponse execute(ParseHttpRequest request) throws IOExcept return executeInternal(request); } - private ParseHttpResponse executeInternal(ParseHttpRequest parseRequest) throws IOException { + /** + * Execute internal. Keep default protection for tests + * @param parseRequest request + * @return response + * @throws IOException exception + */ + ParseHttpResponse executeInternal(ParseHttpRequest parseRequest) throws IOException { Request okHttpRequest = getRequest(parseRequest); Call okHttpCall = okHttpClient.newCall(okHttpRequest); @@ -177,7 +181,7 @@ private static class ParseOkHttpRequestBody extends RequestBody { private ParseHttpBody parseBody; - public ParseOkHttpRequestBody(ParseHttpBody parseBody) { + ParseOkHttpRequestBody(ParseHttpBody parseBody) { this.parseBody = parseBody; } @@ -196,9 +200,5 @@ public MediaType contentType() { public void writeTo(BufferedSink bufferedSink) throws IOException { parseBody.writeTo(bufferedSink.outputStream()); } - - public ParseHttpBody getParseHttpBody() { - return parseBody; - } } }