将方法转换为java 8 lambda

将方法转换为java 8 lambda,java,lambda,functional-programming,java-8,java-stream,Java,Lambda,Functional Programming,Java 8,Java Stream,如何使用Java 8 lambda/stream()以更直观的方式在函数式编程中编写此方法 int animation = R.style.DialogAnimationSlideHorizontal; String body; String subject = mSubjectView.getText().toString(); BaseDialog dialog = dialogFactory.getType(DialogTypes.DIALOG_FULL); if (!checkFiel

如何使用Java 8 lambda/stream()以更直观的方式在函数式编程中编写此方法

int animation = R.style.DialogAnimationSlideHorizontal;
String body;
String subject = mSubjectView.getText().toString();
BaseDialog dialog = dialogFactory.getType(DialogTypes.DIALOG_FULL);

if (!checkFields()) {
    // one of the recipients is invalid.
    body = getString(R.string.bad_address);
    dialog.showDialog(body, animation, new DialogBuilder.Positive() {
        @Override
        public void handleClick(DialogInterface dialogInterface, View view) {
            // do nothing
        }
    });
} else if (Helpers.isEmpty(subject)) {
        // Yup, empty... send the message without a subject?
        body = getString(R.string.empty_subject_compose);
        dialog.showDialog(body, animation, new DialogBuilder.Positive() {
            @Override
            public void handleClick(DialogInterface dialogInterface, View view) {
                // user accepted to send anyway.
                mWebView.getComposeContent();
            }
        });
} else {
    // everything is correct! send the message.
    mWebView.getComposeContent();
}

将所有匿名类替换为lambdas-like

new DialogBuilder.Positive() {
    @Override
    public void handleClick(DialogInterface dialogInterface, View view) {
       ...
    }
}

               |
               V

(dialogInterface, view) -> { /*do nothing*/ }
(dialogInterface, view) -> { mWebView.getComposeContent(); }

我不知道如何在这里应用流API。

将所有匿名类替换为类似lambdas的类

new DialogBuilder.Positive() {
    @Override
    public void handleClick(DialogInterface dialogInterface, View view) {
       ...
    }
}

               |
               V

(dialogInterface, view) -> { /*do nothing*/ }
(dialogInterface, view) -> { mWebView.getComposeContent(); }

我不知道如何在这里应用流API。

尝试更广泛的改进,包括
checkFields()
之类的方法(如果代码检查一组字段,它是流的一个很好的候选者)。Functional在与整体功能风格架构搭配时效果最佳。尝试更广泛的改进,包括
checkFields()
(如果代码检查一组字段,那么它是流的一个很好的候选者)。与整体功能风格体系结构搭配使用时,Functional效果最佳。