diff --git a/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java b/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java index 1f43a503616..db8d5f29d59 100644 --- a/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java +++ b/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -40,6 +39,13 @@ import org.eclipse.xsd.XSDTypeDefinition; import org.eclipse.xsd.util.XSDConstants; import org.eclipse.xsd.util.XSDUtil; +import org.geotools.api.feature.type.AttributeDescriptor; +import org.geotools.api.feature.type.AttributeType; +import org.geotools.api.feature.type.ComplexType; +import org.geotools.api.feature.type.FeatureTypeFactory; +import org.geotools.api.feature.type.Name; +import org.geotools.api.feature.type.PropertyDescriptor; +import org.geotools.api.feature.type.Schema; import org.geotools.feature.NameImpl; import org.geotools.feature.type.FeatureTypeFactoryImpl; import org.geotools.feature.type.SchemaImpl; @@ -54,16 +60,8 @@ import org.geotools.graph.util.graph.CycleDetector; import org.geotools.graph.util.graph.DirectedCycleDetector; import org.geotools.util.Utilities; -import org.geotools.xsd.Schemas; import org.geotools.xs.XS; -import org.geotools.api.feature.Attribute; -import org.geotools.api.feature.type.AttributeDescriptor; -import org.geotools.api.feature.type.AttributeType; -import org.geotools.api.feature.type.ComplexType; -import org.geotools.api.feature.type.FeatureTypeFactory; -import org.geotools.api.feature.type.Name; -import org.geotools.api.feature.type.PropertyDescriptor; -import org.geotools.api.feature.type.Schema; +import org.geotools.xsd.Schemas; /** * Parses an XML schema to procuce an instance of @@ -313,9 +311,8 @@ public Collection getImports() { public XSDTypeDefinition getXSDType(AttributeType type) { for (Entry xsdTypeDefinitionAttributeTypeEntry : types.entrySet()) { - Entry entry = xsdTypeDefinitionAttributeTypeEntry; - XSDTypeDefinition xsdType = (XSDTypeDefinition) entry.getKey(); - AttributeType gtType = (AttributeType) entry.getValue(); + XSDTypeDefinition xsdType = xsdTypeDefinitionAttributeTypeEntry.getKey(); + AttributeType gtType = xsdTypeDefinitionAttributeTypeEntry.getValue(); if (gtType.equals(type)) { return xsdType; diff --git a/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java b/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java index 8fd2b3b68c1..48af72c114f 100644 --- a/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java +++ b/build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java @@ -339,9 +339,7 @@ public String generate(Object argument) if (!type.getUserData().isEmpty()) { //attributes for (Map.Entry objectObjectEntry : type.getUserData().entrySet()) { - Map.Entry entry = objectObjectEntry; - Name n = (Name) entry.getKey(); - PropertyDescriptor pd = (PropertyDescriptor) entry.getValue(); + PropertyDescriptor pd = (PropertyDescriptor) objectObjectEntry.getValue(); PropertyType pdType = pd.getType(); String pdTypeName = pdType.getName().getLocalPart().toUpperCase() + diff --git a/modules/extension/app-schema/app-schema/src/test/java/org/geotools/data/complex/BoreholeTest.java b/modules/extension/app-schema/app-schema/src/test/java/org/geotools/data/complex/BoreholeTest.java index a8a71b3dd58..b0cb3509097 100644 --- a/modules/extension/app-schema/app-schema/src/test/java/org/geotools/data/complex/BoreholeTest.java +++ b/modules/extension/app-schema/app-schema/src/test/java/org/geotools/data/complex/BoreholeTest.java @@ -181,9 +181,8 @@ public void testParseBoreholeSchema() throws Exception { expectedNamesAndTypes.put(name(XMMLNS, "log"), typeName(XMMLNS, "LogPropertyType")); for (Entry nameNameEntry : expectedNamesAndTypes.entrySet()) { - Entry entry = nameNameEntry; - Name dName = (Name) entry.getKey(); - Name tName = (Name) entry.getValue(); + Name dName = nameNameEntry.getKey(); + Name tName = nameNameEntry.getValue(); AttributeDescriptor d = (AttributeDescriptor) Types.descriptor(borehole, dName); assertNotNull("Descriptor not found: " + dName, d); diff --git a/modules/extension/complex/src/main/java/org/geotools/data/complex/feature/type/FeatureTypeRegistry.java b/modules/extension/complex/src/main/java/org/geotools/data/complex/feature/type/FeatureTypeRegistry.java index ac7a88501f3..0f52eba6572 100644 --- a/modules/extension/complex/src/main/java/org/geotools/data/complex/feature/type/FeatureTypeRegistry.java +++ b/modules/extension/complex/src/main/java/org/geotools/data/complex/feature/type/FeatureTypeRegistry.java @@ -638,9 +638,8 @@ private void createFoundationTypes() { protected void importSchema(Schema schema) { for (Entry nameAttributeTypeEntry : schema.entrySet()) { - Entry entry = nameAttributeTypeEntry; - Name key = (Name) entry.getKey(); - Object value = entry.getValue(); + Name key = nameAttributeTypeEntry.getKey(); + Object value = nameAttributeTypeEntry.getValue(); if (typeRegistry.containsKey(key)) { LOGGER.finer("Ignoring " + key diff --git a/modules/extension/mbstyle/src/main/java/org/geotools/mbstyle/MBStyle.java b/modules/extension/mbstyle/src/main/java/org/geotools/mbstyle/MBStyle.java index c8e35647713..717142439a9 100644 --- a/modules/extension/mbstyle/src/main/java/org/geotools/mbstyle/MBStyle.java +++ b/modules/extension/mbstyle/src/main/java/org/geotools/mbstyle/MBStyle.java @@ -135,7 +135,6 @@ public MBLayer layer(String id) { public List layers() { JSONArray layers = parse.getJSONArray(json, "layers"); List layersList = new ArrayList<>(); - @SuppressWarnings("PMD.UnusedLocalVariable") int labelPriority = 0; for (Object obj : layers) { if (obj instanceof JSONObject) { @@ -156,7 +155,8 @@ public List layers() { } // adjust label priority so that the labels of the last layer are painted first if (mbLayer instanceof SymbolMBLayer) { - ((SymbolMBLayer) mbLayer).setLabelPriority(labelPriority += DEFAULT_LABEL_PRIORITY); + labelPriority += DEFAULT_LABEL_PRIORITY; + ((SymbolMBLayer) mbLayer).setLabelPriority(labelPriority); } layersList.add(mbLayer); } else { diff --git a/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xsd/impl/ParseExecutor.java b/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xsd/impl/ParseExecutor.java index e625868daea..4b15838c16a 100644 --- a/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xsd/impl/ParseExecutor.java +++ b/modules/extension/xsd/xsd-core/src/main/java/org/geotools/xsd/impl/ParseExecutor.java @@ -279,8 +279,7 @@ public XSDNamedComponent getDeclaration() { // atomic // walk through the facets and preparse as necessary - for (org.eclipse.xsd.XSDConstrainingFacet xsdConstrainingFacet : type.getFacets()) { - XSDFacet facet = xsdConstrainingFacet; + for (org.eclipse.xsd.XSDConstrainingFacet facet : type.getFacets()) { if (facet instanceof XSDWhiteSpaceFacet && !parser.isCDATA()) { XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet; diff --git a/modules/extension/xsd/xsd-core/src/test/java/org/geotools/xsd/test/XMLTestSupport.java b/modules/extension/xsd/xsd-core/src/test/java/org/geotools/xsd/test/XMLTestSupport.java index 10096a2b82f..5d6d0fcd809 100644 --- a/modules/extension/xsd/xsd-core/src/test/java/org/geotools/xsd/test/XMLTestSupport.java +++ b/modules/extension/xsd/xsd-core/src/test/java/org/geotools/xsd/test/XMLTestSupport.java @@ -337,15 +337,14 @@ protected Binding binding(QName name) { throw new RuntimeException(e); } - for (Map.Entry stringStringEntry : mappings.entrySet()) { - Map.Entry mapping = stringStringEntry; - String key = (String) mapping.getKey(); + for (Map.Entry mapping : mappings.entrySet()) { + String key = mapping.getKey(); if (key == null) { key = ""; } - namespaces.declarePrefix(key, (String) mapping.getValue()); + namespaces.declarePrefix(key, mapping.getValue()); } context.registerComponentInstance(namespaces); diff --git a/modules/library/cql/src/main/java/org/geotools/filter/text/commons/AbstractFilterBuilder.java b/modules/library/cql/src/main/java/org/geotools/filter/text/commons/AbstractFilterBuilder.java index 2191df2ddef..a69bdce3ebd 100644 --- a/modules/library/cql/src/main/java/org/geotools/filter/text/commons/AbstractFilterBuilder.java +++ b/modules/library/cql/src/main/java/org/geotools/filter/text/commons/AbstractFilterBuilder.java @@ -665,10 +665,7 @@ public BinarySpatialOperator buildSpatialEqualFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.equal(property, geom); + return filterFactory.equal(property, geom); } public BinarySpatialOperator buildSpatialDisjointFilter() throws CQLException { @@ -676,10 +673,7 @@ public BinarySpatialOperator buildSpatialDisjointFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.disjoint(property, geom); + return filterFactory.disjoint(property, geom); } public BinarySpatialOperator buildSpatialIntersectsFilter() throws CQLException { @@ -688,10 +682,7 @@ public BinarySpatialOperator buildSpatialIntersectsFilter() throws CQLException Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.intersects(property, geom); + return filterFactory.intersects(property, geom); } public PropertyIsEqualTo buildSpatialRelateFilter() throws CQLException { @@ -726,10 +717,7 @@ public BinarySpatialOperator buildSpatialTouchesFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.touches(property, geom); + return filterFactory.touches(property, geom); } public BinarySpatialOperator buildSpatialCrossesFilter() throws CQLException { @@ -737,10 +725,7 @@ public BinarySpatialOperator buildSpatialCrossesFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.crosses(property, geom); + return filterFactory.crosses(property, geom); } public BinarySpatialOperator buildSpatialWithinFilter() throws CQLException { @@ -749,10 +734,7 @@ public BinarySpatialOperator buildSpatialWithinFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.within(property, geom); + return filterFactory.within(property, geom); } public BinarySpatialOperator buildSpatialContainsFilter() throws CQLException { @@ -761,10 +743,7 @@ public BinarySpatialOperator buildSpatialContainsFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.contains(property, geom); + return filterFactory.contains(property, geom); } public BinarySpatialOperator buildSpatialOverlapsFilter() throws CQLException { @@ -773,10 +752,7 @@ public BinarySpatialOperator buildSpatialOverlapsFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.overlaps(property, geom); + return filterFactory.overlaps(property, geom); } public Filter buildBBox() throws CQLException { @@ -816,10 +792,7 @@ public DistanceBufferOperator buildSpatialDWithinFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.dwithin(property, geom, tolerance, unit); + return filterFactory.dwithin(property, geom, tolerance, unit); } public DistanceBufferOperator buildSpatialBeyondFilter() throws CQLException { @@ -832,10 +805,7 @@ public DistanceBufferOperator buildSpatialBeyondFilter() throws CQLException { Expression property = this.resultStack.popExpression(); - FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry - // implementation - - return ff.beyond(property, geom, tolerance, unit); + return filterFactory.beyond(property, geom, tolerance, unit); } /** diff --git a/modules/library/main/src/main/java/org/geotools/data/DataUtilities.java b/modules/library/main/src/main/java/org/geotools/data/DataUtilities.java index 5d82d3e7407..a5f1c9652c4 100644 --- a/modules/library/main/src/main/java/org/geotools/data/DataUtilities.java +++ b/modules/library/main/src/main/java/org/geotools/data/DataUtilities.java @@ -722,11 +722,10 @@ public static Object duplicate(Object src) { if (src instanceof Map) { @SuppressWarnings("unchecked") - Map map = (Map) src; + Map map = (Map) src; Map copy = new HashMap<>(map.size()); - for (Map.Entry objectObjectEntry : map.entrySet()) { - Map.Entry entry = objectObjectEntry; + for (Map.Entry entry : map.entrySet()) { copy.put(entry.getKey(), duplicate(entry.getValue())); } diff --git a/modules/library/main/src/main/java/org/geotools/data/store/DataFeatureCollection.java b/modules/library/main/src/main/java/org/geotools/data/store/DataFeatureCollection.java index 8ad56658504..18fa29bbc38 100644 --- a/modules/library/main/src/main/java/org/geotools/data/store/DataFeatureCollection.java +++ b/modules/library/main/src/main/java/org/geotools/data/store/DataFeatureCollection.java @@ -101,8 +101,9 @@ protected void fireChange(SimpleFeature feature, int type) { } protected void fireChange(Collection coll, int type) { - @SuppressWarnings({"unchecked", "PMD.UnnecessaryCast"}) - SimpleFeature[] features = (SimpleFeature[]) coll.toArray(n -> new SimpleFeature[n]); + @SuppressWarnings("unchecked") + Collection fcoll = coll; + SimpleFeature[] features = fcoll.toArray(SimpleFeature[]::new); fireChange(features, type); } diff --git a/modules/library/main/src/main/java/org/geotools/feature/visitor/AbstractCalcResult.java b/modules/library/main/src/main/java/org/geotools/feature/visitor/AbstractCalcResult.java index f97a15e52d9..7a6d8385b61 100644 --- a/modules/library/main/src/main/java/org/geotools/feature/visitor/AbstractCalcResult.java +++ b/modules/library/main/src/main/java/org/geotools/feature/visitor/AbstractCalcResult.java @@ -156,7 +156,8 @@ public Set toSet() { } @Override - public List toList() { + @SuppressWarnings("unchecked") + public List toList() { Object value = getValue(); if (value == null) { @@ -164,27 +165,14 @@ public List toList() { } if (value instanceof List) { - List list = (List) value; - - return list; + return (List) value; } if (value.getClass().isArray()) { return Arrays.asList((Object[]) value); } - if (value instanceof HashSet) { - Set set = (HashSet) value; - // Object[] values = set.toArray(); - return Arrays.asList(set.toArray()); - // List list = new ArrayList(); - // for (int i = 0; i < values.length; i++) - // list.add(values[i]); - // return list; - } - if (value instanceof Collection) { - @SuppressWarnings("unchecked") Collection cast = (Collection) value; return new ArrayList<>(cast); } @@ -194,7 +182,7 @@ public List toList() { @Override public Object[] toArray() { - List list = toList(); + List list = toList(); if (list == null) { return null; @@ -203,7 +191,6 @@ public Object[] toArray() { return list.toArray(); } - @SuppressWarnings("unchecked") public String[] toStringArray() { List list = toList(); @@ -211,7 +198,7 @@ public String[] toStringArray() { return null; } - return list.stream().map(o -> o != null ? String.valueOf(o) : null).toArray(n -> new String[n]); + return list.stream().map(o -> o != null ? String.valueOf(o) : null).toArray(String[]::new); } @Override diff --git a/modules/library/main/src/main/java/org/geotools/filter/function/EqualIntervalFunction.java b/modules/library/main/src/main/java/org/geotools/filter/function/EqualIntervalFunction.java index 2071ec54e90..00ef254516d 100644 --- a/modules/library/main/src/main/java/org/geotools/filter/function/EqualIntervalFunction.java +++ b/modules/library/main/src/main/java/org/geotools/filter/function/EqualIntervalFunction.java @@ -139,7 +139,7 @@ private RangedClassifier calculateNonNumerical(int classNum, FeatureCollection stringStringEntry : map.entrySet()) { - final Map.Entry entry = stringStringEntry; - final String oldName = (String) entry.getKey(); - final String newName = (String) entry.getValue(); + for (Map.Entry entry : map.entrySet()) { + final String oldName = entry.getKey(); + final String newName = entry.getValue(); /* * Replaces all occurences of 'oldName' by 'newName'. */ diff --git a/modules/library/referencing/src/main/java/org/geotools/referencing/factory/wms/WebCRSFactory.java b/modules/library/referencing/src/main/java/org/geotools/referencing/factory/wms/WebCRSFactory.java index 326c4395f7e..cc6b7e84271 100644 --- a/modules/library/referencing/src/main/java/org/geotools/referencing/factory/wms/WebCRSFactory.java +++ b/modules/library/referencing/src/main/java/org/geotools/referencing/factory/wms/WebCRSFactory.java @@ -129,11 +129,10 @@ public Citation getAuthority() { public Set getAuthorityCodes(final Class type) throws FactoryException { ensureInitialized(); final Set set = new LinkedHashSet<>(); - for (Map.Entry integerCoordinateReferenceSystemEntry : crsMap.entrySet()) { - final Map.Entry entry = integerCoordinateReferenceSystemEntry; - final CoordinateReferenceSystem crs = (CoordinateReferenceSystem) entry.getValue(); + for (Map.Entry entry : crsMap.entrySet()) { + final CoordinateReferenceSystem crs = entry.getValue(); if (type.isAssignableFrom(crs.getClass())) { - final Integer code = (Integer) entry.getKey(); + final Integer code = entry.getKey(); set.add(String.valueOf(code)); } } diff --git a/modules/library/referencing/src/main/java/org/geotools/referencing/wkt/Preprocessor.java b/modules/library/referencing/src/main/java/org/geotools/referencing/wkt/Preprocessor.java index c1b91b56e8f..527112f058c 100644 --- a/modules/library/referencing/src/main/java/org/geotools/referencing/wkt/Preprocessor.java +++ b/modules/library/referencing/src/main/java/org/geotools/referencing/wkt/Preprocessor.java @@ -246,9 +246,8 @@ private String substitute(final String text) { replacements = last = new Replacement(0, 0, offset); StringBuilder buffer = null; for (Map.Entry stringDefinitionEntry : definitions.entrySet()) { - final Map.Entry entry = stringDefinitionEntry; - final String name = (String) entry.getKey(); - final Definition def = (Definition) entry.getValue(); + final String name = stringDefinitionEntry.getKey(); + final Definition def = stringDefinitionEntry.getValue(); int index = (buffer != null) ? buffer.indexOf(name) : text.indexOf(name); while (index >= 0) { /* @@ -368,9 +367,8 @@ public void printDefinitions(final Writer out) throws IOException { table.nextLine(); table.writeHorizontalSeparator(); for (Map.Entry stringDefinitionEntry : definitions.entrySet()) { - final Map.Entry entry = stringDefinitionEntry; - final Object object = ((Definition) entry.getValue()).asObject; - table.write(String.valueOf(entry.getKey())); + final Object object = stringDefinitionEntry.getValue().asObject; + table.write(stringDefinitionEntry.getKey()); table.nextColumn(); table.write(Classes.getShortClassName(object)); table.nextColumn(); diff --git a/modules/library/xml/src/main/java/org/geotools/xml/styling/SLDTransformer.java b/modules/library/xml/src/main/java/org/geotools/xml/styling/SLDTransformer.java index 4cfa3ed4e09..29eadd597d7 100644 --- a/modules/library/xml/src/main/java/org/geotools/xml/styling/SLDTransformer.java +++ b/modules/library/xml/src/main/java/org/geotools/xml/styling/SLDTransformer.java @@ -179,10 +179,9 @@ public Translator createTranslator(ContentHandler handler) { // add pre-configured namespace mappings if (!uri2prefix.isEmpty()) { for (Entry uriStringEntry : uri2prefix.entrySet()) { - Entry e = uriStringEntry; - URI uri = (URI) e.getKey(); + URI uri = uriStringEntry.getKey(); if (uri != null) { - String prefix = (String) e.getValue(); + String prefix = uriStringEntry.getValue(); // FIXME handle default namespace and possible clash with // one already known to the namespace-support delegate; i.e. // the entry with an empty prefix