本文整理汇总了Java中com.google.android.agera.Function类的典型用法代码示例。如果您正苦于以下问题:Java Function类的具体用法?Java Function怎么用?Java Function使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Function类属于com.google.android.agera包,在下文中一共展示了Function类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: setUpRepository
import com.google.android.agera.Function; //导入依赖的package包/类
private void setUpRepository() {
networkExecutor = Executors.newSingleThreadExecutor();
mMutableRepository = Repositories.mutableRepository(mPagination);
mLoadDataRepository = Repositories.repositoryWithInitialValue(Result.<ApiResult<GirlInfo>>absent())
.observe(mMutableRepository)
.onUpdatesPerLoop()
.goTo(networkExecutor)
.attemptGetFrom(new GirlsSupplier(mMutableRepository)).orSkip()
.thenTransform(new Function<ApiResult<GirlInfo>, Result<ApiResult<GirlInfo>>>() {
@NonNull
@Override
public Result<ApiResult<GirlInfo>> apply(@NonNull ApiResult<GirlInfo> input) {
return absentIfNull(input);
}
})
.onDeactivation(RepositoryConfig.SEND_INTERRUPT)
.compile();
}
开发者ID:captain-miao,项目名称:AndroidAgeraTutorial,代码行数:22,代码来源:ComplexRecycleViewActivity.java
示例2: yinResponseToResult
import com.google.android.agera.Function; //导入依赖的package包/类
@NonNull private static Function<HttpResponse, Result<String>> yinResponseToResult() {
return Functions.functionFrom(HttpResponse.class)
.apply(input -> new String(input.getBody()))
.apply(body -> {
String re = "title\">\\s+.+?href=\"([^\"]*)\">(.+?)</a>.+</li>";
Pattern pattern = Pattern.compile(re, Pattern.DOTALL);
return pattern.matcher(body);
})
.thenApply(matcher -> {
if (matcher.find()) {
return Result.success("为你找到最新的一篇文章是: \n" +
matcher.group(2) + "\n" + matcher.group(1));
} else {
return Result.absent();
}
});
}
开发者ID:drakeet,项目名称:TimeMachine,代码行数:18,代码来源:YinRequests.java
示例3: mapResponse
import com.google.android.agera.Function; //导入依赖的package包/类
@NonNull private static Function<HttpResponse, Result<String>> mapResponse() {
return Functions.functionFrom(HttpResponse.class)
.apply(input -> new String(input.getBody()))
.apply(body -> {
int sourceTag = body.indexOf("<sdk:source>");
if (sourceTag != -1) {
String apiLevelStart = "<sdk:api-level>";
String apiLevelEnd = "</sdk:api-level>";
int targetStart = body.indexOf(apiLevelStart, sourceTag) +
apiLevelStart.length();
int targetEnd = body.indexOf(apiLevelEnd, targetStart);
return body.substring(targetStart, targetEnd);
}
return "24";
})
.thenApply(version -> {
return Result.success("为你找到最新的 Android SDK Source 是第 " + version + " 版");
});
}
开发者ID:drakeet,项目名称:TimeMachine,代码行数:20,代码来源:AndroidSDKRequests.java
示例4: prepare
import com.google.android.agera.Function; //导入依赖的package包/类
@SuppressWarnings("unchecked") private void prepare() {
translateReaction = Reservoirs.<Translation>reactionReservoir();
Repository<Result<String>> translationRepo = repositoryWithInitialValue(
Result.<String>absent())
.observe(translateReaction)
.onUpdatesPerLoop()
.attemptGetFrom(translateReaction).orSkip()
.goTo(networkExecutor)
.check(input -> input.getStep() == OnConfirm)
.orEnd((Function<Translation, Result<String>>) input -> {
Log.e("check-confirm", input.toString());
return Result.failure();
})
.mergeIn(YOU_DAO, current2UrlMerger())
.attemptTransform(urlToResponse())
.orEnd(Result::failure)
.goTo(calculationExecutor)
.transform(youdaoResponseToResult())
.goLazy()
.thenTransform(input -> input)
.onDeactivation(SEND_INTERRUPT)
.compile();
translationRepo.addUpdatable(() -> translationRepo.get()
.ifSucceededSendTo(this::handleConfirm)
.ifFailedSendTo(errorHandler()));
}
开发者ID:drakeet,项目名称:TimeMachine,代码行数:27,代码来源:TransformService.java
示例5: CompiledRepositoryPresenter
import com.google.android.agera.Function; //导入依赖的package包/类
CompiledRepositoryPresenter(
@NonNull final Function<Object, Integer> itemId,
@NonNull final Function<Object, Integer> layoutId,
@NonNull final Function<Object, Long> stableIdForItem,
@NonNull final SparseArray<Object> handlers,
final int recycleConfig,
@NonNull final Function<Object, List<Object>> converter,
final int collectionId,
@NonNull final Function<Object, Object> keyForItem,
final boolean detectMoves) {
this.itemId = itemId;
this.collectionId = collectionId;
this.converter = converter;
this.layoutId = layoutId;
this.stableIdForItem = stableIdForItem;
this.recycleConfig = recycleConfig;
this.handlers = handlers;
this.enableDiff = keyForItem != NO_KEY_FOR_ITEM;
this.keyForItem = keyForItem;
this.detectMoves = detectMoves;
}
开发者ID:google,项目名称:agera,代码行数:22,代码来源:DataBindingRepositoryPresenterCompiler.java
示例6: shouldBindRepositoryPresenterOfCollection
import com.google.android.agera.Function; //导入依赖的package包/类
@Test
public void shouldBindRepositoryPresenterOfCollection() {
final RepositoryPresenter<String> repositoryPresenter =
dataBindingRepositoryPresenterOf(String.class)
.layout(LAYOUT_ID)
.itemId(ITEM_ID)
.forCollection(new Function<String, List<String>>() {
@NonNull
@Override
public List<String> apply(@NonNull final String input) {
return singletonList(valueOf(input.charAt(0)));
}
});
repositoryPresenter.bind(STRING, 0, viewHolder);
verify(viewDataBinding).setVariable(ITEM_ID, FIRST_STRING_CHARACTER);
verify(viewDataBinding).executePendingBindings();
verifyNoMoreInteractions(viewDataBinding);
}
开发者ID:google,项目名称:agera,代码行数:20,代码来源:DataBindingRepositoryPresentersTest.java
示例7: CompiledRepositoryPresenter
import com.google.android.agera.Function; //导入依赖的package包/类
CompiledRepositoryPresenter(
@NonNull final Function<Object, Integer> layoutId,
@NonNull final Binder<Object, View> binder,
@NonNull final Function<Object, Long> stableIdForItem,
@NonNull final Receiver<View> recycler,
@NonNull final Function<Object, Object> keyForItem,
final boolean detectMoves,
@NonNull final Function<Object, List<Object>> converter,
@NonNull final Binder<Object, View> collectionBinder) {
this.collectionBinder = collectionBinder;
this.converter = converter;
this.layoutId = layoutId;
this.binder = binder;
this.stableIdForItem = stableIdForItem;
this.recycler = recycler;
this.enableDiff = keyForItem != NO_KEY_FOR_ITEM;
this.keyForItem = keyForItem;
this.detectMoves = detectMoves;
}
开发者ID:google,项目名称:agera,代码行数:20,代码来源:RepositoryPresenterCompiler.java
示例8: shouldBindRepositoryPresenterOfCollection
import com.google.android.agera.Function; //导入依赖的package包/类
@Test
public void shouldBindRepositoryPresenterOfCollection() {
final RepositoryPresenter<String> repositoryPresenter =
repositoryPresenterOf(String.class)
.layout(LAYOUT_ID)
.bindWith(binder)
.forCollection(new Function<String, List<String>>() {
@NonNull
@Override
public List<String> apply(@NonNull final String input) {
return singletonList(valueOf(input.charAt(0)));
}
});
repositoryPresenter.bind(STRING, 0, viewHolder);
verify(binder).bind(FIRST_STRING_CHARACTER, view);
}
开发者ID:google,项目名称:agera,代码行数:17,代码来源:RepositoryPresentersTest.java
示例9: shouldBindRepositoryPresenterCollectionOfCollection
import com.google.android.agera.Function; //导入依赖的package包/类
@Test
public void shouldBindRepositoryPresenterCollectionOfCollection() {
final RepositoryPresenter<String> repositoryPresenter =
repositoryPresenterOf(String.class)
.layout(LAYOUT_ID)
.bindWith(binder)
.bindCollectionWith(collectionBinder)
.forCollection(new Function<String, List<String>>() {
@NonNull
@Override
public List<String> apply(@NonNull final String input) {
return singletonList(valueOf(input.charAt(0)));
}
});
repositoryPresenter.bind(STRING, 0, viewHolder);
verify(binder).bind(FIRST_STRING_CHARACTER, view);
verify(collectionBinder).bind(STRING, view);
}
开发者ID:google,项目名称:agera,代码行数:19,代码来源:RepositoryPresentersTest.java
示例10: setUpRepository
import com.google.android.agera.Function; //导入依赖的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
示例11: setUpRepository
import com.google.android.agera.Function; //导入依赖的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
示例12: setUpRepository
import com.google.android.agera.Function; //导入依赖的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
示例13: initData
import com.google.android.agera.Function; //导入依赖的package包/类
@Override protected void initData() {
SaveVolley saveVolley = SaveVolleys
.<GankData>request(TEST_URL)
.method(Method.GET)
.parseStyle(GSON)
.classOf(GankData.class)
.createRequest()
.context(this)
.compile();
final Repository<GankResultData> repository = Repositories.repositoryWithInitialValue(
INITIAL_VALUE)
.observe(saveVolley.getReservoir())
.onUpdatesPerLoop()
.goTo(executor)
.attemptGetFrom(saveVolley.getReservoir())
.orSkip()
.thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
/**
* Returns the result of applying this function to {@code input}.
*/
@NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
if (input instanceof GankData) {
return Result.success(((GankData) input).results.get(0));
} else if (input instanceof VolleyError) {
return Result.failure((VolleyError) input);
}
return Result.failure();
}
})
.orSkip()
.compile();
repository.addUpdatable(new Updatable() {
@Override public void update() {
getContentText.setText(repository.get().toString());
}
});
}
开发者ID:CaMnter,项目名称:SaveVolley,代码行数:40,代码来源:Okhttp3AgeraGsonActivity.java
示例14: initData
import com.google.android.agera.Function; //导入依赖的package包/类
@Override protected void initData() {
SaveVolley saveVolley = SaveVolleys
.<GankData>request(TEST_URL)
.method(Method.GET)
.parseStyle(GSON)
.classOf(GankData.class)
.createRequest()
.context(this)
.compile();
final Repository<GankResultData> repository = Repositories
.repositoryWithInitialValue(INITIAL_VALUE)
.observe(saveVolley.getReservoir())
.onUpdatesPerLoop()
.goTo(executor)
.attemptGetFrom(saveVolley.getReservoir())
.orSkip()
.thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
/**
* Returns the result of applying this function to {@code input}.
*/
@NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
if (input instanceof GankData) {
return Result.success(((GankData) input).results.get(0));
} else if (input instanceof VolleyError) {
return Result.failure((VolleyError) input);
}
return Result.failure();
}
})
.orSkip()
.compile();
repository.addUpdatable(new Updatable() {
@Override public void update() {
getContentText.setText(repository.get().toString());
}
});
}
开发者ID:CaMnter,项目名称:SaveVolley,代码行数:40,代码来源:HurlAgeraGsonActivity.java
示例15: initData
import com.google.android.agera.Function; //导入依赖的package包/类
@Override protected void initData() {
SaveVolley saveVolley = SaveVolleys
.<GankData>request(TEST_URL)
.method(Method.GET)
.parseStyle(FASTJSON)
.classOf(GankData.class)
.createRequest()
.context(this)
.compile();
final Repository<GankResultData> repository = Repositories
.repositoryWithInitialValue(INITIAL_VALUE)
.observe(saveVolley.getReservoir())
.onUpdatesPerLoop()
.goTo(executor)
.attemptGetFrom(saveVolley.getReservoir())
.orSkip()
.thenAttemptTransform(new Function<Object, Result<GankResultData>>() {
/**
* Returns the result of applying this function to {@code input}.
*/
@NonNull @Override public Result<GankResultData> apply(@NonNull Object input) {
if (input instanceof GankData) {
return Result.success(((GankData) input).results.get(0));
} else if (input instanceof VolleyError) {
return Result.failure((VolleyError) input);
}
return Result.failure();
}
})
.orSkip()
.compile();
repository.addUpdatable(new Updatable() {
@Override public void update() {
getContentText.setText(repository.get().toString());
}
});
}
开发者ID:CaMnter,项目名称:SaveVolley,代码行数:40,代码来源:HurlAgeraFastjsonActivity.java
示例16: youdaoResponseToResult
import com.google.android.agera.Function; //导入依赖的package包/类
@NonNull public static Function<HttpResponse, Result<String>> youdaoResponseToResult() {
return Functions.functionFrom(HttpResponse.class)
.apply(input -> new String(input.getBody()))
.thenApply(json -> {
YouDao youDao = new Gson().fromJson(json, YouDao.class);
if (youDao.isSuccessful() && youDao.translation.size() > 0) {
return Result.success(youDao.translation.get(0));
}
return Result.failure();
});
}
开发者ID:drakeet,项目名称:TimeMachine,代码行数:12,代码来源:TranslateRequests.java
示例17: responseInterceptor
import com.google.android.agera.Function; //导入依赖的package包/类
public static Function<Result<HttpResponse>, Result<HttpResponse>> responseInterceptor() {
return input -> {
if (input.succeeded()) {
Log.d("Response Interceptor", new String(input.get().getBody()));
} else {
Log.e("Response Interceptor", "Failed", input.getFailure());
}
return input;
};
}
开发者ID:drakeet,项目名称:TimeMachine,代码行数:11,代码来源:LogFunctions.java
示例18: urlToResponse
import com.google.android.agera.Function; //导入依赖的package包/类
@NonNull public static Function<String, Result<HttpResponse>> urlToResponse() {
return Functions.functionFrom(String.class)
.apply(requestInterceptor())
.apply(url -> httpGetRequest(url).compile())
.apply(httpFunction())
.thenApply(responseInterceptor());
}
开发者ID:drakeet,项目名称:TimeMachine,代码行数:8,代码来源:Requests.java
示例19: RowHandler
import com.google.android.agera.Function; //导入依赖的package包/类
private RowHandler(@NonNull final RecycledViewPool pool,
@NonNull final Function<TRow, Long> stableId,
@NonNull final Function<TRow, RepositoryPresenter<TRow>> presenter,
@NonNull final Function<TRow, LayoutManager> layoutManager) {
this.stableId = checkNotNull(stableId);
this.presenter = checkNotNull(presenter);
this.layoutManager = layoutManager;
this.itemRowStates = new IdentityHashMap<>();
this.previousStableIds = new IdentityHashMap<>();
this.adapterRepositories = new IdentityHashMap<>();
this.startedAdapters = new HashSet<>();
this.pool = pool;
}
开发者ID:google,项目名称:agera,代码行数:14,代码来源:RowHandler.java
示例20: rowBinder
import com.google.android.agera.Function; //导入依赖的package包/类
@NonNull
static <TRow> RowHandler<TRow> rowBinder(
@NonNull final RecycledViewPool pool,
@NonNull final Function<TRow, LayoutManager> layoutManager,
@NonNull final Function<TRow, Long> stableIdFunction,
@NonNull final Function<TRow, RepositoryPresenter<TRow>> presenterFromView) {
return new RowHandler<>(pool, stableIdFunction, presenterFromView, layoutManager);
}
开发者ID:google,项目名称:agera,代码行数:9,代码来源:RowHandler.java
注:本文中的com.google.android.agera.Function类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论