Skip to content

Commit 84edc64

Browse files
groldanaaime
authored andcommitted
[GEOT-7593] Updating to PMD 7.13
Some additional improvements especially around removing redundant or dead code.
1 parent e27d135 commit 84edc64

16 files changed

Lines changed: 54 additions & 111 deletions

File tree

build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/SchemaGenerator.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.util.Collections;
2323
import java.util.HashMap;
2424
import java.util.HashSet;
25-
import java.util.Iterator;
2625
import java.util.List;
2726
import java.util.Map;
2827
import java.util.Map.Entry;
@@ -40,6 +39,13 @@
4039
import org.eclipse.xsd.XSDTypeDefinition;
4140
import org.eclipse.xsd.util.XSDConstants;
4241
import org.eclipse.xsd.util.XSDUtil;
42+
import org.geotools.api.feature.type.AttributeDescriptor;
43+
import org.geotools.api.feature.type.AttributeType;
44+
import org.geotools.api.feature.type.ComplexType;
45+
import org.geotools.api.feature.type.FeatureTypeFactory;
46+
import org.geotools.api.feature.type.Name;
47+
import org.geotools.api.feature.type.PropertyDescriptor;
48+
import org.geotools.api.feature.type.Schema;
4349
import org.geotools.feature.NameImpl;
4450
import org.geotools.feature.type.FeatureTypeFactoryImpl;
4551
import org.geotools.feature.type.SchemaImpl;
@@ -54,16 +60,8 @@
5460
import org.geotools.graph.util.graph.CycleDetector;
5561
import org.geotools.graph.util.graph.DirectedCycleDetector;
5662
import org.geotools.util.Utilities;
57-
import org.geotools.xsd.Schemas;
5863
import org.geotools.xs.XS;
59-
import org.geotools.api.feature.Attribute;
60-
import org.geotools.api.feature.type.AttributeDescriptor;
61-
import org.geotools.api.feature.type.AttributeType;
62-
import org.geotools.api.feature.type.ComplexType;
63-
import org.geotools.api.feature.type.FeatureTypeFactory;
64-
import org.geotools.api.feature.type.Name;
65-
import org.geotools.api.feature.type.PropertyDescriptor;
66-
import org.geotools.api.feature.type.Schema;
64+
import org.geotools.xsd.Schemas;
6765

