Tasks.java
5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
package com.google.android.gms.tasks;
import android.support.annotation.NonNull;
import com.google.android.gms.common.internal.zzac;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import mf;
public final class Tasks
{
private static <TResult> TResult a(Task<TResult> paramTask)
throws ExecutionException
{
if (paramTask.isSuccessful()) {
return (TResult)paramTask.getResult();
}
throw new ExecutionException(paramTask.getException());
}
private static void a(Task<?> paramTask, b paramb)
{
paramTask.addOnSuccessListener(TaskExecutors.a, paramb);
paramTask.addOnFailureListener(TaskExecutors.a, paramb);
}
public static <TResult> TResult await(@NonNull Task<TResult> paramTask)
throws ExecutionException, InterruptedException
{
zzac.zzye();
zzac.zzb(paramTask, "Task must not be null");
if (paramTask.isComplete()) {
return (TResult)a(paramTask);
}
a locala = new a((byte)0);
a(paramTask, locala);
locala.a.await();
return (TResult)a(paramTask);
}
public static <TResult> TResult await(@NonNull Task<TResult> paramTask, long paramLong, @NonNull TimeUnit paramTimeUnit)
throws ExecutionException, InterruptedException, TimeoutException
{
zzac.zzye();
zzac.zzb(paramTask, "Task must not be null");
zzac.zzb(paramTimeUnit, "TimeUnit must not be null");
if (paramTask.isComplete()) {
return (TResult)a(paramTask);
}
a locala = new a((byte)0);
a(paramTask, locala);
if (!locala.a.await(paramLong, paramTimeUnit)) {
throw new TimeoutException("Timed out waiting for Task");
}
return (TResult)a(paramTask);
}
public static <TResult> Task<TResult> call(@NonNull Callable<TResult> paramCallable)
{
return call(TaskExecutors.MAIN_THREAD, paramCallable);
}
public static <TResult> Task<TResult> call(@NonNull Executor paramExecutor, @NonNull final Callable<TResult> paramCallable)
{
zzac.zzb(paramExecutor, "Executor must not be null");
zzac.zzb(paramCallable, "Callback must not be null");
mf localmf = new mf();
paramExecutor.execute(new Runnable()
{
public final void run()
{
try
{
Tasks.this.a(paramCallable.call());
return;
}
catch (Exception localException)
{
Tasks.this.a(localException);
}
}
});
return localmf;
}
public static <TResult> Task<TResult> forException(@NonNull Exception paramException)
{
mf localmf = new mf();
localmf.a(paramException);
return localmf;
}
public static <TResult> Task<TResult> forResult(TResult paramTResult)
{
mf localmf = new mf();
localmf.a(paramTResult);
return localmf;
}
public static Task<Void> whenAll(Collection<? extends Task<?>> paramCollection)
{
if (paramCollection.isEmpty()) {
return forResult(null);
}
Object localObject = paramCollection.iterator();
while (((Iterator)localObject).hasNext()) {
if ((Task)((Iterator)localObject).next() == null) {
throw new NullPointerException("null tasks are not accepted");
}
}
localObject = new mf();
c localc = new c(paramCollection.size(), (mf)localObject);
paramCollection = paramCollection.iterator();
while (paramCollection.hasNext()) {
a((Task)paramCollection.next(), localc);
}
return (Task<Void>)localObject;
}
public static Task<Void> whenAll(Task<?>... paramVarArgs)
{
if (paramVarArgs.length == 0) {
return forResult(null);
}
return whenAll(Arrays.asList(paramVarArgs));
}
static final class a
implements Tasks.b
{
final CountDownLatch a = new CountDownLatch(1);
public final void onFailure(@NonNull Exception paramException)
{
this.a.countDown();
}
public final void onSuccess(Object paramObject)
{
this.a.countDown();
}
}
static abstract interface b
extends OnFailureListener, OnSuccessListener<Object>
{}
static final class c
implements Tasks.b
{
private final Object a = new Object();
private final int b;
private final mf<Void> c;
private int d;
private int e;
private Exception f;
public c(int paramInt, mf<Void> parammf)
{
this.b = paramInt;
this.c = parammf;
}
private void a()
{
if (this.d + this.e == this.b)
{
if (this.f == null) {
this.c.a(null);
}
}
else {
return;
}
mf localmf = this.c;
int i = this.e;
int j = this.b;
localmf.a(new ExecutionException(54 + i + " out of " + j + " underlying tasks failed", this.f));
}
public final void onFailure(@NonNull Exception paramException)
{
synchronized (this.a)
{
this.e += 1;
this.f = paramException;
a();
return;
}
}
public final void onSuccess(Object arg1)
{
synchronized (this.a)
{
this.d += 1;
a();
return;
}
}
}
}
/* Location: /home/merong/decompile/hackery-dex2jar.jar!/com/google/android/gms/tasks/Tasks.class
* Java compiler version: 6 (50.0)
* JD-Core Version: 0.7.1
*/