StreamToLoop: special handling of skip(1)

This commit is contained in:
Tagir Valeev
2018-03-12 14:47:53 +07:00
parent 6ece8e587e
commit ebbdbbe432
5 changed files with 21 additions and 16 deletions

View File

@@ -8,10 +8,10 @@ public class Main {
private static long test() {
long count = 0L;
Set<Integer> uniqueValues = new HashSet<>();
long toSkip = 1;
boolean first = true;
for (Integer integer : new Integer[]{1, 2, 3, 2, 3}) {
if (toSkip > 0) {
toSkip--;
if (first) {
first = false;
continue;
}
if (uniqueValues.add(integer)) {

View File

@@ -204,7 +204,7 @@ public class Main {
public static IntSummaryStatistics testNestedSkip(int... values) {
IntSummaryStatistics stat = new IntSummaryStatistics();
long toSkipOuter = 1;
long toSkipOuter = 2;
for (int x : values) {
if (toSkipOuter > 0) {
toSkipOuter--;
@@ -226,7 +226,7 @@ public class Main {
public static IntSummaryStatistics testNestedSkip2(int... values) {
IntSummaryStatistics stat = new IntSummaryStatistics();
long toSkip = 1;
long toSkip = 2;
for (int x : values) {
if (x > 0) {
long toSkipInner = x;

View File

@@ -7,10 +7,10 @@ public class Main {
private static String test0(List<CharSequence> list) {
StringBuilder sb = new StringBuilder();
Set<CharSequence> uniqueValues = new HashSet<>();
long toSkip = 1;
boolean first = true;
for (CharSequence charSequence : list) {
if (toSkip > 0) {
toSkip--;
if (first) {
first = false;
continue;
}
if (uniqueValues.add(charSequence)) {
@@ -24,10 +24,10 @@ public class Main {
StringJoiner joiner = new StringJoiner(delimiter);
long toSkip = 2;
Set<CharSequence> uniqueValues = new HashSet<>();
long toSkip1 = 1;
boolean first = true;
for (CharSequence charSequence : list) {
if (toSkip1 > 0) {
toSkip1--;
if (first) {
first = false;
continue;
}
if (uniqueValues.add(charSequence)) {
@@ -44,10 +44,10 @@ public class Main {
private static String test3(List<CharSequence> list, String delimiter) {
StringJoiner joiner = new StringJoiner(delimiter, "<", ">");
Set<CharSequence> uniqueValues = new HashSet<>();
long toSkip = 1;
boolean first = true;
for (CharSequence charSequence : list) {
if (toSkip > 0) {
toSkip--;
if (first) {
first = false;
continue;
}
if (uniqueValues.add(charSequence)) {

View File

@@ -73,11 +73,11 @@ public class Main {
}
public static IntSummaryStatistics testNestedSkip(int... values) {
return Arrays.stream(values).skip(1).filter(x -> x > 0).flatMap(v -> IntStream.range(0, 100).skip(v)).summaryStatistics();
return Arrays.stream(values).skip(2).filter(x -> x > 0).flatMap(v -> IntStream.range(0, 100).skip(v)).summaryStatistics();
}
public static IntSummaryStatistics testNestedSkip2(int... values) {
return Arrays.stream(values).filter(x -> x > 0).flatMap(v -> IntStream.range(0, 100).skip(v)).skip(1).summaryStatistics();
return Arrays.stream(values).filter(x -> x > 0).flatMap(v -> IntStream.range(0, 100).skip(v)).skip(2).summaryStatistics();
}
public String testSorted(List<List<String>> list) {