You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2020/11/24 22:25:16 UTC
[sis] 03/03: Reduce a little bit the amount of text in `GridGeometry.toString()` and in `AbstractGridResource.logLoadOperation(…)`.
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 925eccfbe2ba78561b71aee65c5778429539eb9f
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Tue Nov 24 22:19:39 2020 +0100
Reduce a little bit the amount of text in `GridGeometry.toString()` and in `AbstractGridResource.logLoadOperation(…)`.
---
.../org/apache/sis/coverage/grid/GridCoverage.java | 2 +-
.../org/apache/sis/coverage/grid/GridGeometry.java | 23 +++++++++++++---------
.../sis/internal/referencing/TemporalAccessor.java | 14 ++++++++++---
.../sis/internal/storage/AbstractGridResource.java | 18 ++++++++++-------
4 files changed, 37 insertions(+), 20 deletions(-)
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
index 5b5e9d6..70f729b 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridCoverage.java
@@ -374,7 +374,7 @@ public abstract class GridCoverage {
*/
@Override
public String toString() {
- return toTree(Locale.getDefault(), GridGeometry.defaultFlags()).toString();
+ return toTree(Locale.getDefault(), gridGeometry.defaultFlags()).toString();
}
/**
diff --git a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
index 522a87b..bea2355 100644
--- a/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
+++ b/core/sis-feature/src/main/java/org/apache/sis/coverage/grid/GridGeometry.java
@@ -943,7 +943,7 @@ public class GridGeometry implements LenientComparable, Serializable {
Instant[] times = timeRange;
if (times == null) {
final TemporalAccessor t = TemporalAccessor.of(getCoordinateReferenceSystem(envelope), 0);
- times = (t != null) ? t.getTimeRange(envelope) : new Instant[0];
+ times = (t != null) ? t.getTimeRange(envelope) : TemporalAccessor.EMPTY;
timeRange = times;
}
return times;
@@ -1409,11 +1409,16 @@ public class GridGeometry implements LenientComparable, Serializable {
/**
* Returns the default set of flags to use for {@link #toString()} implementations.
- * Current implementation returns all flags, but future implementation may omit some
- * flags if experience suggests that they are too verbose in practice.
+ * Current implementation returns all core properties, augmented with only derived
+ * properties that are defined.
*/
- static int defaultFlags() {
- return EXTENT | ENVELOPE | CRS | GRID_TO_CRS | RESOLUTION | GEOGRAPHIC_EXTENT | TEMPORAL_EXTENT;
+ final int defaultFlags() {
+ int flags = EXTENT | GRID_TO_CRS | CRS;
+ if (null != envelope) flags |= ENVELOPE;
+ if (null != resolution) flags |= RESOLUTION;
+ if (null != geographicBBox()) flags |= GEOGRAPHIC_EXTENT;
+ if (timeRange().length != 0) flags |= TEMPORAL_EXTENT;
+ return flags;
}
/**
@@ -1430,8 +1435,8 @@ public class GridGeometry implements LenientComparable, Serializable {
/**
* Returns a tree representation of some elements of this grid geometry.
- * The tree representation is for debugging purpose only and may change
- * in any future SIS version.
+ * The tree representation is for debugging or logging purposes
+ * and may change in any future SIS version.
*
* @param locale the locale to use for textual labels.
* @param bitmask combination of {@link #EXTENT}, {@link #ENVELOPE}, {@link #CRS}, {@link #GRID_TO_CRS},
@@ -1553,10 +1558,10 @@ public class GridGeometry implements LenientComparable, Serializable {
{
final TableAppender table = new TableAppender(buffer, " ");
final AngleFormat nf = new AngleFormat("DD°MM′SS″", locale);
- final GeographicBoundingBox bbox = geographicBBox();
+ final GeographicBoundingBox bbox = ((bitmask & GEOGRAPHIC_EXTENT) != 0) ? geographicBBox() : null;
double westBoundLongitude = Double.NaN;
double eastBoundLongitude = Double.NaN;
- final Instant[] times = timeRange();
+ final Instant[] times = ((bitmask & TEMPORAL_EXTENT) != 0) ? timeRange() : TemporalAccessor.EMPTY;
vocabulary.appendLabel(Vocabulary.Keys.LowerBound, table);
table.setCellAlignment(TableAppender.ALIGN_RIGHT);
if (bbox != null) {
diff --git a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/TemporalAccessor.java b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/TemporalAccessor.java
index 580651d..0a80be8 100644
--- a/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/TemporalAccessor.java
+++ b/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/TemporalAccessor.java
@@ -28,12 +28,17 @@ import org.apache.sis.geometry.AbstractEnvelope;
* Convenience methods for accessing the temporal component of an object (envelope, grid geometry…).
*
* @author Martin Desruisseaux (Geomatys)
- * @version 1.0
+ * @version 1.1
* @since 1.0
* @module
*/
public final class TemporalAccessor {
/**
+ * Empty array of instants.
+ */
+ public static final Instant[] EMPTY = new Instant[0];
+
+ /**
* Dimension of the temporal component.
*/
public final int dimension;
@@ -85,15 +90,18 @@ public final class TemporalAccessor {
* @param envelope the envelope from which to get the start time end end time.
* @return the start time and end time in an array of length 1 or 2, or an empty array if none.
*/
- @SuppressWarnings("fallthrough")
+ @SuppressWarnings({"fallthrough", "ReturnOfCollectionOrArrayField"})
public Instant[] getTimeRange(final AbstractEnvelope envelope) {
Instant startTime = timeCRS.toInstant(envelope.getLower(dimension));
Instant endTime = timeCRS.toInstant(envelope.getUpper(dimension));
if (startTime == null) {
+ if (endTime == null) {
+ return EMPTY;
+ }
startTime = endTime;
endTime = null;
}
- Instant[] times = new Instant[(endTime != null) ? 2 : (startTime != null) ? 1 : 0];
+ final Instant[] times = new Instant[(endTime != null) ? 2 : 1];
switch (times.length) {
default: times[1] = endTime; // Fall through.
case 1: times[0] = startTime; // Fall through.
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java
index 60df95d..43f798e 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/AbstractGridResource.java
@@ -386,13 +386,17 @@ public abstract class AbstractGridResource extends AbstractResource implements G
parameters[0] = IOUtilities.filename(file != null ? file : getSourceName());
parameters[5] = nanos / (double) StandardDateFormat.NANOS_PER_SECOND;
JDK9.ifPresentOrElse(domain.getGeographicExtent(), (box) -> {
- final AngleFormat f = new AngleFormat("D°MM′SS″", locale);
- f.setRoundingMode(RoundingMode.FLOOR);
- parameters[1] = f.format(new Latitude (box.getSouthBoundLatitude()));
- parameters[3] = f.format(new Longitude(box.getWestBoundLongitude()));
- f.setRoundingMode(RoundingMode.CEILING);
- parameters[2] = f.format(new Latitude (box.getNorthBoundLatitude()));
- parameters[4] = f.format(new Longitude(box.getEastBoundLongitude()));
+ final AngleFormat f = new AngleFormat(locale);
+ double min = box.getSouthBoundLatitude();
+ double max = box.getNorthBoundLatitude();
+ f.setPrecision(max - min, true);
+ f.setRoundingMode(RoundingMode.FLOOR); parameters[1] = f.format(new Latitude(min));
+ f.setRoundingMode(RoundingMode.CEILING); parameters[2] = f.format(new Latitude(max));
+ min = box.getWestBoundLongitude();
+ max = box.getEastBoundLongitude();
+ f.setPrecision(max - min, true);
+ f.setRoundingMode(RoundingMode.FLOOR); parameters[3] = f.format(new Longitude(min));
+ f.setRoundingMode(RoundingMode.CEILING); parameters[4] = f.format(new Longitude(max));
}, () -> {
// If no geographic coordinates, fallback on the 2 first dimensions.
if (domain.isDefined(GridGeometry.ENVELOPE)) {