This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
commit 7e8d0565cd7eb2f413cd28a2c16a8a96f1814d16 Author: Martin Desruisseaux <[email protected]> AuthorDate: Thu Jan 16 10:20:28 2020 +0100 Minor documentation correction, argument checks and add "TODO" tag for remembering next work to do. --- .../org/apache/sis/index/tree/NodeIterator.java | 4 ++++ .../java/org/apache/sis/index/tree/PointTree.java | 25 +++++++++++++++------- .../org/apache/sis/index/tree/PointTreeTest.java | 5 +++-- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/index/tree/NodeIterator.java b/core/sis-feature/src/main/java/org/apache/sis/index/tree/NodeIterator.java index 95f78d2..3bd0a29 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/index/tree/NodeIterator.java +++ b/core/sis-feature/src/main/java/org/apache/sis/index/tree/NodeIterator.java @@ -401,6 +401,7 @@ class NodeIterator<E> implements Spliterator<E> { } if (half != 0) { return new NodeIterator<>(this, half); + // TODO: check if new.current != null. } // TODO: go down in the tree and explore other nodes. } @@ -409,6 +410,9 @@ class NodeIterator<E> implements Spliterator<E> { /** * Returns an estimate of the number of elements or {@link Long#MAX_VALUE} if too expensive to compute. + * + * @todo Compute an estimated size by multiplying {@link PointTree#count} by the percentage of bits set + * in {@link Cursor#quadrants} (use {@link #bitmask} for the number of bits in the 100% case). */ @Override public long estimateSize() { diff --git a/core/sis-feature/src/main/java/org/apache/sis/index/tree/PointTree.java b/core/sis-feature/src/main/java/org/apache/sis/index/tree/PointTree.java index 655c55e..b1e0e29 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/index/tree/PointTree.java +++ b/core/sis-feature/src/main/java/org/apache/sis/index/tree/PointTree.java @@ -148,7 +148,7 @@ public class PointTree<E> extends AbstractSet<E> implements CheckedContainer<E>, /** * Whether the stream can be parallel by default. - * Should be true only if the {@link #locator} is thread safe. + * Should be {@code false} if the {@link #locator} is not thread-safe. */ private final boolean parallel; @@ -171,8 +171,8 @@ public class PointTree<E> extends AbstractSet<E> implements CheckedContainer<E>, * @param bounds bounds of the region of data to be inserted in the <var>k</var>-dimensional tree. * @param locator function computing a position for an arbitrary element of this tree. * @param nodeCapacity the capacity of each node (not to be confused with a capacity of the tree). - * @param parallel Whether the stream can be parallel by default. - * Should be true only if the given {@code locator} is thread safe. + * @param parallel whether the stream can be parallel by default. + * Should be {@code false} if the given {@code locator} is not thread-safe. */ public PointTree(final Class<E> elementType, final Envelope bounds, final Function<? super E, double[]> locator, final int nodeCapacity, final boolean parallel) @@ -182,16 +182,21 @@ public class PointTree<E> extends AbstractSet<E> implements CheckedContainer<E>, ArgumentChecks.ensureNonNull ("locator", locator); ArgumentChecks.ensureStrictlyPositive("nodeCapacity", nodeCapacity); final int n = bounds.getDimension(); - if (n < 2) { - throw new IllegalArgumentException(Errors.format(Errors.Keys.MismatchedDimension_3, "bounds", 2, n)); - } if (n > MAXIMUM_DIMENSIONS) { throw new IllegalArgumentException(Errors.format(Errors.Keys.ExcessiveNumberOfDimensions_1, n)); } treeRegion = new double[n*2]; + boolean isValid = (n >= 2); for (int i=0; i<n; i++) { - ArgumentChecks.ensureFinite("treeRegion", treeRegion[i] = bounds.getMedian(i)); - ArgumentChecks.ensureFinite("treeRegion", treeRegion[i+n] = bounds.getSpan(i)); + final double m = treeRegion[i] = bounds.getMedian(i); + final double s = treeRegion[i+n] = bounds.getSpan(i); + isValid &= !Double.isNaN(m) && (s > 0); + if (Double.isInfinite(m) || Double.isInfinite(s)) { + throw new IllegalArgumentException(Errors.format(Errors.Keys.InfiniteArgumentValue_1, "treeRegion")); + } + } + if (!isValid) { + throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyEnvelope2D)); } this.crs = bounds.getCoordinateReferenceSystem(); this.elementType = elementType; @@ -206,6 +211,8 @@ public class PointTree<E> extends AbstractSet<E> implements CheckedContainer<E>, * The CRS is taken from the envelope given in argument to the constructor. * * @return the CRS of all points in this tree, if presents. + * + * @see #getDimension() */ public final Optional<CoordinateReferenceSystem> getCoordinateReferenceSystem() { return Optional.ofNullable(crs); @@ -215,6 +222,8 @@ public class PointTree<E> extends AbstractSet<E> implements CheckedContainer<E>, * Returns the number of dimensions of points in this tree. * * @return the number of dimensions of points in this tree. + * + * @see #getCoordinateReferenceSystem() */ public final int getDimension() { return treeRegion.length >>> 1; diff --git a/core/sis-feature/src/test/java/org/apache/sis/index/tree/PointTreeTest.java b/core/sis-feature/src/test/java/org/apache/sis/index/tree/PointTreeTest.java index 40b830f..081b5c0 100644 --- a/core/sis-feature/src/test/java/org/apache/sis/index/tree/PointTreeTest.java +++ b/core/sis-feature/src/test/java/org/apache/sis/index/tree/PointTreeTest.java @@ -155,9 +155,10 @@ public final strictfp class PointTreeTest extends TestCase { @Test public void testSpliterator() { createTree(); - final List<Spliterator<Element>> iterators = new ArrayList<>(2); + final int n = 4; // Maximal number of splits. + final List<Spliterator<Element>> iterators = new ArrayList<>(n); iterators.add(tree.spliterator()); - for (int i=0; i<4; i++) { + for (int i=0; i<n; i++) { Spliterator<Element> it = iterators.get(iterators.size() - 1); it = it.trySplit(); if (it != null) {
