提交 c40a60e9 编写于 作者: J Josh Soref 提交者: Oleg Nenashev

[JENKINS-53177] - Promote ConsoleAnnotatorAggregator to try to fix Anonymous complaint (#3598)

JENKINS-53177
上级 c0d9fb75
......@@ -91,41 +91,42 @@ public abstract class ConsoleAnnotator<T> implements Serializable {
return (ConsoleAnnotator)a;
}
/**
* Bundles all the given {@link ConsoleAnnotator} into a single annotator.
*/
public static <T> ConsoleAnnotator<T> combine(Collection<? extends ConsoleAnnotator<? super T>> all) {
switch (all.size()) {
case 0: return null; // none
case 1: return cast(all.iterator().next()); // just one
}
class Aggregator extends ConsoleAnnotator<T> {
List<ConsoleAnnotator<T>> list;
private static final class ConsoleAnnotatorAggregator<T> extends ConsoleAnnotator<T> {
List<ConsoleAnnotator<T>> list;
Aggregator(Collection list) {
this.list = new ArrayList<ConsoleAnnotator<T>>(list);
}
ConsoleAnnotatorAggregator(Collection list) {
this.list = new ArrayList<ConsoleAnnotator<T>>(list);
}
public ConsoleAnnotator annotate(T context, MarkupText text) {
ListIterator<ConsoleAnnotator<T>> itr = list.listIterator();
while (itr.hasNext()) {
ConsoleAnnotator a = itr.next();
ConsoleAnnotator b = a.annotate(context,text);
if (a!=b) {
if (b==null) itr.remove();
else itr.set(b);
}
public ConsoleAnnotator annotate(T context, MarkupText text) {
ListIterator<ConsoleAnnotator<T>> itr = list.listIterator();
while (itr.hasNext()) {
ConsoleAnnotator a = itr.next();
ConsoleAnnotator b = a.annotate(context,text);
if (a!=b) {
if (b==null) itr.remove();
else itr.set(b);
}
}
switch (list.size()) {
switch (list.size()) {
case 0: return null; // no more annotator left
case 1: return list.get(0); // no point in aggregating
default: return this;
}
}
}
return new Aggregator(all);
}
/**
* Bundles all the given {@link ConsoleAnnotator} into a single annotator.
*/
public static <T> ConsoleAnnotator<T> combine(Collection<? extends ConsoleAnnotator<? super T>> all) {
switch (all.size()) {
case 0: return null; // none
case 1: return cast(all.iterator().next()); // just one
}
return new ConsoleAnnotatorAggregator<T>(all);
}
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册