mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 20:42:52 +07:00
StreamToLoop tests grouped
This commit is contained in:
+35
@@ -0,0 +1,35 @@
|
||||
// "Fix all 'Stream API call chain can be replaced with loop' problems in file" "true"
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.*;
|
||||
|
||||
public class Main {
|
||||
public long testCount(List<String> list) {
|
||||
long count = 0L;
|
||||
Set<String> uniqueValues = new HashSet<>();
|
||||
for (String s : list) {
|
||||
if (uniqueValues.add(s)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
private static List<Object> testToList(List<? extends Number> numbers) {
|
||||
List<Object> list = new ArrayList<>();
|
||||
Set<Number> uniqueValues = new HashSet<>();
|
||||
for (Number number : numbers) {
|
||||
if (uniqueValues.add(number)) {
|
||||
list.add(number);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(testToList(Arrays.asList(1,2,3,5,3,2,2,2,1,1,4,3)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user