本文整理汇总了Java中com.google.android.agera.Supplier类的典型用法代码示例。如果您正苦于以下问题:Java Supplier类的具体用法?Java Supplier怎么用?Java Supplier使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Supplier类属于com.google.android.agera包,在下文中一共展示了Supplier类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setUpRepository
import com.google.android.agera.Supplier; //导入依赖的package包/类
private void setUpRepository() {
mExecutor = Executors.newSingleThreadExecutor();
mReservoir = Reservoirs.reservoir();
Supplier<Result<Integer>> supplier = new Supplier<Result<Integer>>() {
@NonNull
@Override
public Result<Integer> get() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
mReservoir.get();// consume receiver
return Result.success(++mCount);
}
};
mRepository = Repositories.repositoryWithInitialValue(Result.<Integer>absent())
.observe(mReservoir)
.onUpdatesPerLoop()
.goTo(mExecutor)
.thenGetFrom(supplier)
.compile();
}
开发者ID:captain-miao,项目名称:AndroidAgeraTutorial,代码行数:24,代码来源:SimpleActivityH.java
示例2: setUpRepository
import com.google.android.agera.Supplier; //导入依赖的package包/类
private void setUpRepository() {
mObservable = new OnClickObservable() {
@Override
public void onClick( ) {
dispatchUpdate();
}
};
Supplier<Result<Integer>> supplier = new Supplier<Result<Integer>>() {
@NonNull
@Override
public Result<Integer> get() {
return Result.success(MockRandomData.getRandomColor());
}
};
mRepository = Repositories.repositoryWithInitialValue(Result.<Integer>absent())
.observe(mObservable)
.onUpdatesPerLoop()
.thenGetFrom(supplier)
.compile();
}
开发者ID:captain-miao,项目名称:AndroidAgeraTutorial,代码行数:22,代码来源:SimpleActivityA.java
示例3: responseTypes
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void responseTypes() {
Type oBodyClass = new TypeToken<Supplier<Result<String>>>() {}.getType();
assertThat(factory.get(oBodyClass, NO_ANNOTATIONS, retrofit).responseType(),
equalTo(new TypeToken<String>() {}.getType()));
Type oBodyWildcard = new TypeToken<Supplier<Result<? extends String>>>() {}.getType();
assertThat(factory.get(oBodyWildcard, NO_ANNOTATIONS, retrofit).responseType(),
equalTo(new TypeToken<String>() {}.getType()));
Type oBodyGeneric = new TypeToken<Supplier<Result<List<String>>>>() {}.getType();
assertThat(factory.get(oBodyGeneric, NO_ANNOTATIONS, retrofit).responseType(),
equalTo(new TypeToken<List<String>>() {}.getType()));
Type oResponseClass = new TypeToken<Supplier<Result<Response<String>>>>() {}.getType();
assertThat(factory.get(oResponseClass, NO_ANNOTATIONS, retrofit).responseType(),
equalTo(new TypeToken<String>() {}.getType()));
Type oResponseWildcard
= new TypeToken<Supplier<Result<Response<? extends String>>>>() {}.getType();
assertThat(factory.get(oResponseWildcard, NO_ANNOTATIONS, retrofit).responseType(),
equalTo(new TypeToken<String>() {}.getType()));
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:23,代码来源:AgeraCallAdapterFactoryTest.java
示例4: setUpRepository
import com.google.android.agera.Supplier; //导入依赖的package包/类
private void setUpRepository() {
networkExecutor = Executors.newSingleThreadExecutor();
uiExecutor = UiThreadExecutor.newUiThreadExecutor();
mObservable = new SimpleObservable() { };
mRepository = Repositories.repositoryWithInitialValue(Result.<ApiResult<GirlInfo>>absent())
.observe(mObservable)
.onUpdatesPerLoop()
//.goTo(uiExecutor)
.getFrom(new Supplier<Object>() {
@NonNull
@Override
public Object get() {
Toast.makeText(RecycleViewActivity.this, "load data begin", Toast.LENGTH_LONG).show();
return new Object();
}
})
.goTo(networkExecutor)
.getFrom(new GirlsSupplier(new Supplier<Integer>() {
@NonNull
@Override
public Integer get() {
return mPagination;
}
}))
.goTo(uiExecutor)
.thenTransform(new Function<Result<ApiResult<GirlInfo>>, Result<ApiResult<GirlInfo>>>() {
@NonNull
@Override
public Result<ApiResult<GirlInfo>> apply(@NonNull Result<ApiResult<GirlInfo>> input) {
Toast.makeText(RecycleViewActivity.this, "load data end", Toast.LENGTH_LONG).show();
return input;
}
})
.onDeactivation(RepositoryConfig.SEND_INTERRUPT)
.compile();
}
开发者ID:captain-miao,项目名称:AndroidAgeraTutorial,代码行数:40,代码来源:RecycleViewActivity.java
示例5: setUpRepository
import com.google.android.agera.Supplier; //导入依赖的package包/类
private void setUpRepository() {
networkExecutor = Executors.newSingleThreadExecutor();
mObservable = new SimpleObservable() { };
mRepository = Repositories.repositoryWithInitialValue(Result.<List<GirlInfo>>absent())
.observe(mObservable)
.onUpdatesPerLoop()
.goTo(networkExecutor)
.getFrom(new GirlsSupplier(new Supplier<Integer>() {
@NonNull
@Override
public Integer get() {
return mPagination;
}
}))
.thenTransform(new Function<Result<ApiResult<GirlInfo>>, Result<List<GirlInfo>>>() {
@NonNull
@Override
public Result<List<GirlInfo>> apply(@NonNull Result<ApiResult<GirlInfo>> input) {
if (input.succeeded() && !input.get().error) {
return Result.success(input.get().results);
} else {
return Result.absent();
}
}
})
.onDeactivation(RepositoryConfig.SEND_INTERRUPT)
.compile();
}
开发者ID:captain-miao,项目名称:AndroidAgeraTutorial,代码行数:31,代码来源:RepositoryAdapterRecycleViewActivity.java
示例6: setUpRepository
import com.google.android.agera.Supplier; //导入依赖的package包/类
private void setUpRepository() {
networkExecutor = Executors.newSingleThreadExecutor();
mObservable = new OnClickObservable() {
@Override
public void onClick( ) {
dispatchUpdate();
}
};
Supplier<String> imageUriSupplier = new Supplier<String>() {
@NonNull
@Override
public String get() {
return MockRandomData.getRandomImage();
}
};
mRepository = Repositories.repositoryWithInitialValue(Result.<Bitmap>absent())
.observe(mObservable)
.onUpdatesPerLoop()
.getFrom(imageUriSupplier)
.goTo(networkExecutor)
.thenTransform(new Function<String, Result<Bitmap>>() {
@NonNull
@Override
public Result<Bitmap> apply(@NonNull String input) {
return new ImageSupplier(input).get();
}
})
.compile();
}
开发者ID:captain-miao,项目名称:AndroidAgeraTutorial,代码行数:32,代码来源:SimpleActivityB.java
示例7: get
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Override
public CallAdapter<?, ?> get(Type returnType, Annotation[] annotations, Retrofit retrofit) {
if (getRawType(returnType) != Supplier.class) {
return null;
}
if (!(returnType instanceof ParameterizedType)) {
throw new IllegalStateException("Supplier return type must be parameterized"
+ " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>");
}
Type innerType = getParameterUpperBound(0, (ParameterizedType) returnType);
if (getRawType(innerType) != Result.class) {
throw new IllegalStateException("Supplier return type must be parameterized"
+ " as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>");
}
Type innerTypeOfInnerType = getParameterUpperBound(0, (ParameterizedType) innerType);
if (getRawType(innerTypeOfInnerType) != Response.class) {
// Generic type is not Response<T>. Use it for body-only adapter.
return new BodyCallAdapter(innerTypeOfInnerType);
}
// Generic type is Response<T>. Extract T and create the Response version of the adapter.
if (!(innerTypeOfInnerType instanceof ParameterizedType)) {
throw new IllegalStateException("Response must be parameterized"
+ " as Response<Foo> or Response<? extends Foo>");
}
Type responseType = getParameterUpperBound(0, (ParameterizedType) innerTypeOfInnerType);
return new ResponseCallAdapter(responseType);
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:30,代码来源:AgeraCallAdapterFactory.java
示例8: rawBodyTypeThrows
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void rawBodyTypeThrows() {
Type reservoirType = new TypeToken<Supplier>() {}.getType();
try {
factory.get(reservoirType, NO_ANNOTATIONS, retrofit);
fail();
} catch (IllegalStateException e) {
assertThat(e, hasMessage(containsString(
"Supplier return type must be parameterized as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>")));
}
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:11,代码来源:AgeraCallAdapterFactoryTest.java
示例9: noUseResultAsFirstInnerTypeThrows
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void noUseResultAsFirstInnerTypeThrows() {
Type reservoirType = new TypeToken<Supplier<String>>() {}.getType();
try {
factory.get(reservoirType, NO_ANNOTATIONS, retrofit);
fail();
} catch (IllegalStateException e) {
assertThat(e, hasMessage(containsString(
"Supplier return type must be parameterized as Supplier<Result<Foo>> or Supplier<Result<? extends Foo>>")));
}
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:11,代码来源:AgeraCallAdapterFactoryTest.java
示例10: rawResponseTypeThrows
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void rawResponseTypeThrows() {
Type reservoirType = new TypeToken<Supplier<Result<Response>>>() {}.getType();
try {
factory.get(reservoirType, NO_ANNOTATIONS, retrofit);
fail();
} catch (IllegalStateException e) {
assertThat(e, hasMessage(containsString(
"Response must be parameterized as Response<Foo> or Response<? extends Foo>")));
}
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:11,代码来源:AgeraCallAdapterFactoryTest.java
示例11: responseSuccess404
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void responseSuccess404() throws Exception {
server.enqueue(new MockResponse().setResponseCode(404).setBody("error"));
Supplier<Result<Response<String>>> supplier = service.response();
try {
supplier.get().get();
fail();
} catch (FailedResultException e) {
assertThat(e.getCause(), instanceOf(HttpException.class));
assertThat(e.getCause(), hasMessage(containsString("HTTP 404 Client Error")));
}
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:13,代码来源:SupplierTest.java
示例12: responseFailure
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void responseFailure() throws Exception {
server.enqueue(new MockResponse().setSocketPolicy(DISCONNECT_AFTER_REQUEST));
Supplier<Result<Response<String>>> supplier = service.response();
try {
supplier.get().get();
fail();
} catch (FailedResultException e) {
assertThat(e.getCause(), instanceOf(IOException.class));
}
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:12,代码来源:SupplierTest.java
示例13: shouldReturnAbsentIfNullBody
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void shouldReturnAbsentIfNullBody() throws Exception {
MockResponse mockResponse = new MockResponse().setStatus(STATUS_NO_CONTENT);
assertNull(mockResponse.getBody());
server.enqueue(mockResponse);
Supplier<Result<Void>> supplier = service.deleteXXX();
Result<Void> result = supplier.get();
assertTrue(result.isAbsent());
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:10,代码来源:SupplierTest.java
示例14: shouldReturnSuccessWithNullBodyResponse
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Test public void shouldReturnSuccessWithNullBodyResponse() throws Exception {
MockResponse mockResponse = new MockResponse().setStatus(STATUS_NO_CONTENT);
assertNull(mockResponse.getBody());
server.enqueue(mockResponse);
Supplier<Result<Response<Void>>> supplier = service.responseOfDeleteXXX();
Result<Response<Void>> responseResult = supplier.get();
assertTrue(responseResult.succeeded());
Response<Void> response = responseResult.get();
assertEquals(response.code(), 204);
assertNull(response.body());
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:14,代码来源:SupplierTest.java
示例15: createWrapper
import com.google.android.agera.Supplier; //导入依赖的package包/类
@NonNull
@Override
protected FlatMapUpdatable createWrapper(@NonNull Updatable updatable) {
Supplier<Observable> supplier = new Supplier<Observable>() {
int i;
@NonNull
@Override
public Observable get() {
return sources[i++];
}
};
return new FlatMapUpdatable(updatable, supplier);
}
开发者ID:akarnokd,项目名称:RxAgera,代码行数:14,代码来源:AgeraMerge.java
示例16: databaseQueryFunction
import com.google.android.agera.Supplier; //导入依赖的package包/类
/**
* Creates a sql query {@link Function}.
*/
@NonNull
public static <T> Function<SqlRequest, Result<List<T>>> databaseQueryFunction(
@NonNull final Supplier<Result<SQLiteDatabase>> database,
@NonNull Function<Cursor, T> rowMap) {
return new DatabaseFunction<>(database, new DatabaseQueryMerger<>(rowMap));
}
开发者ID:google,项目名称:agera,代码行数:10,代码来源:SqlDatabaseFunctions.java
示例17: getUserInfo
import com.google.android.agera.Supplier; //导入依赖的package包/类
@GET("{page}")
Supplier<Result<Beauty>> getUserInfo(@Path("page") int page);
开发者ID:zjutkz,项目名称:AgeraBeauty,代码行数:3,代码来源:BeautyApi.java
示例18: GirlsSupplier
import com.google.android.agera.Supplier; //导入依赖的package包/类
public GirlsSupplier(@NonNull Supplier<Integer> supplier ) {
mSupplierPagination = supplier;
}
开发者ID:captain-miao,项目名称:AndroidAgeraTutorial,代码行数:4,代码来源:GirlsSupplier.java
示例19: adapt
import com.google.android.agera.Supplier; //导入依赖的package包/类
@Override public Supplier<Result<Response<R>>> adapt(Call<R> call) {
return new CallResponseSupplier<R>(call);
}
开发者ID:drakeet,项目名称:retrofit-agera-call-adapter,代码行数:4,代码来源:AgeraCallAdapterFactory.java
示例20: getSomeObject
import com.google.android.agera.Supplier; //导入依赖的package包/类
@GET("some_object.json")
Supplier<Result<SomeObject>> getSomeObject();
开发者ID:BlackGoblin,项目名称:AgeraRetrofit,代码行数:3,代码来源:SomeObjectAPI.java
注:本文中的com.google.android.agera.Supplier类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论