6866
/**
6967
* Parses an XML schema to procuce an instance of
@@ -313,9 +311,8 @@ public Collection<Schema> getImports() {
313311
public XSDTypeDefinition getXSDType(AttributeType type) {
314312
for (Entry<XSDTypeDefinition, AttributeType> xsdTypeDefinitionAttributeTypeEntry :
315313
types.entrySet()) {
316-
Entry entry = xsdTypeDefinitionAttributeTypeEntry;
317-
XSDTypeDefinition xsdType = (XSDTypeDefinition) entry.getKey();
318-
AttributeType gtType = (AttributeType) entry.getValue();
314+
XSDTypeDefinition xsdType = xsdTypeDefinitionAttributeTypeEntry.getKey();
315+
AttributeType gtType = xsdTypeDefinitionAttributeTypeEntry.getValue();
319316

320317
if (gtType.equals(type)) {
321318
return xsdType;

build/maven/xmlcodegen/src/main/java/org/geotools/maven/xmlcodegen/templates/SchemaClassTemplate.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -339,9 +339,7 @@ public String generate(Object argument)
339339
if (!type.getUserData().isEmpty()) {
340340
//attributes
341341
for (Map.Entry<Object, Object> objectObjectEntry : type.getUserData().entrySet()) {
342-
Map.Entry entry = objectObjectEntry;
343-
Name n = (Name) entry.getKey();
344-
PropertyDescriptor pd = (PropertyDescriptor) entry.getValue();
342+
PropertyDescriptor pd = (PropertyDescriptor) objectObjectEntry.getValue();
345343
PropertyType pdType = pd.getType();
346344

347345
String pdTypeName = pdType.getName().getLocalPart().toUpperCase() +

modules/extension/app-schema/app-schema/src/test/java/org/geotools/data/complex/BoreholeTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,8 @@ public void testParseBoreholeSchema() throws Exception {
181181
expectedNamesAndTypes.put(name(XMMLNS, "log"), typeName(XMMLNS, "LogPropertyType"));
182182

183183
for (Entry<Name, Name> nameNameEntry : expectedNamesAndTypes.entrySet()) {
184-
Entry entry = nameNameEntry;
185-
Name dName = (Name) entry.getKey();
186-
Name tName = (Name) entry.getValue();
184+
Name dName = nameNameEntry.getKey();
185+
Name tName = nameNameEntry.getValue();
187186

188187
AttributeDescriptor d = (AttributeDescriptor) Types.descriptor(borehole, dName);
189188
assertNotNull("Descriptor not found: " + dName, d);

modules/extension/complex/src/main/java/org/geotools/data/complex/feature/type/FeatureTypeRegistry.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,9 +638,8 @@ private void createFoundationTypes() {
638638

639639
protected void importSchema(Schema schema) {
640640
for (Entry<Name, AttributeType> nameAttributeTypeEntry : schema.entrySet()) {
641-
Entry entry = nameAttributeTypeEntry;
642-
Name key = (Name) entry.getKey();
643-
Object value = entry.getValue();
641+
Name key = nameAttributeTypeEntry.getKey();
642+
Object value = nameAttributeTypeEntry.getValue();
644643
if (typeRegistry.containsKey(key)) {
645644
LOGGER.finer("Ignoring "
646645
+ key

modules/extension/mbstyle/src/main/java/org/geotools/mbstyle/MBStyle.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ public MBLayer layer(String id) {
135135
public List<MBLayer> layers() {
136136
JSONArray layers = parse.getJSONArray(json, "layers");
137137
List<MBLayer> layersList = new ArrayList<>();
138-
@SuppressWarnings("PMD.UnusedLocalVariable")
139138
int labelPriority = 0;
140139
for (Object obj : layers) {
141140
if (obj instanceof JSONObject) {
@@ -156,7 +155,8 @@ public List<MBLayer> layers() {
156155
}
157156
// adjust label priority so that the labels of the last layer are painted first
158157
if (mbLayer instanceof SymbolMBLayer) {
159-
((SymbolMBLayer) mbLayer).setLabelPriority(labelPriority += DEFAULT_LABEL_PRIORITY);
158+
labelPriority += DEFAULT_LABEL_PRIORITY;
159+
((SymbolMBLayer) mbLayer).setLabelPriority(labelPriority);
160160
}
161161
layersList.add(mbLayer);
162162
} else {

modules/extension/xsd/xsd-core/src/main/java/org/geotools/xsd/impl/ParseExecutor.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ public XSDNamedComponent getDeclaration() {
279279
// atomic
280280

281281
// walk through the facets and preparse as necessary
282-
for (org.eclipse.xsd.XSDConstrainingFacet xsdConstrainingFacet : type.getFacets()) {
283-
XSDFacet facet = xsdConstrainingFacet;
282+
for (org.eclipse.xsd.XSDConstrainingFacet facet : type.getFacets()) {
284283

285284
if (facet instanceof XSDWhiteSpaceFacet && !parser.isCDATA()) {
286285
XSDWhiteSpaceFacet whitespace = (XSDWhiteSpaceFacet) facet;

modules/extension/xsd/xsd-core/src/test/java/org/geotools/xsd/test/XMLTestSupport.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,14 @@ protected Binding binding(QName name) {
337337
throw new RuntimeException(e);
338338
}
339339

340-
for (Map.Entry<String, String> stringStringEntry : mappings.entrySet()) {
341-
Map.Entry mapping = stringStringEntry;
342-
String key = (String) mapping.getKey();
340+
for (Map.Entry<String, String> mapping : mappings.entrySet()) {
341+
String key = mapping.getKey();
343342

344343
if (key == null) {
345344
key = "";
346345
}
347346

348-
namespaces.declarePrefix(key, (String) mapping.getValue());
347+
namespaces.declarePrefix(key, mapping.getValue());
349348
}
350349

351350
context.registerComponentInstance(namespaces);

modules/library/cql/src/main/java/org/geotools/filter/text/commons/AbstractFilterBuilder.java

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -665,21 +665,15 @@ public BinarySpatialOperator buildSpatialEqualFilter() throws CQLException {
665665

666666
Expression property = this.resultStack.popExpression();
667667

668-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
669-
// implementation
670-
671-
return ff.equal(property, geom);
668+
return filterFactory.equal(property, geom);
672669
}
673670

674671
public BinarySpatialOperator buildSpatialDisjointFilter() throws CQLException {
675672
Literal geom = this.resultStack.popLiteral();
676673

677674
Expression property = this.resultStack.popExpression();
678675

679-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
680-
// implementation
681-
682-
return ff.disjoint(property, geom);
676+
return filterFactory.disjoint(property, geom);
683677
}
684678

685679
public BinarySpatialOperator buildSpatialIntersectsFilter() throws CQLException {
@@ -688,10 +682,7 @@ public BinarySpatialOperator buildSpatialIntersectsFilter() throws CQLException
688682

689683
Expression property = this.resultStack.popExpression();
690684

691-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
692-
// implementation
693-
694-
return ff.intersects(property, geom);
685+
return filterFactory.intersects(property, geom);
695686
}
696687

697688
public PropertyIsEqualTo buildSpatialRelateFilter() throws CQLException {
@@ -726,21 +717,15 @@ public BinarySpatialOperator buildSpatialTouchesFilter() throws CQLException {
726717

727718
Expression property = this.resultStack.popExpression();
728719

729-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
730-
// implementation
731-
732-
return ff.touches(property, geom);
720+
return filterFactory.touches(property, geom);
733721
}
734722

735723
public BinarySpatialOperator buildSpatialCrossesFilter() throws CQLException {
736724
Literal geom = this.resultStack.popLiteral();
737725

738726
Expression property = this.resultStack.popExpression();
739727

740-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
741-
// implementation
742-
743-
return ff.crosses(property, geom);
728+
return filterFactory.crosses(property, geom);
744729
}
745730

746731
public BinarySpatialOperator buildSpatialWithinFilter() throws CQLException {
@@ -749,10 +734,7 @@ public BinarySpatialOperator buildSpatialWithinFilter() throws CQLException {
749734

750735
Expression property = this.resultStack.popExpression();
751736

752-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
753-
// implementation
754-
755-
return ff.within(property, geom);
737+
return filterFactory.within(property, geom);
756738
}
757739

758740
public BinarySpatialOperator buildSpatialContainsFilter() throws CQLException {
@@ -761,10 +743,7 @@ public BinarySpatialOperator buildSpatialContainsFilter() throws CQLException {
761743

762744
Expression property = this.resultStack.popExpression();
763745

764-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
765-
// implementation
766-
767-
return ff.contains(property, geom);
746+
return filterFactory.contains(property, geom);
768747
}
769748

770749
public BinarySpatialOperator buildSpatialOverlapsFilter() throws CQLException {
@@ -773,10 +752,7 @@ public BinarySpatialOperator buildSpatialOverlapsFilter() throws CQLException {
773752

774753
Expression property = this.resultStack.popExpression();
775754

776-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
777-
// implementation
778-
779-
return ff.overlaps(property, geom);
755+
return filterFactory.overlaps(property, geom);
780756
}
781757

782758
public Filter buildBBox() throws CQLException {
@@ -816,10 +792,7 @@ public DistanceBufferOperator buildSpatialDWithinFilter() throws CQLException {
816792

817793
Expression property = this.resultStack.popExpression();
818794

819-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
820-
// implementation
821-
822-
return ff.dwithin(property, geom, tolerance, unit);
795+
return filterFactory.dwithin(property, geom, tolerance, unit);
823796
}
824797

825798
public DistanceBufferOperator buildSpatialBeyondFilter() throws CQLException {
@@ -832,10 +805,7 @@ public DistanceBufferOperator buildSpatialBeyondFilter() throws CQLException {
832805

833806
Expression property = this.resultStack.popExpression();
834807

835-
FilterFactory ff = filterFactory; // TODO this cast must be removed. It depends of Geometry
836-
// implementation
837-
838-
return ff.beyond(property, geom, tolerance, unit);
808+
return filterFactory.beyond(property, geom, tolerance, unit);
839809
}
840810

841811
/**

modules/library/main/src/main/java/org/geotools/data/DataUtilities.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -722,11 +722,10 @@ public static Object duplicate(Object src) {
722722

723723
if (src instanceof Map) {
724724
@SuppressWarnings("unchecked")
725-
Map<Object, Object> map = (Map) src;
725+
Map<Object, Object> map = (Map<Object, Object>) src;
726726
Map<Object, Object> copy = new HashMap<>(map.size());
727727

728-
for (Map.Entry<Object, Object> objectObjectEntry : map.entrySet()) {
729-
Map.Entry entry = objectObjectEntry;
728+
for (Map.Entry<Object, Object> entry : map.entrySet()) {
730729
copy.put(entry.getKey(), duplicate(entry.getValue()));
731730
}
732731

modules/library/main/src/main/java/org/geotools/data/store/DataFeatureCollection.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,9 @@ protected void fireChange(SimpleFeature feature, int type) {
101101
}
102102

103103
protected void fireChange(Collection coll, int type) {
104-
@SuppressWarnings({"unchecked", "PMD.UnnecessaryCast"})
105-
SimpleFeature[] features = (SimpleFeature[]) coll.toArray(n -> new SimpleFeature[n]);
104+
@SuppressWarnings("unchecked")
105+
Collection<SimpleFeature> fcoll = coll;
106+
SimpleFeature[] features = fcoll.toArray(SimpleFeature[]::new);
106107
fireChange(features, type);
107108
}
108109

0 commit comments

Comments
 (0)