Skip to content

Commit 53b05e9

Browse files
Jawnnypoorogerhu
authored andcommitted
Code cleanup (#632)
* Remove unused method in ParseHttpClient * Remove redundant access modifiers on interfaces * Collapse Exceptions * Remove redundant typing * Remove redundant casting * Simplify some boolean logic, access static methods via static class * Change some access levels for ParseHttpClient
1 parent 394851a commit 53b05e9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+86
-153
lines changed

Parse/src/main/java/com/parse/ConfigCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ public interface ConfigCallback extends ParseCallback2<ParseConfig, ParseExcepti
4040
* The exception raised by the fetch, or {@code null} if it succeeded.
4141
*/
4242
@Override
43-
public void done(ParseConfig config, ParseException e);
43+
void done(ParseConfig config, ParseException e);
4444
}

Parse/src/main/java/com/parse/CountCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ public interface CountCallback {
4444
* @param e
4545
* The exception raised by the count, or null if it succeeded.
4646
*/
47-
public void done(int count, ParseException e);
47+
void done(int count, ParseException e);
4848
}

Parse/src/main/java/com/parse/DeleteCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,5 +40,5 @@ public interface DeleteCallback extends ParseCallback1<ParseException> {
4040
* The exception raised by the delete, or {@code null} if it succeeded.
4141
*/
4242
@Override
43-
public void done(ParseException e);
43+
void done(ParseException e);
4444
}

Parse/src/main/java/com/parse/FindCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ public interface FindCallback<T extends ParseObject> extends ParseCallback2<List
4545
* The exception raised by the save, or null if it succeeded.
4646
*/
4747
@Override
48-
public void done(List<T> objects, ParseException e);
48+
void done(List<T> objects, ParseException e);
4949
}

Parse/src/main/java/com/parse/FunctionCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ public interface FunctionCallback<T> extends ParseCallback2<T, ParseException> {
4545
* The exception raised by the cloud call, or {@code null} if it succeeded.
4646
*/
4747
@Override
48-
public void done(T object, ParseException e);
48+
void done(T object, ParseException e);
4949
}

Parse/src/main/java/com/parse/GetCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ public interface GetCallback<T extends ParseObject> extends ParseCallback2<T, Pa
4343
* The exception raised by the fetch, or {@code null} if it succeeded.
4444
*/
4545
@Override
46-
public void done(T object, ParseException e);
46+
void done(T object, ParseException e);
4747
}

Parse/src/main/java/com/parse/GetDataCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ public interface GetDataCallback extends ParseCallback2<byte[], ParseException>
3535
* The exception raised by the fetch, or {@code null} if it succeeded.
3636
*/
3737
@Override
38-
public void done(byte[] data, ParseException e);
38+
void done(byte[] data, ParseException e);
3939
}
4040

Parse/src/main/java/com/parse/GetDataStreamCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ public interface GetDataStreamCallback extends ParseCallback2<InputStream, Parse
3737
* The exception raised by the fetch, or {@code null} if it succeeded.
3838
*/
3939
@Override
40-
public void done(InputStream input, ParseException e);
40+
void done(InputStream input, ParseException e);
4141
}

Parse/src/main/java/com/parse/GetFileCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@ public interface GetFileCallback extends ParseCallback2<File, ParseException> {
3737
* The exception raised by the fetch, or {@code null} if it succeeded.
3838
*/
3939
@Override
40-
public void done(File file, ParseException e);
40+
void done(File file, ParseException e);
4141
}

Parse/src/main/java/com/parse/LocationCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,5 +44,5 @@ public interface LocationCallback extends ParseCallback2<ParseGeoPoint, ParseExc
4444
* The exception raised by the location fetch, or {@code null} if it succeeded.
4545
*/
4646
@Override
47-
public void done(ParseGeoPoint geoPoint, ParseException e);
47+
void done(ParseGeoPoint geoPoint, ParseException e);
4848
}

