Skip to content

Commit e232951

Browse files
committed
Merge pull request #310 from daisuke-nomura/master
Replace deprecated
2 parents d34e5fa + d551b2e commit e232951

16 files changed

+57
-41
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import bolts.Continuation;
3030
import bolts.Task;
31+
import bolts.TaskCompletionSource;
3132

3233
/**
3334
* A class that manages registering for GCM and updating the registration if it is out of date.
@@ -286,7 +287,7 @@ private static class Request {
286287
final private String senderId;
287288
final private Random random;
288289
final private int identifier;
289-
final private Task<String>.TaskCompletionSource tcs;
290+
final private TaskCompletionSource<String> tcs;
290291
final private PendingIntent appIntent;
291292
final private AtomicInteger tries;
292293
final private PendingIntent retryIntent;
@@ -304,7 +305,7 @@ private Request(Context context, String senderId) {
304305
this.senderId = senderId;
305306
this.random = new Random();
306307
this.identifier = this.random.nextInt();
307-
this.tcs = Task.create();
308+
this.tcs = new TaskCompletionSource<>();
308309
this.appIntent = PendingIntent.getBroadcast(this.context, identifier, new Intent(), 0);
309310
this.tries = new AtomicInteger(0);
310311

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import bolts.Capture;
2222
import bolts.Task;
23+
import bolts.TaskCompletionSource;
2324

2425
/**
2526
* LocationNotifier is a wrapper around fetching the current device's location. It looks for the GPS
@@ -58,7 +59,7 @@
5859
*/
5960
/* package */ static Task<Location> getCurrentLocationAsync(Context context,
6061
long timeout, Criteria criteria) {
61-
final Task<Location>.TaskCompletionSource tcs = Task.create();
62+
final TaskCompletionSource<Location> tcs = new TaskCompletionSource<>();
6263
final Capture<ScheduledFuture<?>> timeoutFuture = new Capture<ScheduledFuture<?>>();
6364
final LocationManager manager =
6465
(LocationManager) context.getSystemService(Context.LOCATION_SERVICE);

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import bolts.Capture;
3232
import bolts.Continuation;
3333
import bolts.Task;
34+
import bolts.TaskCompletionSource;
3435

3536
/** package */ class OfflineStore {
3637

@@ -188,7 +189,7 @@ public Void then(Task<String> task) throws Exception {
188189
*/
189190
private Task<String> getOrCreateUUIDAsync(final ParseObject object, ParseSQLiteDatabase db) {
190191
final String newUUID = UUID.randomUUID().toString();
191-
final Task<String>.TaskCompletionSource tcs = Task.create();
192+
final TaskCompletionSource<String> tcs = new TaskCompletionSource<>();
192193

193194
synchronized (lock) {
194195
Task<String> uuidTask = objectToUuidMap.get(object);
@@ -484,7 +485,7 @@ public List<T> then(Task<Void> task) throws Exception {
484485
/* package for OfflineQueryLogic */ <T extends ParseObject> Task<T> fetchLocallyAsync(
485486
final T object,
486487
final ParseSQLiteDatabase db) {
487-
final Task<T>.TaskCompletionSource tcs = Task.create();
488+
final TaskCompletionSource<T> tcs = new TaskCompletionSource<>();
488489
Task<String> uuidTask;
489490

490491
synchronized (lock) {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import bolts.Capture;
3030
import bolts.Continuation;
3131
import bolts.Task;
32+
import bolts.TaskCompletionSource;
3233

3334
/**
3435
* ParseCommandCache manages an on-disk cache of commands to be executed, and a thread with a
@@ -78,7 +79,7 @@ public static int getPendingCount() {
7879
// Map of filename to TaskCompletionSource, for all commands that are in the queue from this run
7980
// of the program. This is necessary so that the original objects can be notified after their
8081
// saves complete.
81-
private HashMap<File, Task<JSONObject>.TaskCompletionSource> pendingTasks = new HashMap<>();
82+
private HashMap<File, TaskCompletionSource<JSONObject>> pendingTasks = new HashMap<>();
8283

8384
private boolean running; // Is the run loop executing commands from the disk cache running?
8485

@@ -289,7 +290,7 @@ public Task<JSONObject> enqueueEventuallyAsync(ParseRESTCommand command,
289290
private Task<JSONObject> enqueueEventuallyAsync(ParseRESTCommand command, boolean preferOldest,
290291
ParseObject object) {
291292
Parse.requirePermission(Manifest.permission.ACCESS_NETWORK_STATE);
292-
Task<JSONObject>.TaskCompletionSource tcs = Task.create();
293+
TaskCompletionSource<JSONObject> tcs = new TaskCompletionSource<>();
293294
byte[] json;
294295
try {
295296
// If this object doesn't have an objectId yet, store the localId so we can remap it to the
@@ -508,7 +509,7 @@ private void maybeRunAllCommandsNow(int retriesRemaining) {
508509

509510
// Convert the command from a string.
510511
final ParseRESTCommand command;
511-
final Task<JSONObject>.TaskCompletionSource tcs =
512+
final TaskCompletionSource<JSONObject> tcs =
512513
pendingTasks.containsKey(file) ? pendingTasks.get(file) : null;
513514

514515
try {

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import bolts.Continuation;
2424
import bolts.Task;
25+
import bolts.TaskCompletionSource;
2526

2627
/**
2728
* {@code ParseFile} is a local representation of a file that is saved to the Parse cloud.
@@ -139,8 +140,8 @@ public String url() {
139140
/* package for tests */ File file;
140141

141142
/* package for tests */ final TaskQueue taskQueue = new TaskQueue();
142-
private Set<Task<?>.TaskCompletionSource> currentTasks = Collections.synchronizedSet(
143-
new HashSet<Task<?>.TaskCompletionSource>());
143+
private Set<TaskCompletionSource<?>> currentTasks = Collections.synchronizedSet(
144+
new HashSet<TaskCompletionSource<?>>());
144145

145146
/**
146147
* Creates a new file from a file pointer.
@@ -345,7 +346,7 @@ public Task<Void> then(Task<State> task) throws Exception {
345346
* @return A Task that will be resolved when the save completes.
346347
*/
347348
public Task<Void> saveInBackground(final ProgressCallback uploadProgressCallback) {
348-
final Task<Void>.TaskCompletionSource cts = Task.create();
349+
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
349350
currentTasks.add(cts);
350351

351352
return ParseUser.getCurrentSessionTokenAsync().onSuccessTask(new Continuation<String, Task<Void>>() {
@@ -425,7 +426,7 @@ public byte[] getData() throws ParseException {
425426
* @return A Task that is resolved when the data has been fetched.
426427
*/
427428
public Task<byte[]> getDataInBackground(final ProgressCallback progressCallback) {
428-
final Task<Void>.TaskCompletionSource cts = Task.create();
429+
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
429430
currentTasks.add(cts);
430431

431432
return taskQueue.enqueue(new Continuation<Void, Task<byte[]>>() {
@@ -511,7 +512,7 @@ public File getFile() throws ParseException {
511512
* @return A Task that is resolved when the file pointer of this object has been fetched.
512513
*/
513514
public Task<File> getFileInBackground(final ProgressCallback progressCallback) {
514-
final Task<Void>.TaskCompletionSource cts = Task.create();
515+
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
515516
currentTasks.add(cts);
516517

517518
return taskQueue.enqueue(new Continuation<Void, Task<File>>() {
@@ -593,7 +594,7 @@ public InputStream getDataStream() throws ParseException {
593594
* @return A Task that is resolved when the data stream of this object has been fetched.
594595
*/
595596
public Task<InputStream> getDataStreamInBackground(final ProgressCallback progressCallback) {
596-
final Task<Void>.TaskCompletionSource cts = Task.create();
597+
final TaskCompletionSource<Void> cts = new TaskCompletionSource<>();
597598
currentTasks.add(cts);
598599

599600
return taskQueue.enqueue(new Continuation<Void, Task<InputStream>>() {
@@ -687,8 +688,8 @@ public Task<File> then(Task<Void> task) throws Exception {
687688
*/
688689
//TODO (grantland): Deprecate and replace with CancellationToken
689690
public void cancel() {
690-
Set<Task<?>.TaskCompletionSource> tasks = new HashSet<>(currentTasks);
691-
for (Task<?>.TaskCompletionSource tcs : tasks) {
691+
Set<TaskCompletionSource<?>> tasks = new HashSet<>(currentTasks);
692+
for (TaskCompletionSource<?> tcs : tasks) {
692693
tcs.trySetCancelled();
693694
}
694695
currentTasks.removeAll(tasks);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import bolts.Capture;
3434
import bolts.Continuation;
3535
import bolts.Task;
36+
import bolts.TaskCompletionSource;
3637

3738
/**
3839
* The {@code ParseObject} is a local representation of data that can be saved and retrieved from
@@ -500,7 +501,7 @@ public static void registerSubclass(Class<? extends ParseObject> subclass) {
500501
static <T> Task<T> enqueueForAll(final List<? extends ParseObject> objects,
501502
Continuation<Void, Task<T>> taskStart) {
502503
// The task that will be complete when all of the child queues indicate they're ready to start.
503-
final Task<Void>.TaskCompletionSource readyToStart = Task.create();
504+
final TaskCompletionSource<Void> readyToStart = new TaskCompletionSource<>();
504505

505506
// First, we need to lock the mutex for the queue for every object. We have to hold this
506507
// from at least when taskStart() is called to when obj.taskQueue enqueue is called, so

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import bolts.Continuation;
2626
import bolts.Task;
27+
import bolts.TaskCompletionSource;
2728

2829
/**
2930
* Manages all *Eventually calls when the local datastore is enabled.
@@ -40,7 +41,7 @@
4041
/**
4142
* TCS that is held until a {@link ParseOperationSet} is completed.
4243
*/
43-
private HashMap<String, Task<JSONObject>.TaskCompletionSource> pendingOperationSetUUIDTasks =
44+
private HashMap<String, TaskCompletionSource<JSONObject>> pendingOperationSetUUIDTasks =
4445
new HashMap<>();
4546

4647
/**
@@ -67,7 +68,7 @@
6768
*
6869
* If an error is set, it means that we are trying to clear out the taskQueues.
6970
*/
70-
private Task<Void>.TaskCompletionSource connectionTaskCompletionSource = Task.create();
71+
private TaskCompletionSource<Void> connectionTaskCompletionSource = new TaskCompletionSource<>();
7172
private final Object connectionLock = new Object();
7273
private final ParseHttpClient httpClient;
7374

@@ -129,7 +130,7 @@ public int pendingCount() {
129130
}
130131

131132
public Task<Integer> pendingCountAsync() {
132-
final Task<Integer>.TaskCompletionSource tcs = Task.create();
133+
final TaskCompletionSource<Integer> tcs = new TaskCompletionSource<>();
133134

134135
taskQueue.enqueue(new Continuation<Void, Task<Void>>() {
135136
@Override
@@ -218,7 +219,7 @@ private Task<Void> waitForConnectionAsync() {
218219
public Task<JSONObject> enqueueEventuallyAsync(final ParseRESTCommand command,
219220
final ParseObject object) {
220221
Parse.requirePermission(Manifest.permission.ACCESS_NETWORK_STATE);
221-
final Task<JSONObject>.TaskCompletionSource tcs = Task.create();
222+
final TaskCompletionSource<JSONObject> tcs = new TaskCompletionSource<>();
222223

223224
taskQueue.enqueue(new Continuation<Void, Task<Void>>() {
224225
@Override
@@ -231,7 +232,7 @@ public Task<Void> then(Task<Void> toAwait) throws Exception {
231232
}
232233

233234
private Task<Void> enqueueEventuallyAsync(final ParseRESTCommand command,
234-
final ParseObject object, Task<Void> toAwait, final Task<JSONObject>.TaskCompletionSource tcs) {
235+
final ParseObject object, Task<Void> toAwait, final TaskCompletionSource<JSONObject> tcs) {
235236
return toAwait.continueWithTask(new Continuation<Void, Task<Void>>() {
236237
@Override
237238
public Task<Void> then(Task<Void> toAwait) throws Exception {
@@ -373,7 +374,7 @@ public Task<Void> then(Task<JSONObject> task) throws Exception {
373374
notifyTestHelper(TestHelper.COMMAND_SUCCESSFUL);
374375
}
375376

376-
Task<JSONObject>.TaskCompletionSource tcs =
377+
TaskCompletionSource<JSONObject> tcs =
377378
pendingOperationSetUUIDTasks.remove(eventuallyPin.getUUID());
378379
if (tcs != null) {
379380
if (error != null) {
@@ -397,7 +398,7 @@ public Task<Void> then(Task<JSONObject> task) throws Exception {
397398
/**
398399
* Map of eventually operation UUID to TCS that is resolved when the operation is complete.
399400
*/
400-
private HashMap<String, Task<JSONObject>.TaskCompletionSource> pendingEventuallyTasks =
401+
private HashMap<String, TaskCompletionSource<JSONObject>> pendingEventuallyTasks =
401402
new HashMap<>();
402403

403404
/**
@@ -429,7 +430,7 @@ public Task<Void> then(Task<JSONObject> task) throws Exception {
429430
}
430431

431432
final String uuid; // The key we use to join the taskQueues
432-
final Task<JSONObject>.TaskCompletionSource tcs;
433+
final TaskCompletionSource<JSONObject> tcs;
433434

434435
synchronized (taskQueueSyncLock) {
435436
if (operationSet != null && eventuallyPin == null) {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import bolts.Continuation;
2727
import bolts.Task;
28+
import bolts.TaskCompletionSource;
2829

2930
/**
3031
* The {@code ParseQuery} class defines a query that is used to fetch {@link ParseObject}s. The most
@@ -890,7 +891,7 @@ public String toString() {
890891

891892
private final Object lock = new Object();
892893
private boolean isRunning = false;
893-
private Task<Void>.TaskCompletionSource cts;
894+
private TaskCompletionSource<Void> cts;
894895

895896
/**
896897
* Constructs a query for a {@link ParseObject} subclass type. A default query with no further

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import bolts.Continuation;
2626
import bolts.Task;
27+
import bolts.TaskCompletionSource;
2728

2829
/** package */ class ParseRESTObjectBatchCommand extends ParseRESTCommand {
2930
public final static int COMMAND_OBJECT_BATCH_MAX_SIZE = 50;
@@ -52,9 +53,9 @@ public static List<Task<JSONObject>> executeBatch(
5253
return tasks;
5354
}
5455

55-
final List<Task<JSONObject>.TaskCompletionSource> tcss = new ArrayList<>(batchSize);
56+
final List<TaskCompletionSource<JSONObject>> tcss = new ArrayList<>(batchSize);
5657
for (int i = 0; i < batchSize; i++) {
57-
Task<JSONObject>.TaskCompletionSource tcs = Task.create();
58+
TaskCompletionSource<JSONObject> tcs = new TaskCompletionSource<>();
5859
tcss.add(tcs);
5960
tasks.add(tcs.getTask());
6061
}
@@ -85,7 +86,7 @@ public static List<Task<JSONObject>> executeBatch(
8586
command.executeAsync(client).continueWith(new Continuation<JSONObject, Void>() {
8687
@Override
8788
public Void then(Task<JSONObject> task) throws Exception {
88-
Task<JSONObject>.TaskCompletionSource tcs;
89+
TaskCompletionSource<JSONObject> tcs;
8990

9091
if (task.isFaulted() || task.isCancelled()) {
9192
// REST command failed or canceled, fail or cancel all tasks

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import bolts.Continuation;
2727
import bolts.Task;
28+
import bolts.TaskCompletionSource;
2829

2930
/**
3031
* ParseRequest takes an arbitrary HttpUriRequest and retries it a number of times with
@@ -229,7 +230,7 @@ public Task<Response> then(Task<Response> task) throws Exception {
229230
PLog.i("com.parse.ParseRequest", "Request failed. Waiting " + delay
230231
+ " milliseconds before attempt #" + (attemptsMade + 1));
231232

232-
final Task<Response>.TaskCompletionSource retryTask = Task.create();
233+
final TaskCompletionSource<Response> retryTask = new TaskCompletionSource<>();
233234
ParseExecutors.scheduled().schedule(new Runnable() {
234235
@Override
235236
public void run() {

0 commit comments

Comments
 (0)