JBIterator: employ skip() in flatten()

This commit is contained in:
Gregory.Shrago
2016-04-26 19:53:42 +03:00
parent 082d80f4bd
commit 4564ba2ce5
2 changed files with 6 additions and 10 deletions
@@ -245,7 +245,7 @@ public class TreeTraverserTest extends TestCase {
// JBIterable ----------------------------------------------
public void testAppend() {
JBIterable<Integer> it = JBIterable.of(1, 2, 3).append(JBIterable.of(4, 5, 6)).append(7);
JBIterable<Integer> it = JBIterable.of(1, 2, 3).append(JBIterable.of(4, 5, 6)).append(JBIterable.empty()).append(7);
assertEquals(7, it.size());
assertEquals(Arrays.asList(1, 2, 3, 4, 5, 6, 7), it.toList());
assertTrue(it.contains(5));
@@ -20,7 +20,6 @@ import com.intellij.openapi.util.Comparing;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Conditions;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.Function;
import com.intellij.util.Functions;
import com.intellij.util.PairFunction;
@@ -193,9 +192,7 @@ public abstract class JBIterable<E> implements Iterable<E> {
*/
@Override
public String toString() {
int max = 50;
List<E> list = take(max + 1).toList();
return "(" + StringUtil.join(list.subList(0, Math.min(list.size(), max)), ", ") + (list.size() > max ? ", ..." : "") + ")";
return myIterable == this ? super.toString() : String.valueOf(myIterable);
}
/**
@@ -365,11 +362,10 @@ public abstract class JBIterable<E> implements Iterable<E> {
@Override
public T nextImpl() {
while ((cur == null || !cur.hasNext()) && iterator.hasNext()) {
cur = fun.fun(iterator.next()).iterator();
}
if (cur == null || !cur.hasNext()) return stop();
return cur.next();
if (cur != null && cur.hasNext()) return cur.next();
if (!iterator.hasNext()) return stop();
cur = fun.fun(iterator.next()).iterator();
return skip();
}
@Override