mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 18:28:55 +07:00
IDEA-164880 Refactoring to function composition methods
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn() {
|
||||
Function<String, Integer> lookup = Integer::parseInt;
|
||||
UnaryOperator<String> selector = String::trim;
|
||||
BinaryOperator<Integer> min = Math::min;
|
||||
String foo = "xyz";
|
||||
|
||||
int res = min.andThen(Math::abs).apply(-1, -2);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn() {
|
||||
Function<String, Integer> lookup = Integer::parseInt;
|
||||
UnaryOperator<String> selector = String::trim;
|
||||
BinaryOperator<Integer> min = Math::min;
|
||||
String foo = "xyz";
|
||||
|
||||
/*check*/
|
||||
|
||||
boolean b = selector.andThen(Collections.singleton(/* "xyz" here */ "xyz")::contains).apply(/* foo here */ foo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn(boolean b) {
|
||||
String foo = "xyz";
|
||||
|
||||
Integer f = (b ? (UnaryOperator<String>) String::trim : (UnaryOperator<String>) s -> s.substring(1)).andThen(Integer::parseInt).apply(foo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn() {
|
||||
Function<String, Integer> lookup = Integer::parseInt;
|
||||
UnaryOperator<String> selector = String::trim;
|
||||
BinaryOperator<Integer> min = Math::min;
|
||||
String foo = "xyz";
|
||||
|
||||
Integer integer = selector.andThen(lookup).apply(" " + foo);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn() {
|
||||
Function<String, Integer> lookup = Integer::parseInt;
|
||||
UnaryOperator<String> selector = String::trim;
|
||||
BinaryOperator<Integer> min = Math::min;
|
||||
String foo = "xyz";
|
||||
|
||||
int res = Math.abs(min.a<caret>pply(-1,-2));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn() {
|
||||
Function<String, Integer> lookup = Integer::parseInt;
|
||||
UnaryOperator<String> selector = String::trim;
|
||||
BinaryOperator<Integer> min = Math::min;
|
||||
String foo = "xyz";
|
||||
|
||||
boolean b = Collections.singleton(/* "xyz" here */ "xyz").contains(/*check*/sel<caret>ector.apply(/* foo here */ foo));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn(boolean b) {
|
||||
String foo = "xyz";
|
||||
|
||||
Integer f = Integer.parseInt(
|
||||
(b ? (UnaryOperator<String>) String::trim : (UnaryOperator<String>) s -> s.substring(1)).apply(fo<caret>o));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// "Replace nested function call with andThen call" "true"
|
||||
|
||||
import java.util.function.BinaryOperator;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
public class Main {
|
||||
private void testFn() {
|
||||
Function<String, Integer> lookup = Integer::parseInt;
|
||||
UnaryOperator<String> selector = String::trim;
|
||||
BinaryOperator<Integer> min = Math::min;
|
||||
String foo = "xyz";
|
||||
|
||||
Integer integer = lookup.apply(sele<caret>ctor.apply(" " + foo));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user