mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-08-25 14:25:04 +07:00
StreamToLoop: min/max: Comparators as lambdas/method references supported; Comparator.naturalOrder() and reverseOrder() inlined.
This commit is contained in:
+1
-2
@@ -5,12 +5,11 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class Main {
|
||||
public static Optional<String> test(List<String> strings) {
|
||||
Comparator<String> comparator = Comparator.naturalOrder();
|
||||
boolean seen = false;
|
||||
String best = null;
|
||||
for (String s : strings) {
|
||||
if (!s.isEmpty()) {
|
||||
if (!seen || comparator.compare(s, best) > 0) {
|
||||
if (!seen || s.compareTo(best) > 0) {
|
||||
seen = true;
|
||||
best = s;
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,9 +6,9 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static String test(List<String> strings) {
|
||||
Comparator<String> comparator = Comparator.comparing(String::length);
|
||||
boolean seen = false;
|
||||
String best = null;
|
||||
Comparator<String> comparator = Comparator.comparing(String::length);
|
||||
for (String string : strings) {
|
||||
if (!seen || comparator.compare(string, best) > 0) {
|
||||
seen = true;
|
||||
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static Optional<String> max(Map<String, List<String>> dependencies, String fruits, Map<String, String> weights) {
|
||||
boolean seen = false;
|
||||
String best = null;
|
||||
for (String s : dependencies.get(fruits)) {
|
||||
if (!seen || weights.get(s).compareTo(weights.get(best)) > 0) {
|
||||
seen = true;
|
||||
best = s;
|
||||
}
|
||||
}
|
||||
return seen ? Optional.of(best) : Optional.empty();
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static Optional<String> max(Map<String, List<String>> dependencies, String fruits, Map<String, String> weights) {
|
||||
boolean seen = false;
|
||||
String best = null;
|
||||
for (String s : dependencies.get(fruits)) {
|
||||
if (!seen || best.compareTo(s) > 0) {
|
||||
seen = true;
|
||||
best = s;
|
||||
}
|
||||
}
|
||||
return seen ? Optional.of(best) : Optional.empty();
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -6,9 +6,9 @@ import java.util.List;
|
||||
|
||||
public class Main {
|
||||
public static String test(List<String> strings, Comparator<CharSequence> comparator) {
|
||||
Comparator<CharSequence> comparator1 = comparator.reversed();
|
||||
boolean seen = false;
|
||||
String best = null;
|
||||
Comparator<CharSequence> comparator1 = comparator.reversed();
|
||||
for (String string : strings) {
|
||||
if (!seen || comparator1.compare(string, best) < 0) {
|
||||
seen = true;
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static Optional<String> max(Map<String, List<String>> dependencies, String fruits, Map<String, String> weights) {
|
||||
return dependencies.get(fruits).stream().m<caret>ax((o1, o2) -> weights.get(o1).compareTo(weights.get(o2)));
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
// "Replace Stream API chain with loop" "true"
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class Main {
|
||||
private static Optional<String> max(Map<String, List<String>> dependencies, String fruits, Map<String, String> weights) {
|
||||
return dependencies.get(fruits).stream().m<caret>ax(Collections.reverseOrder());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user