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 531be33a7856498b87b29e21056bd39d8ac75eaa Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Mon Aug 15 13:14:41 2022 +0200 Move `Result` inner class as a top-level class. There is no code change other than this move. --- .../sis/internal/processing/isoline/Isolines.java | 59 +------------ .../sis/internal/processing/isoline/Result.java | 98 ++++++++++++++++++++++ 2 files changed, 99 insertions(+), 58 deletions(-) diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/processing/isoline/Isolines.java b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/isoline/Isolines.java index abb8792332..a0ec6005f2 100644 --- a/core/sis-feature/src/main/java/org/apache/sis/internal/processing/isoline/Isolines.java +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/isoline/Isolines.java @@ -16,7 +16,6 @@ */ package org.apache.sis.internal.processing.isoline; -import java.util.AbstractList; import java.util.Arrays; import java.util.List; import java.util.Map; @@ -25,8 +24,6 @@ import java.util.TreeMap; import java.util.NavigableMap; import java.util.function.BiConsumer; import java.util.concurrent.Future; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.CompletionException; import java.awt.Shape; import java.awt.geom.Path2D; import java.awt.image.RenderedImage; @@ -37,7 +34,6 @@ import org.apache.sis.internal.processing.image.TiledProcess; import org.apache.sis.image.PixelIterator; import org.apache.sis.util.ArgumentChecks; import org.apache.sis.util.ArraysExt; -import org.apache.sis.util.resources.Errors; import org.apache.sis.util.Debug; import static org.apache.sis.internal.processing.isoline.Tracer.UPPER_LEFT; @@ -443,7 +439,7 @@ abort: while (iterator.next()) { * @param isolines result of {@code generate(…)} or {@code parallelGenerate(…)} method call. * @return isoline shapes for each values in each band. */ - private static NavigableMap<Double,Shape>[] toArray(final Isolines[] isolines) { + static NavigableMap<Double,Shape>[] toArray(final Isolines[] isolines) { @SuppressWarnings({"rawtypes", "unchecked"}) final NavigableMap<Double,Shape>[] result = new NavigableMap[isolines.length]; for (int i=0; i<result.length; i++) { @@ -473,59 +469,6 @@ abort: while (iterator.next()) { return new Result(isolines); } - /** - * Deferred isoline result, created when computation is continuing in background. - * The {@link Future} result is requested the first time that {@link #get(int)} is invoked. - */ - private static final class Result extends AbstractList<NavigableMap<Double,Shape>> { - /** The task computing isolines result. Reset to {@code null} when no longer needed. */ - private Future<Isolines[]> task; - - /** The result of {@link Future#get()} fetched when first needed. */ - private NavigableMap<Double,Shape>[] isolines; - - /** Creates a new list for the given future isolines. */ - Result(final Future<Isolines[]> task) { - this.task = task; - } - - /** Fetches the isolines from the {@link Future} if not already done. */ - @SuppressWarnings("ReturnOfCollectionOrArrayField") - private NavigableMap<Double,Shape>[] isolines() { - if (isolines == null) { - if (task == null) { - throw new CompletionException(Errors.format(Errors.Keys.BackgroundComputationFailed), null); - } - try { - isolines = Isolines.toArray(task.get()); - task = null; - } catch (InterruptedException e) { - // Do not clear `task`: the result may become available later. - throw new CompletionException(Errors.format(Errors.Keys.InterruptedWhileWaitingResult), e); - } catch (ExecutionException e) { - task = null; - throw new CompletionException(Errors.format(Errors.Keys.BackgroundComputationFailed), e.getCause()); - } - } - return isolines; - } - - /** Returns the list length, which is the number of bands. */ - @Override public int size() { - return isolines().length; - } - - /** Returns the isolines in the given band. */ - @Override public NavigableMap<Double,Shape> get(final int band) { - return isolines()[band]; - } - - /** Returns the list content as an array. */ - @Override public Object[] toArray() { - return isolines().clone(); - } - } - /** * Returns the pixel coordinates of all level, for debugging purposes only. * The {@link #gridToCRS} transform is <em>not</em> applied by this method. diff --git a/core/sis-feature/src/main/java/org/apache/sis/internal/processing/isoline/Result.java b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/isoline/Result.java new file mode 100644 index 0000000000..8eaa48ffb4 --- /dev/null +++ b/core/sis-feature/src/main/java/org/apache/sis/internal/processing/isoline/Result.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.sis.internal.processing.isoline; + +import java.awt.Shape; +import java.util.AbstractList; +import java.util.NavigableMap; +import java.util.concurrent.Future; +import java.util.concurrent.CompletionException; +import java.util.concurrent.ExecutionException; +import org.apache.sis.util.resources.Errors; + + +/** + * Deferred isoline result, created when computation is continuing in background. + * The {@link Future} result is requested the first time that {@link #get(int)} is invoked. + * + * @author Martin Desruisseaux (Geomatys) + * @version 1.3 + * @since 1.1 + * @module + */ +final class Result extends AbstractList<NavigableMap<Double,Shape>> { + /** + * The task computing isolines result. Reset to {@code null} when no longer needed. + */ + private Future<Isolines[]> task; + + /** + * The result of {@link Future#get()} fetched when first needed. + */ + private NavigableMap<Double,Shape>[] isolines; + + /** + * Creates a new list for the given future isolines. + */ + Result(final Future<Isolines[]> task) { + this.task = task; + } + + /** + * Fetches the isolines from the {@link Future} if not already done. + */ + @SuppressWarnings("ReturnOfCollectionOrArrayField") + private NavigableMap<Double,Shape>[] isolines() { + if (isolines == null) { + if (task == null) { + throw new CompletionException(Errors.format(Errors.Keys.BackgroundComputationFailed), null); + } + try { + isolines = Isolines.toArray(task.get()); + task = null; + } catch (InterruptedException e) { + // Do not clear `task`: the result may become available later. + throw new CompletionException(Errors.format(Errors.Keys.InterruptedWhileWaitingResult), e); + } catch (ExecutionException e) { + task = null; + throw new CompletionException(Errors.format(Errors.Keys.BackgroundComputationFailed), e.getCause()); + } + } + return isolines; + } + + /** + * Returns the list length, which is the number of bands. + */ + @Override public int size() { + return isolines().length; + } + + /** + * Returns the isolines in the given band. + */ + @Override public NavigableMap<Double,Shape> get(final int band) { + return isolines()[band]; + } + + /** + * Returns the list content as an array. + */ + @Override public Object[] toArray() { + return isolines().clone(); + } +}