import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
-import com.google.common.collect.Iterables;
/**
* Base class for history trees that encapsulates the logic to read from/write
// TODO Change this to evaluate the nodes lazily
- List<Iterable<E>> intervalsOfNodes = new LinkedList<>();
+ List<E> intervalsOfNodes = new ArrayList<>();
/* Queue is a stack of nodes containing nodes intersecting t */
Deque<Integer> queue = new LinkedList<>();
/* Here we add the relevant children nodes for BFS */
queue.addAll(currentNode.selectNextChildren(nodeCondition));
}
- Iterable<E> nodeIntervals = currentNode.getMatchingIntervals(nodeCondition, extraPredicate);
- intervalsOfNodes.add(nodeIntervals);
+ Collection<E> nodeIntervals = currentNode.getMatchingIntervals(nodeCondition, extraPredicate);
+ intervalsOfNodes.addAll(nodeIntervals);
}
} catch (ClosedChannelException e) {
}
- return Iterables.concat(intervalsOfNodes);
+ return intervalsOfNodes;
}
@Override
import java.util.Objects;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.function.Predicate;
-import java.util.stream.Collectors;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
public final Collection<Integer> selectNextChildren(TimeRangeCondition timeCondition) {
fNode.takeReadLock();
try {
- return selectNextIndices(timeCondition).stream()
- .map(i -> fChildren[i])
- .collect(Collectors.toList());
+ List<Integer> list = new ArrayList<>();
+ for (int index : selectNextIndices(timeCondition)) {
+ list.add(fChildren[index]);
+ }
+ return list;
} finally {
fNode.releaseReadLock();
}
}
@Override
- public Iterable<E> getMatchingIntervals(TimeRangeCondition timeCondition,
+ public Collection<E> getMatchingIntervals(TimeRangeCondition timeCondition,
Predicate<E> extraPredicate) {
// TODO Benchmark using/returning streams instead of iterables
-
if (isOnDisk()) {
return doGetMatchingIntervals(timeCondition, extraPredicate);
}
}
}
- private Iterable<E> doGetMatchingIntervals(TimeRangeCondition timeCondition,
+ private Collection<E> doGetMatchingIntervals(TimeRangeCondition timeCondition,
Predicate<E> extraPredicate) {
List<E> list = new ArrayList<>();
for (int i = getStartIndexFor(timeCondition, extraPredicate); i < fIntervals.size(); i++) {