diff options
-rw-r--r-- | container-search/src/main/java/com/yahoo/search/result/HitGroup.java | 14 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java | 7 |
2 files changed, 13 insertions, 8 deletions
diff --git a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java index a12a2566f68..056976724bb 100644 --- a/container-search/src/main/java/com/yahoo/search/result/HitGroup.java +++ b/container-search/src/main/java/com/yahoo/search/result/HitGroup.java @@ -500,15 +500,15 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< if (hit.isAuxiliary()) continue; currentIndex++; - if (currentIndex < offset || currentIndex >= highBound) { + if (currentIndex < offset || currentIndex >= highBound) handleRemovedHit(hit); - } } if ((offset > 0) || (hits.size() > highBound)) { ListenableArrayList<Hit> newHits = new ListenableArrayList<>(numHits); - for (int index = offset; index < Math.min(highBound, hits.size()); index++) { + for (int index = offset; index < Math.min(highBound, hits.size()); index++) newHits.add(hits.get(index)); - } + for (Runnable listener : hits.listeners()) + newHits.addListener(listener); hits = newHits; unmodifiableHits = Collections.unmodifiableList(hits); } @@ -842,7 +842,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< Hit hitClone = i.next().clone(); hitGroupClone.hits.add(hitClone); } - if (this.errorHit!=null) { // Find the cloned error and assign it + if (this.errorHit != null) { // Find the cloned error and assign it for (Hit hit : hitGroupClone.asList()) { if (hit instanceof DefaultErrorHit) hitGroupClone.errorHit=(DefaultErrorHit)hit; @@ -874,7 +874,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< /* This is an optimisation to avoid creating many temporary hash sets in the happy path. The simple naive implementation is - Set<String> filled = null; + Set<String> filled = null; for (Hit hit : hits) { if (hit.getFilled() == null) continue; if (filled == null) @@ -883,7 +883,7 @@ public class HitGroup extends Hit implements DataList<Hit>, Cloneable, Iterable< filled.retainAll(hit.getFilled()); } return filled; - */ + */ Iterator<Hit> iterator = hits.iterator(); Set<String> firstSummaryNames = getSummaryNamesNextFilledHit(iterator); if (firstSummaryNames == null || firstSummaryNames.isEmpty()) diff --git a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java index e3f73212170..44569471049 100644 --- a/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java +++ b/vespajlib/src/main/java/com/yahoo/collections/ListenableArrayList.java @@ -3,13 +3,13 @@ package com.yahoo.collections; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.List; /** * An array list which notifies listeners after one or more items are added * * @author bratseth - * @since 5.1.17 */ @SuppressWarnings("serial") public class ListenableArrayList<ITEM> extends ArrayList<ITEM> { @@ -56,6 +56,11 @@ public class ListenableArrayList<ITEM> extends ArrayList<ITEM> { return result; } + public List<Runnable> listeners() { + if (listeners == null) return Collections.emptyList(); + return Collections.unmodifiableList(listeners); + } + /** * Adds a listener which is invoked whenever elements are added to this. * This may not be invoked once for each added element. |