提交 04b0283d 编写于 作者: K Kohsuke Kawaguchi

[JENKINS-15465] tweaking subList implementation and iterator.

I can't really think of how null ends up in the resulting list, but adding a check in Iterator to detect that situation.

Also, improved the efficiency of the subList implementation.
(cherry picked from commit 807dc717)
上级 6fca1f08
......@@ -36,6 +36,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.SortedMap;
import java.util.logging.Level;
import java.util.logging.Logger;
......@@ -104,6 +105,8 @@ public final class RunMap<R extends Run<?,R>> extends AbstractLazyLoadRunMap<R>
R last = next;
if (last!=null)
next = last.getPreviousBuild();
else
throw new NoSuchElementException();
return last;
}
......
......@@ -44,6 +44,7 @@ import java.util.Comparator;
import java.util.GregorianCalendar;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
/**
* {@link List} of {@link Run}s, sorted in the descending date order.
......@@ -128,6 +129,25 @@ public class RunList<R extends Run> extends AbstractList<R> {
return Iterators.get(iterator(),index);
}
/**
* {@link AbstractList#subList(int, int)} isn't very efficient on our {@link Iterable} based implementation.
* In fact the range check alone would require us to iterate all the elements,
* so we'd be better off just copying into ArrayList.
*/
@Override
public List<R> subList(int fromIndex, int toIndex) {
List<R> r = new ArrayList<R>();
Iterator<R> itr = iterator();
Iterators.skip(itr,fromIndex);
for (int i=toIndex-fromIndex; i>0; i--) {
if (itr.hasNext())
r.add(itr.next());
else
throw new NoSuchElementException();
}
return r;
}
@Override
public int indexOf(Object o) {
int index=0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册