本文整理了Java中com.annimon.stream.Optional.ifPresent()
方法的一些代码示例,展示了Optional.ifPresent()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Optional.ifPresent()
方法的具体详情如下:
包路径:com.annimon.stream.Optional
类名称:Optional
方法名:ifPresent
[英]Invokes consumer function with value if present.
[中]调用具有值(如果存在)的使用者函数。
代码示例来源:origin: aNNiMON/Lightweight-Stream-API
/**
* Invokes consumer function with the value if present.
* This method same as {@code ifPresent}, but does not breaks chaining
*
* @param consumer consumer function
* @return this {@code Optional}
* @see #ifPresent(com.annimon.stream.function.Consumer)
* @since 1.1.2
*/
public Optional<T> executeIfPresent(Consumer<? super T> consumer) {
ifPresent(consumer);
return this;
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
public void init() {
if (!preferencesManager.getAutologinEnabled()) {
preferencesManager.clear();
dataManager.clearData();
}
getMvpView().ifPresent(splashView -> {
preferencesManager.getToken().ifPresentOrElse(token -> splashView.goToProjectList(), splashView::goToLogin);
splashView.close();
});
}
}
代码示例来源:origin: aNNiMON/Lightweight-Stream-API
@Test
public void testIfPresent() {
Optional.of(10).ifPresent(new Consumer<Integer>() {
@Override
public void accept(Integer value) {
assertEquals(10, (int) value);
}
});
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void goBack() {
baseActivity.ifPresent(BaseActivity::goBack);
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void close() {
baseActivity.ifPresent(BaseActivity::close);
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void dismissProgress() {
baseActivity.ifPresent(BaseActivity::dismissProgress);
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void showProgress() {
baseActivity.ifPresent(BaseActivity::showProgress);
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void dismissProgress() {
progressDlg.ifPresent(Dialog::dismiss);
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
public void processFirstItemClick() {
renderClause1();
callbackOpt.ifPresent(BottomMenuCallback::onClause1Press);
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void showToastMessage(String text) {
baseActivity.ifPresent(activity -> activity.showToastMessage(text));
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void showToastMessage(int textRes) {
baseActivity.ifPresent(activity -> activity.showToastMessage(textRes));
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
public void logEvent(AnalyticsEvent event, Bundle bundle) {
fabricManager.ifPresent(fabricManager -> fabricManager.logEvent(event));
googleManager.ifPresent(googleManager -> googleManager.logEvent(event, bundle));
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void onClick(View v) {
int vId = v.getId();
if (vId == ID_CLAUSE_1) {
processFirstItemClick();
} else if (vId == ID_CLAUSE_2) {
renderClause2();
callbackOpt.ifPresent(BottomMenuCallback::onClause2Press);
}
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void onChanged() {
super.onChanged();
checkIfEmpty();
onUpdateListener.ifPresent(OnUpdateListener::onUpdate);
}
};
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
private void syncProjects() {
Disposable disposable = dataManager.syncProjects()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(list -> {
analyticsManager.logEvent(AnalyticsEvent.SYNC_PROJECTS);
getMvpView().ifPresent(ProjectListView::stopRefreshAnimation);
}, getErrorConsumer());
addToDisposables(disposable);
}
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
baseActivity.ifPresent(activity ->
fragmentComponent = Optional.of(activity.activityComponent().fragmentComponent(new FragmentModule(this))));
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
private void navigateToNext() {
getMvpView().ifPresent(authView -> {
authView.navigateToListScreen();
authView.close();
});
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
public void init() {
Disposable disposable = dataManager.getProjects()
.observeOn(AndroidSchedulers.mainThread())
.subscribe(list -> getMvpView().ifPresent(projectListView -> projectListView.setupList(list)), getErrorConsumer());
addToDisposables(disposable);
syncProjects();
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
public void onLogoutSelected() {
analyticsManager.logEvent(AnalyticsEvent.LOG_OUT);
preferencesManager.setToken(null);
dataManager.clearData();
getMvpView().ifPresent(SettingsView::startAuthClearTop);
}
代码示例来源:origin: GrossumUA/TAS_Android_Boilerplate
public void init() {
analyticsManager.logEvent(AnalyticsEvent.ENTER_SETTINGS);
getMvpView().ifPresent(settingsView -> settingsView.fillView(preferencesManager.getAutologinEnabled()));
}
}
内容来源于网络,如有侵权,请联系作者删除!