Parse/src/main/java/com/parse/LocationNotifier.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
/* package */ static Task<Location> getCurrentLocationAsync(Context context,
6161
long timeout, Criteria criteria) {
6262
final TaskCompletionSource<Location> tcs = new TaskCompletionSource<>();
63-
final Capture<ScheduledFuture<?>> timeoutFuture = new Capture<ScheduledFuture<?>>();
63+
final Capture<ScheduledFuture<?>> timeoutFuture = new Capture<>();
6464
final LocationManager manager =
6565
(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
6666
final LocationListener listener = new LocationListener() {

Parse/src/main/java/com/parse/LockSet.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
import java.util.concurrent.locks.Lock;
1717

1818
/** package */ class LockSet {
19-
private static WeakHashMap<Lock, Long> stableIds = new WeakHashMap<Lock, Long>();
19+
private static final WeakHashMap<Lock, Long> stableIds = new WeakHashMap<>();
2020
private static long nextStableId = 0L;
2121

2222
private final Set<Lock> locks;
2323

2424
public LockSet(Collection<Lock> locks) {
25-
this.locks = new TreeSet<Lock>(new Comparator<Lock>() {
25+
this.locks = new TreeSet<>(new Comparator<Lock>() {
2626
@Override
2727
public int compare(Lock lhs, Lock rhs) {
2828
Long lhsId = getStableId(lhs);

Parse/src/main/java/com/parse/LogInCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,5 +43,5 @@ public interface LogInCallback extends ParseCallback2<ParseUser, ParseException>
4343
* The exception raised by the login, or {@code null} if it succeeded.
4444
*/
4545
@Override
46-
public void done(ParseUser user, ParseException e);
46+
void done(ParseUser user, ParseException e);
4747
}

Parse/src/main/java/com/parse/LogOutCallback.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ public interface LogOutCallback extends ParseCallback1<ParseException> {
3939
* The exception raised by the log out, or {@code null} if it succeeded.
4040
*/
4141
@Override
42-
public void done(ParseException e);
42+
void done(ParseException e);
4343
}

Parse/src/main/java/com/parse/ManifestInfo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ private static boolean hasAnyGcmSpecificDeclaration() {
463463
}
464464

465465
private static boolean isGooglePlayServicesAvailable() {
466-
return Build.VERSION.SDK_INT >= 8 && getPackageInfo("com.google.android.gsf") != null;
466+
return getPackageInfo("com.google.android.gsf") != null;
467467
}
468468

469469
private static ManifestCheckResult gcmSupportLevel() {

Parse/src/main/java/com/parse/NotificationCompat.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,15 +314,15 @@ public Builder setStyle(Style style) {
314314
*/
315315
@Deprecated
316316
public Notification getNotification() {
317-
return (Notification) IMPL.build(this);
317+
return IMPL.build(this);
318318
}
319319

320320
/**
321321
* Combine all of the options that have been set and return a new {@link Notification}
322322
* object.
323323
*/
324324
public Notification build() {
325-
return (Notification) IMPL.build(this);
325+
return IMPL.build(this);
326326
}
327327

328328
protected static CharSequence limitCharSequenceLength(CharSequence cs) {

Parse/src/main/java/com/parse/OfflineStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public Task<Void> then(Task<Void> ignore) throws Exception {
106106
}
107107
}
108108
tasks.clear();
109-
return Task.forResult((Void) null);
109+
return Task.forResult(null);
110110
}
111111
}
112112
});

Parse/src/main/java/com/parse/Parse.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
import android.util.Log;
1616

1717
import java.io.File;
18-
import java.io.FileNotFoundException;
1918
import java.io.FileOutputStream;
2019
import java.io.IOException;
2120
import java.io.RandomAccessFile;
22-
import java.io.UnsupportedEncodingException;
2321
import java.net.MalformedURLException;
2422
import java.net.URL;
2523
import java.util.HashSet;
@@ -545,8 +543,6 @@ static void checkCacheApplicationId() {
545543
f.close();
546544
String diskApplicationId = new String(bytes, "UTF-8");
547545
matches = diskApplicationId.equals(applicationId);
548-
} catch (FileNotFoundException e) {
549-
// Well, it existed a minute ago. Let's assume it doesn't match.
550546
} catch (IOException e) {
551547
// Hmm, the applicationId file was malformed or something. Assume it
552548
// doesn't match.
@@ -568,11 +564,6 @@ static void checkCacheApplicationId() {
568564
FileOutputStream out = new FileOutputStream(applicationIdFile);
569565
out.write(applicationId.getBytes("UTF-8"));
570566
out.close();
571-
} catch (FileNotFoundException e) {
572-
// Nothing we can really do about it.
573-
} catch (UnsupportedEncodingException e) {
574-
// Nothing we can really do about it. This would mean Java doesn't
575-
// understand UTF-8, which is unlikely.
576567
} catch (IOException e) {
577568
// Nothing we can really do about it.
578569
}

Parse/src/main/java/com/parse/ParseCallback1.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@
2525
* @param t
2626
* Generally an {@link Throwable} that was thrown by the operation, if there was any.
2727
*/
28-
public void done(T t);
28+
void done(T t);
2929
}

Parse/src/main/java/com/parse/ParseCallback2.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,5 @@
2828
* @param t2
2929
* Generally an {@link Throwable} that was thrown by the operation, if there was any.
3030
*/
31-
public void done(T1 t1, T2 t2);
31+
void done(T1 t1, T2 t2);
3232
}

Parse/src/main/java/com/parse/ParseCommandCache.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ public void setConnected(boolean connected) {
437437
*/
438438
private <T> T waitForTaskWithoutLock(Task<T> task) throws ParseException {
439439
synchronized (lock) {
440-
final Capture<Boolean> finished = new Capture<Boolean>(false);
440+
final Capture<Boolean> finished = new Capture<>(false);
441441
task.continueWith(new Continuation<T, Void>() {
442442
@Override
443443
public Void then(Task<T> task) throws Exception {

Parse/src/main/java/com/parse/ParseCountingFileHttpBody.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public void writeTo(OutputStream output) throws IOException {
3636
throw new IllegalArgumentException("Output stream may not be null");
3737
}
3838

39-
final FileInputStream fileInput = new FileInputStream(file);;
39+
final FileInputStream fileInput = new FileInputStream(file);
4040
try {
4141
byte[] buffer = new byte[DEFAULT_CHUNK_SIZE];
4242
int n;

Parse/src/main/java/com/parse/ParseFileUtils.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public static FileInputStream openInputStream(File file) throws IOException {
9292
if (file.isDirectory()) {
9393
throw new IOException("File '" + file + "' exists but is a directory");
9494
}
95-
if (file.canRead() == false) {
95+
if (!file.canRead()) {
9696
throw new IOException("File '" + file + "' cannot be read");
9797
}
9898
} else {
@@ -148,13 +148,13 @@ public static FileOutputStream openOutputStream(File file) throws IOException {
148148
if (file.isDirectory()) {
149149
throw new IOException("File '" + file + "' exists but is a directory");
150150
}
151-
if (file.canWrite() == false) {
151+
if (!file.canWrite()) {
152152
throw new IOException("File '" + file + "' cannot be written to");
153153
}
154154
} else {
155155
File parent = file.getParentFile();
156-
if (parent != null && parent.exists() == false) {
157-
if (parent.mkdirs() == false) {
156+
if (parent != null && !parent.exists()) {
157+
if (!parent.mkdirs()) {
158158
throw new IOException("File '" + file + "' could not be created");
159159
}
160160
}
@@ -170,7 +170,6 @@ public static FileOutputStream openOutputStream(File file) throws IOException {
170170
* @param srcFile the file to be moved
171171
* @param destFile the destination file
172172
* @throws NullPointerException if source or destination is {@code null}
173-
* @throws FileExistsException if the destination file exists
174173
* @throws IOException if source or destination is invalid
175174
* @throws IOException if an IO error occurs moving the file
176175
* @since 1.4
@@ -225,7 +224,6 @@ public static void moveFile(final File srcFile, final File destFile) throws IOEx
225224
* @throws IOException if source or destination is invalid
226225
* @throws IOException if an IO error occurs during copying
227226
* @throws IOException if the output file length is not the same as the input file length after the copy completes
228-
* @see #copyFileToDirectory(File, File)
229227
* @see #copyFile(File, File, boolean)
230228
*/
231229
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
255253
* @throws IOException if source or destination is invalid
256254
* @throws IOException if an IO error occurs during copying
257255
* @throws IOException if the output file length is not the same as the input file length after the copy completes
258-
* @see #copyFileToDirectory(File, File, boolean)
259256
* @see #doCopyFile(File, File, boolean)
260257
*/
261258
public static void copyFile(final File srcFile, final File destFile,
@@ -266,7 +263,7 @@ public static void copyFile(final File srcFile, final File destFile,
266263
if (destFile == null) {
267264
throw new NullPointerException("Destination must not be null");
268265
}
269-
if (srcFile.exists() == false) {
266+
if (!srcFile.exists()) {
270267
throw new FileNotFoundException("Source '" + srcFile + "' does not exist");
271268
}
272269
if (srcFile.isDirectory()) {
@@ -281,7 +278,7 @@ public static void copyFile(final File srcFile, final File destFile,
281278
throw new IOException("Destination '" + parentFile + "' directory cannot be created");
282279
}
283280
}
284-
if (destFile.exists() && destFile.canWrite() == false) {
281+
if (destFile.exists() && !destFile.canWrite()) {
285282
throw new IOException("Destination '" + destFile + "' exists but is read-only");
286283
}
287284
doCopyFile(srcFile, destFile, preserveFileDate);
@@ -476,9 +473,6 @@ public static void forceDelete(final File file) throws IOException {
476473
* Will not return true if there is a Symbolic Link anywhere in the path,
477474
* only if the specific file is.
478475
* <p>
479-
* <b>Note:</b> the current implementation always returns {@code false} if the system
480-
* is detected as Windows using {@link FilenameUtils#isSystemWindows()}
481-
* <p>
482476
* For code that runs on Java 1.7 or later, use the following method instead:
483477
* <br>
484478
* {@code boolean java.nio.file.Files.isSymbolicLink(Path path)}

0 commit comments

Comments
 (0)