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 e3289235a9756b87a4ba423152f23c258c1248d9 Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Feb 20 12:09:57 2024 +0100 Opportunistically use "pattern matching for instanceof" in test code. The main code is unchanged (stay on Java 11). --- endorsed/build.gradle.kts | 4 +- .../apache/sis/feature/AbstractFeatureTest.java | 14 +++---- .../org/apache/sis/feature/FeatureTestCase.java | 2 +- .../feature/builder/FeatureTypeBuilderTest.java | 4 +- .../apache/sis/feature/test/FeatureComparator.java | 34 ++++++++------- .../test/org/apache/sis/filter/PeriodLiteral.java | 3 +- .../sis/metadata/PropertyConsistencyCheck.java | 9 ++-- .../test/org/apache/sis/metadata/TreeNodeTest.java | 4 +- .../org/apache/sis/metadata/TreeTableViewTest.java | 4 +- .../org/apache/sis/metadata/sql/TestDatabase.java | 4 +- .../apache/sis/xml/test/DocumentComparator.java | 48 +++++++++++----------- .../org/apache/sis/xml/test/PackageVerifier.java | 22 +++++----- .../apache/sis/geometry/AbstractEnvelopeTest.java | 6 +-- .../apache/sis/geometry/GeneralEnvelopeTest.java | 3 +- .../org/apache/sis/io/wkt/WKTDictionaryTest.java | 4 +- .../org/apache/sis/referencing/Assertions.java | 26 ++++++------ .../sis/referencing/GeodeticObjectVerifier.java | 4 +- .../projection/MapProjectionTestCase.java | 4 +- .../projection/ProjectionResultComparator.java | 3 +- .../operation/provider/MapProjectionTest.java | 4 +- .../operation/transform/MathTransformTestCase.java | 8 ++-- .../operation/transform/MathTransformWrapper.java | 4 +- .../transform/TransformResultComparator.java | 6 +-- .../report/CoordinateOperationMethods.java | 16 ++++---- .../report/CoordinateReferenceSystems.java | 24 +++++------ .../referencing/util/j2d/ShapeUtilitiesExt.java | 9 ++-- .../apache/sis/storage/netcdf/base/TestCase.java | 12 ++---- .../org/apache/sis/storage/folder/StoreTest.java | 4 +- .../apache/sis/storage/test/SubsampledImage.java | 13 +++--- .../test/org/apache/sis/io/LineAppenderTest.java | 4 +- .../org/apache/sis/io/TabulationExpansionTest.java | 4 +- .../test/org/apache/sis/io/WordWrapTest.java | 4 +- .../org/apache/sis/measure/SystemUnitTest.java | 7 ++-- .../test/org/apache/sis/test/TestUtilities.java | 8 +--- incubator/build.gradle.kts | 2 + .../test/org/apache/sis/map/SEPortrayerTest.java | 6 +-- .../storage/coveragejson/binding/BindingTest.java | 8 ++-- optional/build.gradle.kts | 2 + 38 files changed, 160 insertions(+), 187 deletions(-) diff --git a/endorsed/build.gradle.kts b/endorsed/build.gradle.kts index 6a8f136011..61b183502b 100644 --- a/endorsed/build.gradle.kts +++ b/endorsed/build.gradle.kts @@ -101,11 +101,11 @@ tasks.compileJava { options.release.set(11) // The version of both Java source code and compiled byte code. } tasks.compileTestJava { + options.compilerArgs.add("-source") // "source", not "release", because we accept any target version. + options.compilerArgs.add("16") // Minimal Java version required by some API that the tests use. srcDir.list().forEach { addRead(options.compilerArgs, it, "org.apache.sis.test.endorsed,org.junit.jupiter.api") } - options.compilerArgs.add("-source") // "source", not "release", because we accept any target version. - options.compilerArgs.add("16") // Minimal Java version required by some API that the tests use. addExportForTests(options.compilerArgs) } diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/AbstractFeatureTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/AbstractFeatureTest.java index 24ba610414..637b6a10d9 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/AbstractFeatureTest.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/AbstractFeatureTest.java @@ -67,14 +67,14 @@ public final class AbstractFeatureTest extends FeatureTestCase { */ CustomFeature(final DefaultFeatureType type) { super(type); - for (final PropertyType pt : type.getProperties(true)) { - if (pt instanceof AttributeType<?>) { - Object value = ((AttributeType<?>) pt).getDefaultValue(); - if (isMultiValued(pt)) { + for (final PropertyType property : type.getProperties(true)) { + if (property instanceof AttributeType<?> attribute) { + Object value = attribute.getDefaultValue(); + if (isMultiValued(property)) { value = new ArrayList<>(PropertyView.singletonOrEmpty(value)); } if (value != null) { - values.put(pt.getName().toString(), value); + values.put(property.getName().toString(), value); } } } @@ -122,8 +122,8 @@ public final class AbstractFeatureTest extends FeatureTestCase { } if (value != null) { final Class<?> base; - if (property instanceof AttributeType<?>) { - base = ((AttributeType<?>) property).getValueClass(); + if (property instanceof AttributeType<?> attribute) { + base = attribute.getValueClass(); } else { base = FeatureType.class; } diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureTestCase.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureTestCase.java index 09b04194ea..a0e939392d 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureTestCase.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/FeatureTestCase.java @@ -357,7 +357,7 @@ public abstract class FeatureTestCase extends TestCase { final DataQuality quality = feature.quality(); for (final Element report : quality.getReports()) { for (final Result result : report.getResults()) { - if (result instanceof ConformanceResult && !((ConformanceResult) result).pass()) { + if (result instanceof ConformanceResult r && !r.pass()) { assertTrue(anomalyIndex < anomalousProperties.length, "Too many reports"); final String propertyName = anomalousProperties[anomalyIndex]; @SuppressWarnings("deprecation") diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java index 6332d83ac4..001d297b87 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/builder/FeatureTypeBuilderTest.java @@ -378,8 +378,8 @@ public final class FeatureTypeBuilderTest extends TestCase { */ private static void assertPropertyEquals(final String name, final Class<?> valueClass, IdentifiedType property) { assertEquals(name, property.getName().toString()); - if (property instanceof Operation) { - property = ((Operation) property).getResult(); + if (property instanceof Operation op) { + property = op.getResult(); } assertEquals(valueClass, attributeType(property).getValueClass()); } diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/test/FeatureComparator.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/test/FeatureComparator.java index 79b7cec702..31a2c18b25 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/test/FeatureComparator.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/feature/test/FeatureComparator.java @@ -178,14 +178,14 @@ public class FeatureComparator { */ private void compareType(final IdentifiedType expected, final IdentifiedType actual) { boolean recognized = false; - if (expected instanceof FeatureType) { + if (expected instanceof FeatureType type) { var c = assertInstanceOf(FeatureType.class, actual, this::path); - compareFeatureType((FeatureType) expected, c); + compareFeatureType(type, c); recognized = true; } - if (expected instanceof PropertyType) { + if (expected instanceof PropertyType type) { var c = assertInstanceOf(PropertyType.class, actual, this::path); - comparePropertyType((PropertyType) expected, c); + comparePropertyType(type, c); recognized = true; } if (!recognized) { @@ -256,8 +256,8 @@ public class FeatureComparator { while (expectedIter.hasNext()) { final Object expectedElement = expectedIter.next(); final Object actualElement = actualIter.next(); - if (expectedElement instanceof Feature) { - compareFeature((Feature) expectedElement, (Feature) actualElement); + if (expectedElement instanceof Feature instance) { + compareFeature(instance, (Feature) actualElement); } else { assertEquals(expectedElement, actualElement); } @@ -274,17 +274,17 @@ public class FeatureComparator { * @throws AssertionError if the actual property is not equal to the expected property. */ private void comparePropertyType(final PropertyType expected, final PropertyType actual) { - if (expected instanceof AttributeType) { + if (expected instanceof AttributeType<?> type) { var c = assertInstanceOf(AttributeType.class, actual, this::path); - compareAttribute((AttributeType) expected, c); + compareAttribute(type, c); } - if (expected instanceof FeatureAssociationRole) { + if (expected instanceof FeatureAssociationRole role) { var c = assertInstanceOf(FeatureAssociationRole.class, actual, this::path); - compareFeatureAssociationRole((FeatureAssociationRole) expected, c); + compareFeatureAssociationRole(role, c); } - if (expected instanceof Operation) { + if (expected instanceof Operation op) { var c = assertInstanceOf(Operation.class, actual, this::path); - compareOperation((Operation) expected, c); + compareOperation(op, c); } } @@ -380,10 +380,8 @@ public class FeatureComparator { if (!ignoreDescription) { assertEquals(expected.getDescription(), actual.getDescription(), () -> path() + "Description differ."); } - if (expected instanceof Deprecable && actual instanceof Deprecable) { - assertEquals(((Deprecable) expected).isDeprecated(), - ((Deprecable) actual).isDeprecated(), - () -> path() + "Deprecated state differ."); + if (expected instanceof Deprecable de && actual instanceof Deprecable da) { + assertEquals(de.isDeprecated(), da.isDeprecated(), () -> path() + "Deprecated state differ."); } } @@ -442,8 +440,8 @@ public class FeatureComparator { * in a singleton collection. */ private static Collection<?> asCollection(final Object value) { - if (value instanceof Collection<?>) { - return (Collection<?>) value; + if (value instanceof Collection<?> c) { + return c; } else { return CollectionsExt.singletonOrEmpty(value); } diff --git a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java index bbe5d1b1bc..5624bfe21e 100644 --- a/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java +++ b/endorsed/src/org.apache.sis.feature/test/org/apache/sis/filter/PeriodLiteral.java @@ -100,8 +100,7 @@ final class PeriodLiteral implements Period, Literal<Feature,Period>, Serializab */ @Override public boolean equals(final Object other) { - if (other instanceof PeriodLiteral) { - final PeriodLiteral p = (PeriodLiteral) other; + if (other instanceof PeriodLiteral p) { return begin == p.begin && end == p.end; } return false; diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyConsistencyCheck.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyConsistencyCheck.java index 69e958c20c..e4c3de1322 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyConsistencyCheck.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/PropertyConsistencyCheck.java @@ -217,8 +217,8 @@ public abstract class PropertyConsistencyCheck extends AnnotationConsistencyChec fail(e.toString()); return; } - if (instance instanceof AbstractMetadata) { - validate((AbstractMetadata) instance); + if (instance instanceof AbstractMetadata md) { + validate(md); } /* * Iterate over all properties defined in the interface, @@ -255,9 +255,8 @@ public abstract class PropertyConsistencyCheck extends AnnotationConsistencyChec assertFalse(isMap | isCollection, "Null values are not allowed to be collections."); } else { assertTrue(propertyType.isInstance(value), "Wrong property type."); - if (value instanceof CheckedContainer<?>) { - assertTrue(elementType.isAssignableFrom(((CheckedContainer<?>) value).getElementType()), - "Wrong element type in collection."); + if (value instanceof CheckedContainer<?> c) { + assertTrue(elementType.isAssignableFrom(c.getElementType()), "Wrong element type in collection."); } if (isMap) { assertTrue(((Map<?,?>) value).isEmpty(), "Collections shall be initially empty."); diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeNodeTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeNodeTest.java index be142cca70..c4e21e2255 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeNodeTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeNodeTest.java @@ -410,8 +410,8 @@ public final class TreeNodeTest extends TestCase { { final Object actual = node.getValue(column); Object unlocalized = actual; - if (unlocalized instanceof InternationalString) { - unlocalized = ((InternationalString) unlocalized).toString(Locale.ROOT); + if (unlocalized instanceof InternationalString i18n) { + unlocalized = i18n.toString(Locale.ROOT); } assertEquals(expected[index++], unlocalized, "values[" + index + ']'); for (final TreeTable.Node child : node.getChildren()) { diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeTableViewTest.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeTableViewTest.java index 967db40900..6fd4062020 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeTableViewTest.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/TreeTableViewTest.java @@ -181,8 +181,8 @@ public final class TreeTableViewTest extends TestCase { * Verifies the value of the given international string in English. */ private static void assertI18nEq(final String expected, Object text) { - if (text instanceof InternationalString) { - text = ((InternationalString) text).toString(Locale.ENGLISH); + if (text instanceof InternationalString i18n) { + text = i18n.toString(Locale.ENGLISH); } assertEquals(expected, text); } diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java index b945c42983..8b0ba0dbea 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/metadata/sql/TestDatabase.java @@ -311,8 +311,8 @@ public class TestDatabase implements AutoCloseable { public final void executeSQL(final List<?> scripts) throws IOException, SQLException { try (Connection c = source.getConnection(); ScriptRunner r = new ScriptRunner(c, 1000)) { for (final Object sql : scripts) { - if (sql instanceof String) { - r.run((String) sql); + if (sql instanceof String s) { + r.run(s); } else { final var s = (Supplier<?>) sql; r.run(s.toString(), (InputStream) s.get()); diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java index 30865ee640..8755724a66 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/DocumentComparator.java @@ -202,16 +202,16 @@ public class DocumentComparator { ArgumentChecks.ensureNonNull("expected", expected); ArgumentChecks.ensureNonNull("actual", actual); DocumentBuilder builder = null; - if (expected instanceof Node) { - expectedDoc = (Node) expected; + if (expected instanceof Node node) { + expectedDoc = node; } else { builder = newDocumentBuilder(); try (InputStream stream = toInputStream(expected)) { expectedDoc = builder.parse(stream); } } - if (actual instanceof Node) { - actualDoc = (Node) actual; + if (actual instanceof Node node) { + actualDoc = node; } else { if (builder == null) { builder = newDocumentBuilder(); @@ -240,12 +240,12 @@ public class DocumentComparator { * See the constructor Javadoc for the list of allowed input type. */ private static InputStream toInputStream(final Object input) throws IOException { - if (input instanceof InputStream) return (InputStream) input; - if (input instanceof File) return new FileInputStream((File) input); - if (input instanceof URI) return ((URI) input).toURL().openStream(); - if (input instanceof URL) return ((URL) input).openStream(); - if (input instanceof Path) return Files.newInputStream((Path) input); - if (input instanceof String) return new ByteArrayInputStream(input.toString().getBytes("UTF-8")); + if (input instanceof InputStream t) return t; + if (input instanceof File t) return new FileInputStream(t); + if (input instanceof URI t) return t.toURL().openStream(); + if (input instanceof URL t) return t.openStream(); + if (input instanceof Path t) return Files.newInputStream(t); + if (input instanceof String t) return new ByteArrayInputStream(t.getBytes("UTF-8")); throw new IOException("Cannot handle input type: " + (input != null ? input.getClass() : input)); } @@ -308,16 +308,16 @@ public class DocumentComparator { * Check text value for types: * TEXT_NODE, CDATA_SECTION_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE */ - if (expected instanceof CDATASection) { - compareCDATASectionNode((CDATASection) expected, actual); - } else if (expected instanceof Text) { - compareTextNode((Text) expected, actual); - } else if (expected instanceof Comment) { - compareCommentNode((Comment) expected, actual); - } else if (expected instanceof ProcessingInstruction) { - compareProcessingInstructionNode((ProcessingInstruction) expected, actual); - } else if (expected instanceof Attr) { - compareAttributeNode((Attr) expected, actual); + if (expected instanceof CDATASection t) { + compareCDATASectionNode(t, actual); + } else if (expected instanceof Text t) { + compareTextNode(t, actual); + } else if (expected instanceof Comment t) { + compareCommentNode(t, actual); + } else if (expected instanceof ProcessingInstruction t) { + compareProcessingInstructionNode(t, actual); + } else if (expected instanceof Attr t) { + compareAttributeNode(t, actual); } else { compareNames(expected, actual); compareAttributes(expected, actual); @@ -663,8 +663,8 @@ public class DocumentComparator { * than zero has been provided. */ private static double doubleValue(final Comparable<?> property) { - if (property instanceof Number) { - return ((Number) property).doubleValue(); + if (property instanceof Number n) { + return n.doubleValue(); } if (property instanceof CharSequence) try { return Double.parseDouble(property.toString()); @@ -723,8 +723,8 @@ public class DocumentComparator { final List<String> hierarchy = new ArrayList<>(); while (node != null) { hierarchy.add(node.getNodeName()); - if (node instanceof Attr) { - node = ((Attr) node).getOwnerElement(); + if (node instanceof Attr t) { + node = t.getOwnerElement(); } else { node = node.getParentNode(); } diff --git a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/PackageVerifier.java b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/PackageVerifier.java index a615042c7e..2444be7fe4 100644 --- a/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/PackageVerifier.java +++ b/endorsed/src/org.apache.sis.metadata/test/org/apache/sis/xml/test/PackageVerifier.java @@ -202,21 +202,21 @@ final class PackageVerifier { for (final XmlJavaTypeAdapter adapter : adapters.value()) { Class<?> propertyType = adapter.type(); if (propertyType == XmlJavaTypeAdapter.DEFAULT.class) { - for (Class<?> c = adapter.value(); ; c = c.getSuperclass()) { - final Type type = c.getGenericSuperclass(); - if (type == null) { + for (Class<?> adapterClass = adapter.value(); ; adapterClass = adapterClass.getSuperclass()) { + final Type adapterType = adapterClass.getGenericSuperclass(); + if (adapterType == null) { throw new SchemaException(String.format( "Cannot infer type for %s adapter.", adapter.value().getName())); } - if (type instanceof ParameterizedType) { - final Type[] p = ((ParameterizedType) type).getActualTypeArguments(); - if (p.length == 2) { - Type pt = p[1]; - if (pt instanceof ParameterizedType) { - pt = ((ParameterizedType) pt).getRawType(); + if (adapterType instanceof ParameterizedType p1) { + final Type[] parameters = p1.getActualTypeArguments(); + if (parameters.length == 2) { + Type typeInAPI = parameters[1]; + if (typeInAPI instanceof ParameterizedType p2) { + typeInAPI = p2.getRawType(); } - if (pt instanceof Class<?>) { - propertyType = (Class<?>) pt; + if (typeInAPI instanceof Class<?> pc) { + propertyType = pc; break; } } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java index 882fbcfdf3..191d24f7db 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/AbstractEnvelopeTest.java @@ -262,8 +262,7 @@ public final class AbstractEnvelopeTest extends TestCase { assertEquals(+180, envelope.getMaximum (0), label); assertEquals( 4, envelope.getMedian (0), label); // Note the alternance with the previous test methods. assertEquals( NaN, envelope.getSpan (0), label); // testCrossingAntiMeridian() + 360°. - if (envelope instanceof AbstractEnvelope) { - final var ext = (AbstractEnvelope) envelope; + if (envelope instanceof AbstractEnvelope ext) { assertTrue (ext.contains (inside), label); assertFalse(ext.contains (outside), label); assertFalse(ext.contains (intersect, false), label); @@ -274,8 +273,7 @@ public final class AbstractEnvelopeTest extends TestCase { assertContains(ext, contained); break; } - if (envelope instanceof Rectangle2D) { - final var ext = (Rectangle2D) envelope; + if (envelope instanceof Rectangle2D ext) { assertTrue (ext.contains (inside), label); assertFalse(ext.contains (outside), label); assertFalse(ext.contains (intersect), label); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java index 01a266d668..2ffe2efe00 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/geometry/GeneralEnvelopeTest.java @@ -123,8 +123,7 @@ public class GeneralEnvelopeTest extends TestCase { assertEquals(ymax, test .getMaximum (1), "ymax"); assertEquals(ymin, lower.getOrdinate(1), "ymin"); assertEquals(ymax, upper.getOrdinate(1), "ymax"); - if (test instanceof Envelope2D) { - final Envelope2D ri = (Envelope2D) test; + if (test instanceof Envelope2D ri) { assertEquals(xmin, ri.getMinX(), "xmin"); assertEquals(xmax, ri.getMaxX(), "xmax"); assertEquals(ymin, ri.getMinY(), "ymin"); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java index 14881eb561..e46ccd6f0b 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/io/wkt/WKTDictionaryTest.java @@ -227,8 +227,8 @@ public final class WKTDictionaryTest extends TestCase { * distinct instance, separated by identity comparison (not by {@link Object#equals(Object)}). */ @Override public void accept(final Object value) { - if (value instanceof StoredTree) { - ((StoredTree) value).forEachValue(this); + if (value instanceof StoredTree tree) { + tree.forEachValue(this); } counts.merge(value, 1, this); } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/Assertions.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/Assertions.java index 890733dae7..f60b96ce9c 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/Assertions.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/Assertions.java @@ -317,9 +317,9 @@ public final class Assertions extends Static { public static void assertContains(final RectangularShape outer, final Rectangle2D inner) { assertTrue(outer.contains (inner), "outer.contains(inner)"); assertTrue(outer.intersects(inner), "outer.intersects(inner)"); - if (outer instanceof Rectangle2D) { - assertTrue (inner.intersects((Rectangle2D) outer), "inner.intersects(outer)"); - assertFalse(inner.contains ((Rectangle2D) outer), "inner.contains(outer)"); + if (outer instanceof Rectangle2D r) { + assertTrue (inner.intersects(r), "inner.intersects(outer)"); + assertFalse(inner.contains (r), "inner.contains(outer)"); } assertTrue(outer.contains(inner.getCenterX(), inner.getCenterY()), "outer.contains(centerX, centerY)"); } @@ -337,8 +337,7 @@ public final class Assertions extends Static { assertTrue(outer.contains (inner, false), "outer.contains(inner)"); assertTrue(outer.intersects(inner, true), "outer.intersects(inner)"); assertTrue(outer.intersects(inner, false), "outer.intersects(inner)"); - if (inner instanceof AbstractEnvelope) { - final AbstractEnvelope ai = (AbstractEnvelope) inner; + if (inner instanceof AbstractEnvelope ai) { assertTrue (ai.intersects(outer, true), "inner.intersects(outer)"); assertTrue (ai.intersects(outer, false), "inner.intersects(outer)"); assertFalse(ai.contains (outer, true), "inner.contains(outer)"); @@ -365,9 +364,9 @@ public final class Assertions extends Static { public static void assertDisjoint(final RectangularShape r1, final Rectangle2D r2) { assertFalse(r1.intersects(r2), "r1.intersects(r2)"); assertFalse(r1.contains(r2), "r1.contains(r2)"); - if (r1 instanceof Rectangle2D) { - assertFalse(r2.intersects((Rectangle2D) r1), "r2.intersects(r1)"); - assertFalse(r2.contains ((Rectangle2D) r1), "r2.contains(r1)"); + if (r1 instanceof Rectangle2D r) { + assertFalse(r2.intersects(r), "r2.intersects(r1)"); + assertFalse(r2.contains (r), "r2.contains(r1)"); } for (int i=0; i<9; i++) { final double x, y; @@ -400,8 +399,7 @@ public final class Assertions extends Static { assertFalse(e1.intersects(e2, true), "e1.intersects(e2)"); assertFalse(e1.contains (e2, false), "e1.contains(e2)"); assertFalse(e1.contains (e2, true), "e1.contains(e2)"); - if (e2 instanceof AbstractEnvelope) { - final AbstractEnvelope ae = (AbstractEnvelope) e2; + if (e2 instanceof AbstractEnvelope ae) { assertFalse(ae.intersects(e1, false), "e2.intersects(e1)"); assertFalse(ae.intersects(e1, true), "e2.intersects(e1)"); assertFalse(ae.contains (e1, false), "e2.contains(e1)"); @@ -436,8 +434,8 @@ public final class Assertions extends Static { */ public static void assertIsIdentity(final MathTransform transform) { assertTrue(transform.isIdentity(), "isIdentity()"); - if (transform instanceof LinearTransform) { - assertTrue(((LinearTransform) transform).getMatrix().isIdentity(), "getMatrix().isIdentity()"); + if (transform instanceof LinearTransform linear) { + assertTrue(linear.getMatrix().isIdentity(), "getMatrix().isIdentity()"); } } @@ -449,8 +447,8 @@ public final class Assertions extends Static { */ public static void assertIsNotIdentity(final MathTransform transform) { assertFalse(transform.isIdentity(), "isIdentity()"); - if (transform instanceof LinearTransform) { - assertFalse(((LinearTransform) transform).getMatrix().isIdentity(), "getMatrix().isIdentity()"); + if (transform instanceof LinearTransform linear) { + assertFalse(linear.getMatrix().isIdentity(), "getMatrix().isIdentity()"); } } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java index 6e8d7a3519..a5559e1592 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/GeodeticObjectVerifier.java @@ -66,8 +66,8 @@ public final class GeodeticObjectVerifier { private static void assertIsWorld(final Extent extent, boolean isMandatory) { if (extent != null) { for (final GeographicExtent element : extent.getGeographicElements()) { - if (element instanceof GeographicBoundingBox) { - assertIsWorld((GeographicBoundingBox) element); + if (element instanceof GeographicBoundingBox bbox) { + assertIsWorld(bbox); isMandatory = false; } } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MapProjectionTestCase.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MapProjectionTestCase.java index 6bf8923257..6661e00b60 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MapProjectionTestCase.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/MapProjectionTestCase.java @@ -158,9 +158,9 @@ abstract class MapProjectionTestCase extends MathTransformTestCase { final NormalizedProjection getKernel() { NormalizedProjection kernel = null; for (final MathTransform component : MathTransforms.getSteps(transform)) { - if (component instanceof NormalizedProjection) { + if (component instanceof NormalizedProjection proj) { assertNull(kernel, "Found more than one kernel."); - kernel = (NormalizedProjection) component; + kernel = proj; } } assertNotNull(kernel); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/ProjectionResultComparator.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/ProjectionResultComparator.java index b7d78396d6..f419d97f78 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/ProjectionResultComparator.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/projection/ProjectionResultComparator.java @@ -98,8 +98,7 @@ final class ProjectionResultComparator extends NormalizedProjection { final List<MathTransform> steps = MathTransforms.getSteps(transform); for (int i=steps.size(); --i >= 0;) { final MathTransform step = steps.get(i); - if (step instanceof NormalizedProjection) { - final NormalizedProjection spherical = (NormalizedProjection) step; + if (step instanceof NormalizedProjection spherical) { final Class<?> sphericalClass = spherical.getClass(); final Class<?> ellipticalClass = sphericalClass.getSuperclass(); assertEquals("Spherical", sphericalClass.getSimpleName(), "Class name for the spherical formulas."); diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/MapProjectionTest.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/MapProjectionTest.java index 22a4d82b25..6c4b1085e3 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/MapProjectionTest.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/provider/MapProjectionTest.java @@ -131,8 +131,8 @@ public final class MapProjectionTest extends TestCase { assertEquals(isMandatory ? 1 : 0, actual.getMinimumOccurs()); if (epsgName != null) { for (final GenericName alias : actual.getAlias()) { - if (alias instanceof Identifier && ((Identifier) alias).getAuthority() != Citations.EPSG) { - assertOgcIdentifierEquals(ogcName, (Identifier) alias); + if (alias instanceof Identifier id && id.getAuthority() != Citations.EPSG) { + assertOgcIdentifierEquals(ogcName, id); return; } } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java index 57b25dbd52..5bba742206 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformTestCase.java @@ -193,8 +193,8 @@ public abstract class MathTransformTestCase extends TransformTestCase { */ @Debug private String getName() { - if (transform instanceof Parameterized) { - final ParameterDescriptorGroup descriptor = ((Parameterized) transform).getParameterDescriptors(); + if (transform instanceof Parameterized pmt) { + final ParameterDescriptorGroup descriptor = pmt.getParameterDescriptors(); if (descriptor != null) { final Identifier identifier = descriptor.getName(); if (identifier != null) { @@ -432,8 +432,8 @@ public abstract class MathTransformTestCase extends TransformTestCase { wkt = transform.toString(); } table.append(wkt).nextColumn(); - if (transform instanceof FormattableObject) { - wkt = ((FormattableObject) transform).toString(Convention.INTERNAL); + if (transform instanceof FormattableObject fmt) { + wkt = fmt.toString(Convention.INTERNAL); } else { wkt = transform.toString(); } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformWrapper.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformWrapper.java index b2d6d836df..2525e3e4c8 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformWrapper.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/MathTransformWrapper.java @@ -212,8 +212,8 @@ public class MathTransformWrapper extends FormattableObject implements MathTrans */ @Override protected final String formatTo(final Formatter formatter) { - if (transform instanceof AbstractMathTransform) { - return ((AbstractMathTransform) transform).formatTo(formatter); + if (transform instanceof AbstractMathTransform fmt) { + return fmt.formatTo(formatter); } throw new UnformattableObjectException(); } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/TransformResultComparator.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/TransformResultComparator.java index 09155035ea..ca7bb0085f 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/TransformResultComparator.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/operation/transform/TransformResultComparator.java @@ -198,8 +198,7 @@ final class TransformResultComparator implements MathTransform { { double tolerance; final MathTransform t1, r1, t2, r2; - if (tr1 instanceof TransformResultComparator) { - final TransformResultComparator c = (TransformResultComparator) tr1; + if (tr1 instanceof TransformResultComparator c) { t1 = c.tested; r1 = c.reference; tolerance = c.tolerance; @@ -207,8 +206,7 @@ final class TransformResultComparator implements MathTransform { t1 = r1 = tr1; tolerance = 0; } - if (tr2 instanceof TransformResultComparator) { - final TransformResultComparator c = (TransformResultComparator) tr2; + if (tr2 instanceof TransformResultComparator c) { t2 = c.tested; r2 = c.reference; if (c.tolerance > tolerance) { diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateOperationMethods.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateOperationMethods.java index a277e048be..2c972e617a 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateOperationMethods.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateOperationMethods.java @@ -346,7 +346,7 @@ public class CoordinateOperationMethods extends HTMLGenerator { remarks = "Optional "; } else { final Comparable<?> min = param.getMinimumValue(); - if ((min instanceof Number) && ((Number) min).doubleValue() == ((Number) param.getMaximumValue()).doubleValue()) { + if ((min instanceof Number n) && n.doubleValue() == ((Number) param.getMaximumValue()).doubleValue()) { remarks = "Unmodifiable "; } else { remarks = "See note "; @@ -425,10 +425,10 @@ public class CoordinateOperationMethods extends HTMLGenerator { } catch (FactoryException e) { continue; // Ignore and inspect the next element. } - if (crs instanceof GeneralDerivedCRS) { - final GeographicBoundingBox candidate = CRS.getGeographicBoundingBox(crs); + if (crs instanceof GeneralDerivedCRS derived) { + final GeographicBoundingBox candidate = CRS.getGeographicBoundingBox(derived); if (candidate != null) { - final String name = ((GeneralDerivedCRS) crs).getConversionFromBase().getMethod().getName().getCode(); + final String name = derived.getConversionFromBase().getMethod().getName().getCode(); DefaultGeographicBoundingBox validity = domainOfValidity.get(name); if (validity == null) { validity = new DefaultGeographicBoundingBox(candidate); @@ -469,11 +469,11 @@ public class CoordinateOperationMethods extends HTMLGenerator { private String getDefaultValue(final ParameterDescriptor<?> param, final String unit) { Object defaultValue = param.getDefaultValue(); if (defaultValue != null) { - if (defaultValue instanceof Number) { + if (defaultValue instanceof Number n) { // Trim the fractional part if unnecessary (e.g. "0.0" to "0"). - defaultValue = Numbers.narrowestNumber((Number) defaultValue); - } else if (defaultValue instanceof String) { - return (String) defaultValue; + defaultValue = Numbers.narrowestNumber(n); + } else if (defaultValue instanceof String s) { + return s; } } else { if (ArraysExt.contains(defaultToLatitudeOfOrigin, param)) { diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java index 7462e24c44..da0c4e162b 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/report/CoordinateReferenceSystems.java @@ -411,8 +411,8 @@ public final class CoordinateReferenceSystems extends AuthorityCodesReport { if (crs instanceof GeographicCRS) { return (crs.getCoordinateSystem().getDimension() == 3) ? "Geographic 3D" : "Geographic"; } - if (crs instanceof GeneralDerivedCRS) { - final OperationMethod method = ((GeneralDerivedCRS) crs).getConversionFromBase().getMethod(); + if (crs instanceof GeneralDerivedCRS derived) { + final OperationMethod method = derived.getConversionFromBase().getMethod(); final Identifier identifier = IdentifiedObjects.getIdentifier(method, Citations.EPSG); if (identifier != null) { return "<a href=\"CoordinateOperationMethods.html#" + identifier.getCode() @@ -428,13 +428,13 @@ public final class CoordinateReferenceSystems extends AuthorityCodesReport { } return "Geocentric"; } - if (crs instanceof VerticalCRS) { - final VerticalDatumType type = ((VerticalCRS) crs).getDatum().getVerticalDatumType(); + if (crs instanceof VerticalCRS vertical) { + final VerticalDatumType type = vertical.getDatum().getVerticalDatumType(); return CharSequences.camelCaseToSentence(type.name().toLowerCase(getLocale())) + " height"; } - if (crs instanceof CompoundCRS) { + if (crs instanceof CompoundCRS compound) { final StringBuilder buffer = new StringBuilder(); - for (final CoordinateReferenceSystem component : ((CompoundCRS) crs).getComponents()) { + for (final CoordinateReferenceSystem component : compound.getComponents()) { if (buffer.length() != 0) { buffer.append(" + "); } @@ -531,16 +531,16 @@ public final class CoordinateReferenceSystems extends AuthorityCodesReport { * If the object is deprecated, find the replacement. * We do not take the whole comment because it may be pretty long. */ - if (object instanceof Deprecable) { - row.isDeprecated = ((Deprecable) object).isDeprecated(); + if (object instanceof Deprecable dep) { + row.isDeprecated = dep.isDeprecated(); if (row.isDeprecated) { String replacedBy = null; InternationalString i18n = object.getRemarks(); for (final Identifier id : object.getIdentifiers()) { - if (id instanceof Deprecable && ((Deprecable) id).isDeprecated()) { - i18n = ((Deprecable) id).getRemarks(); - if (id instanceof DeprecatedCode) { - replacedBy = ((DeprecatedCode) id).replacedBy; + if (id instanceof Deprecable did && did.isDeprecated()) { + i18n = did.getRemarks(); + if (id instanceof DeprecatedCode dc) { + replacedBy = dc.replacedBy; } break; } diff --git a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/j2d/ShapeUtilitiesExt.java b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/j2d/ShapeUtilitiesExt.java index e7414410f5..7286033e29 100644 --- a/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/j2d/ShapeUtilitiesExt.java +++ b/endorsed/src/org.apache.sis.referencing/test/org/apache/sis/referencing/util/j2d/ShapeUtilitiesExt.java @@ -120,19 +120,16 @@ public final class ShapeUtilitiesExt { public static Point2D.Double pointOnBezier(final Shape bezier, final double t) { final double x, y; final double mt = 1 - t; - if (bezier instanceof Line2D) { - final Line2D z = (Line2D) bezier; + if (bezier instanceof Line2D z) { x = mt * z.getX1() + t * z.getX2(); y = mt * z.getY1() + t * z.getY2(); - } else if (bezier instanceof QuadCurve2D) { - final QuadCurve2D z = (QuadCurve2D) bezier; + } else if (bezier instanceof QuadCurve2D z) { final double a = mt * mt; final double b = mt * t * 2; final double c = t * t; x = a * z.getX1() + b * z.getCtrlX() + c * z.getX2(); y = a * z.getY1() + b * z.getCtrlY() + c * z.getY2(); - } else if (bezier instanceof CubicCurve2D) { - final CubicCurve2D z = (CubicCurve2D) bezier; + } else if (bezier instanceof CubicCurve2D z) { final double a = mt * mt * mt; final double b = mt * mt * t * 3; final double c = mt * (t * t) * 3; diff --git a/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java b/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java index b231a151bd..3b7e9af51a 100644 --- a/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java +++ b/endorsed/src/org.apache.sis.storage.netcdf/test/org/apache/sis/storage/netcdf/base/TestCase.java @@ -220,15 +220,9 @@ public abstract class TestCase extends org.apache.sis.test.TestCase { * only after we have closed all other files. */ if (failure != null) { - if (failure instanceof IOException) { - throw (IOException) failure; - } - if (failure instanceof RuntimeException) { - throw (RuntimeException) failure; - } - if (failure instanceof Error) { - throw (Error) failure; - } + if (failure instanceof IOException e) throw e; + if (failure instanceof RuntimeException e) throw e; + if (failure instanceof Error e) throw e; throw new UndeclaredThrowableException(failure); } } diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/folder/StoreTest.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/folder/StoreTest.java index 09535b53ae..ccd89be0dd 100644 --- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/folder/StoreTest.java +++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/folder/StoreTest.java @@ -116,8 +116,8 @@ public final class StoreTest extends TestCase { for (Identification info : resource.getMetadata().getIdentificationInfo()) { final String id = Citations.getIdentifier(info.getCitation()); assertTrue(identifiers.remove(id), id); - if (resource instanceof Aggregate) { - verifyContent((Aggregate) resource, identifiers); + if (resource instanceof Aggregate aggregate) { + verifyContent(aggregate, identifiers); } } } diff --git a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/SubsampledImage.java b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/SubsampledImage.java index 69d55bb6bf..1b4f2dc2f0 100644 --- a/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/SubsampledImage.java +++ b/endorsed/src/org.apache.sis.storage/test/org/apache/sis/storage/test/SubsampledImage.java @@ -94,8 +94,7 @@ final class SubsampledImage extends PlanarImage { this.offX = offX; this.offY = offY; final SampleModel sourceModel = source.getSampleModel(); - if (sourceModel instanceof PixelInterleavedSampleModel) { - final PixelInterleavedSampleModel sm = (PixelInterleavedSampleModel) sourceModel; + if (sourceModel instanceof PixelInterleavedSampleModel sm) { final int pixelStride = sm.getPixelStride(); final int scanlineStride = sm.getScanlineStride(); final int strideOffset = pixelStride*offX + scanlineStride*offY; @@ -117,8 +116,7 @@ final class SubsampledImage extends PlanarImage { divExclusive(sm.getWidth(), subX), divExclusive(sm.getHeight(), subY), pixelStride*subX, scanlineStride*subY, bandOffsets); - } else if (sourceModel instanceof MultiPixelPackedSampleModel) { - final MultiPixelPackedSampleModel sm = (MultiPixelPackedSampleModel) sourceModel; + } else if (sourceModel instanceof MultiPixelPackedSampleModel sm) { assertEquals(1, subX, "Subsampling on the X axis is not supported."); model = new MultiPixelPackedSampleModel(sm.getDataType(), divExclusive(sm.getWidth(), subX), @@ -203,9 +201,9 @@ final class SubsampledImage extends PlanarImage { throw e; } final String warning = image.verify(); - if (warning != null && (source instanceof PlanarImage)) { + if (warning != null && (source instanceof PlanarImage planar)) { // Source warning may be "source.height", which we replace by "height". - final String s = Strings.orEmpty(((PlanarImage) source).verify()); + final String s = Strings.orEmpty(planar.verify()); assertEquals(s.substring(s.lastIndexOf('.') + 1), warning, s); } return image; @@ -365,8 +363,7 @@ final class SubsampledImage extends PlanarImage { */ @Override public boolean equals(final Object object) { - if (object instanceof SubsampledImage) { - final SubsampledImage other = (SubsampledImage) object; + if (object instanceof SubsampledImage other) { return source.equals(other.source) && subX == other.subX && subY == other.subY && diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/LineAppenderTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/LineAppenderTest.java index 04f9a011a6..0e8d11bf5e 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/LineAppenderTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/LineAppenderTest.java @@ -56,8 +56,8 @@ public class LineAppenderTest extends AppenderTestCase { @Override void run(final String lineSeparator) throws IOException { final Appendable f = appender; - if (f instanceof LineAppender) { - assertEquals(" ", ((LineAppender) f).getLineSeparator()); + if (f instanceof LineAppender la) { + assertEquals(" ", la.getLineSeparator()); } assertSame(f, f.append("Le vrai" + lineSeparator + "policitien, ")); assertSame(f, f.append("c'est celui\r\nqui\r")); // Line separator broken on two method calls. diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/TabulationExpansionTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/TabulationExpansionTest.java index 23a6e8cf3b..0ecc48b19f 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/TabulationExpansionTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/TabulationExpansionTest.java @@ -55,8 +55,8 @@ public final class TabulationExpansionTest extends LineAppenderTest { @Override void run(final String lineSeparator) throws IOException { final Appendable f = appender; - if (f instanceof LineAppender) { - assertEquals(8, ((LineAppender) f).getTabulationWidth()); + if (f instanceof LineAppender la) { + assertEquals(8, la.getTabulationWidth()); } assertSame(f, f.append("12\t8" + lineSeparator)); assertSame(f, f.append("1234\t8" + lineSeparator)); diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/WordWrapTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/WordWrapTest.java index e662e8fa86..feaea17279 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/WordWrapTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/io/WordWrapTest.java @@ -73,8 +73,8 @@ public class WordWrapTest extends LineAppenderTest { @Override void run(final String lineSeparator) throws IOException { final Appendable f = appender; - if (f instanceof LineAppender) { - assertEquals(LINE_LENGTH, ((LineAppender) f).getMaximalLineLength()); + if (f instanceof LineAppender la) { + assertEquals(LINE_LENGTH, la.getMaximalLineLength()); } final String BLUE = X364.FOREGROUND_BLUE .sequence(); final String DEFAULT = X364.FOREGROUND_DEFAULT.sequence(); diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/SystemUnitTest.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/SystemUnitTest.java index d3e1a6cfab..dc0bba58d0 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/SystemUnitTest.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/measure/SystemUnitTest.java @@ -61,11 +61,10 @@ public final class SystemUnitTest extends TestCase { @Test public void verifyRelatedUnits() throws ReflectiveOperationException { for (final Field f : Units.class.getFields()) { - final Object value = f.get(null); - if (value instanceof SystemUnit<?>) { - final ConventionalUnit<?>[] related = ((SystemUnit<?>) value).related(); + if (f.get(null) instanceof SystemUnit<?> value) { + final ConventionalUnit<?>[] related = value.related(); if (related != null) { - final String symbol = ((SystemUnit<?>) value).getSymbol(); + final String symbol = value.getSymbol(); for (final ConventionalUnit<?> r : related) { assertNotNull(r, symbol); assertInstanceOf(LinearConverter.class, r.toTarget, symbol); diff --git a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestUtilities.java b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestUtilities.java index 464ad86ba8..a955d968a1 100644 --- a/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestUtilities.java +++ b/endorsed/src/org.apache.sis.util/test/org/apache/sis/test/TestUtilities.java @@ -377,12 +377,8 @@ public final class TestUtilities extends Static { */ public static void rethrownIfNotNull(final Throwable failure) { if (failure != null) { - if (failure instanceof Error) { - throw (Error) failure; - } - if (failure instanceof RuntimeException) { - throw (RuntimeException) failure; - } + if (failure instanceof Error e) throw e; + if (failure instanceof RuntimeException e) throw e; throw new UndeclaredThrowableException(failure); } } diff --git a/incubator/build.gradle.kts b/incubator/build.gradle.kts index 10f43f7745..157103840f 100644 --- a/incubator/build.gradle.kts +++ b/incubator/build.gradle.kts @@ -82,6 +82,8 @@ tasks.compileJava { options.release.set(11) // The version of both Java source code and compiled byte code. } tasks.compileTestJava { + options.compilerArgs.add("-source") // "source", not "release", because we accept any target version. + options.compilerArgs.add("16") // For consistency with the value set in the `endorsed` modules. srcDir.list().forEach { addRead(options.compilerArgs, it, "org.apache.sis.test.incubator,org.junit.jupiter.api") } diff --git a/incubator/src/org.apache.sis.portrayal.map/test/org/apache/sis/map/SEPortrayerTest.java b/incubator/src/org.apache.sis.portrayal.map/test/org/apache/sis/map/SEPortrayerTest.java index cde2a88bb3..f3e9ef9f59 100644 --- a/incubator/src/org.apache.sis.portrayal.map/test/org/apache/sis/map/SEPortrayerTest.java +++ b/incubator/src/org.apache.sis.portrayal.map/test/org/apache/sis/map/SEPortrayerTest.java @@ -172,15 +172,13 @@ public class SEPortrayerTest { presentations.stream().forEach(new Consumer<Presentation>() { @Override public void accept(Presentation t) { - if (t instanceof SEPresentation) { - SEPresentation se = (SEPresentation) t; + if (t instanceof SEPresentation se) { Feature Feature = se.getCandidate(); ids.add(new Match(String.valueOf(Feature.getPropertyValue(AttributeConvention.IDENTIFIER)), se.getLayer(), se.getResource(), se.getSymbolizer())); - } else if (t instanceof ExceptionPresentation) { - final ExceptionPresentation ep = (ExceptionPresentation) t; + } else if (t instanceof ExceptionPresentation ep) { ids.add(new Match(ep.getException())); } } diff --git a/incubator/src/org.apache.sis.storage.coveragejson/test/org/apache/sis/storage/coveragejson/binding/BindingTest.java b/incubator/src/org.apache.sis.storage.coveragejson/test/org/apache/sis/storage/coveragejson/binding/BindingTest.java index 46bb1ff72c..4449517327 100644 --- a/incubator/src/org.apache.sis.storage.coveragejson/test/org/apache/sis/storage/coveragejson/binding/BindingTest.java +++ b/incubator/src/org.apache.sis.storage.coveragejson/test/org/apache/sis/storage/coveragejson/binding/BindingTest.java @@ -219,10 +219,10 @@ public class BindingTest { private static List<Object> asList(Object... array) { final List<Object> lst = new ArrayList<>(array.length); for (int i=0;i<array.length;i++) { - if (array[i] instanceof Integer) { - lst.add(BigDecimal.valueOf((Integer) array[i])); - } else if (array[i] instanceof Double) { - lst.add(BigDecimal.valueOf((Double) array[i])); + if (array[i] instanceof Integer v) { + lst.add(BigDecimal.valueOf(v)); + } else if (array[i] instanceof Double v) { + lst.add(BigDecimal.valueOf(v)); } else { lst.add(array[i]); } diff --git a/optional/build.gradle.kts b/optional/build.gradle.kts index 37ecbf7ccf..9d3b5aa332 100644 --- a/optional/build.gradle.kts +++ b/optional/build.gradle.kts @@ -84,6 +84,8 @@ tasks.compileJava { options.release.set(16) // The version of both Java source code and compiled byte code. } tasks.compileTestJava { + options.compilerArgs.add("-source") // "source", not "release", because we accept any target version. + options.compilerArgs.add("16") patchForTests(options.compilerArgs); srcDir.list().forEach { addRead(options.compilerArgs, it, "org.apache.sis.test.optional,org.junit.jupiter.api")