Skip to content

Commit

Permalink
Updating PMD to 7.2.0, mostly cleaning up unecessary type specs and e…
Browse files Browse the repository at this point in the history
…mpty statements
  • Loading branch information
aaime committed Jun 9, 2024
1 parent c3bbebf commit 8d37f42
Show file tree
Hide file tree
Showing 63 changed files with 140 additions and 173 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public ConveyorTile doNonMetatilingRequest(ConveyorTile tile)

@Override
protected Matcher<TileLayer> infoEquals(TileLayer expected) {
return new CustomMatcher<TileLayer>(
return new CustomMatcher<>(
"ArcGISCacheLayer matching "
+ expected.getName()
+ " with "
Expand All @@ -140,7 +140,7 @@ public boolean matches(Object item) {

@Override
protected Matcher<TileLayer> infoEquals(int expected) {
return new CustomMatcher<TileLayer>("ArcGISCacheLayer with value" + expected) {
return new CustomMatcher<>("ArcGISCacheLayer with value" + expected) {

@Override
public boolean matches(Object item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public boolean delete(TileRange tileRange) throws StorageException {

// open an iterator oer tile locations, to avoid memory accumulation
final Iterator<long[]> tileLocations =
new AbstractIterator<long[]>() {
new AbstractIterator<>() {

// TileRange iterator with 1x1 meta tiling factor
private TileRangeIterator trIter =
Expand Down Expand Up @@ -405,7 +405,7 @@ public boolean removeListener(BlobStoreListener listener) {
@Override
public boolean rename(String oldLayerName, String newLayerName) throws StorageException {
log.fine("No need to rename layers, AzureBlobStore uses layer id as key root");
if (client.listBlobs(oldLayerName, 1).size() > 0) {
if (!client.listBlobs(oldLayerName, 1).isEmpty()) {
listeners.sendLayerRenamed(oldLayerName, newLayerName);
}
return true;
Expand Down Expand Up @@ -443,7 +443,7 @@ private Properties getLayerMetadata(String layerName) {
@Override
public boolean layerExists(String layerName) {
final String coordsPrefix = keyBuilder.forLayer(layerName);
return client.listBlobs(coordsPrefix, 1).size() > 0;
return !client.listBlobs(coordsPrefix, 1).isEmpty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public void issuePendingBulkDeletes() throws StorageException {

public synchronized boolean asyncDelete(String prefix, long timestamp) {
// do we have anything to delete?
if (client.listBlobs(prefix, 1).size() == 0) {
if (client.listBlobs(prefix, 1).isEmpty()) {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ public DefaultGridsets(boolean useEPSG900913, boolean useGWC11xNames) {
266.144470692553,
133.072235346276,
66.5361176731382,
33.2680588365691,
33.2680588365691
};

// the 60 UTM zones from the OGC TMS specification
Expand All @@ -441,32 +441,7 @@ public DefaultGridsets(boolean useEPSG900913, boolean useGWC11xNames) {
20003931.4586255),
true,
null,
new double[] {
279072704.500914,
139536352.250457,
69768176.1252285,
34884088.0626143,
17442044.0313071,
8721022.01565356,
4360511.00782678,
2180255.50391339,
1090127.7519567,
545063.875978348,
272531.937989174,
136265.968994587,
68132.9844972935,
34066.4922486467,
17033.2461243234,
8516.62306216168,
4258.31153108084,
2129.15576554042,
1064.57788277021,
532.288941385105,
266.144470692553,
133.072235346276,
66.5361176731382,
33.2680588365691
},
UTM_SCALES,
1d,
GridSetFactory.DEFAULT_PIXEL_SIZE_METER,
new String[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static enum PathGeneratorType {
DEFAULT,
TMS,
SLIPPY
};
}

private static final long serialVersionUID = -6470560864068854508L;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public abstract class Conveyor {
public static enum RequestHandler {
LAYER,
SERVICE
};
}

public static enum CacheResult {
HIT,
MISS,
WMS,
OTHER
};
}

private String layerId = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,19 @@ public long getSize() {

/** @see org.geowebcache.io.Resource#transferTo(java.nio.channels.WritableByteChannel) */
@Override
@SuppressWarnings({"PMD.UnusedLocalVariable", "PMD.EmptyControlStatement"})
public long transferTo(WritableByteChannel channel) throws IOException {
if (length > 0) {
ByteBuffer buffer = ByteBuffer.wrap(data, offset, length);
long written = 0;
while ((written += channel.write(buffer)) < length) {;
}
while ((written += channel.write(buffer)) < length) ;
}
return length;
}

/** @see org.geowebcache.io.Resource#transferFrom(java.nio.channels.ReadableByteChannel) */
@Override
@SuppressWarnings({"PMD.UnusedLocalVariable", "PMD.EmptyControlStatement"})
public long transferFrom(ReadableByteChannel channel) throws IOException {
if (channel instanceof FileChannel) {
FileChannel fc = (FileChannel) channel;
Expand All @@ -114,8 +115,7 @@ public long transferFrom(ReadableByteChannel channel) throws IOException {
}
ByteBuffer buffer = ByteBuffer.wrap(data);
int read = 0;
while ((read += channel.read(buffer)) < length) {;
}
while ((read += channel.read(buffer)) < length) ;
} else {
offset = 0;
length = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,24 +49,25 @@ public long getSize() {
}

@Override
@SuppressWarnings({"PMD.UnusedLocalVariable", "PMD.EmptyControlStatement"})
public long transferTo(WritableByteChannel target) throws IOException {
// FileLock lock = in.lock();

try (FileInputStream fis = new FileInputStream(file);
FileChannel in = fis.getChannel(); ) {
final long size = in.size();
long written = 0;
while ((written += in.transferTo(written, size, target)) < size) {;
}
while ((written += in.transferTo(written, size, target)) < size) ;
return size;
}
}

@Override
@SuppressWarnings("PMD.UnusedLocalVariable")
public long transferFrom(ReadableByteChannel channel) throws IOException {
try (FileOutputStream fos = new FileOutputStream(file);
FileChannel out = fos.getChannel();
FileLock lock = out.lock(); ) {
FileLock lock = out.lock()) {
final int buffsize = 4096;
long position = 0;
long read;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext co
reader.moveUp();
}
populateCollection(reader, context, result, set);
if (set.size() > 0) {
if (!set.isEmpty()) {
result.addAll(set); // comparator will not be called if internally optimized
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public Iterable<TileLayer> getLayerListFiltered() {
Stream s =
StreamSupport.stream(result.spliterator(), false)
.filter(x -> !tileLayerDispatcherFilter.exclude(x));
result = (Iterable<TileLayer>) s::iterator;
result = s::iterator;
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public enum GeometryType {
point,
line,
polygon
};
}

String id;
String description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class WMSLayer extends AbstractTileLayer implements ProxyLayer {
public enum RequestType {
MAP,
FEATUREINFO
};
}

public enum HttpRequestMode {
Get,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public class ImageMime extends MimeType {
public boolean isCompatible(String otherMimeType) {
return super.isCompatible(otherMimeType)
|| otherMimeType.startsWith("image/png");
};
}
};

public static final ImageMime jpeg =
Expand Down Expand Up @@ -336,7 +336,7 @@ public String getMimeType(org.geowebcache.io.Resource resource) throws IOExcepti
return pngDelegate.getMimeType();
}
}
};
}

@Override
public boolean isCompatible(String otherMimeType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ public static enum TYPE {
SEED,
RESEED,
TRUNCATE
};
}

public static enum STATE {
UNSET,
READY,
RUNNING,
DONE,
DEAD
};
}

/**
* Value shared between all the threads in the group, is incremented each time a task starts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,9 @@ private void updateStatusInfo(TileLayer layer, long tilesCount, long start_time)
// estimated time of completion in seconds, use a moving average over the last
this.timeSpent = (int) (System.currentTimeMillis() - start_time) / 1000;

int threadCount = sharedThreadCount.get();
long timeTotal =
Math.round(
(double) timeSpent
* (((double) tilesTotal / threadCount) / (double) tilesCount));
// using double to force the next calcuation to double type
double threadCount = sharedThreadCount.get();
long timeTotal = Math.round(timeSpent * ((tilesTotal / threadCount) / tilesCount));

this.timeRemaining = (int) (timeTotal - timeSpent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static enum Status {
MISS,
LOCK,
EXPIRED_LOCK
};
}

Status status = Status.UNSET;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class TransientCache {
private static FilePathGenerator keyGenerator = new DefaultFilePathGenerator("");

private Map<String, CachedResource> cache =
new LinkedHashMap<String, CachedResource>() {
new LinkedHashMap<>() {

/** serialVersionUID */
private static final long serialVersionUID = -4106644240603796847L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
public interface TileFileVisitor {

/** Invoked before visitng a directory */
default void preVisitDirectory(File dir) {};
default void preVisitDirectory(File dir) {}

/** Invoked on a specific tile file */
public void visitFile(File tile, long x, long y, int z);

/** Invoked on a directory post file visit */
default void postVisitDirectory(File dir) {};
default void postVisitDirectory(File dir) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public enum Convention {
TMS,
/** Slippy map convention, where tile coordinates have their * origin at top left (NW) */
XYZ
};
}

@SuppressWarnings("unused")
private static Logger log = Logging.getLogger(XYZFilePathGenerator.class.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ private ExceptionUtils() {}
public static <T extends Throwable> boolean isOrSuppresses(T e, Class<? extends T> klazz) {
return Streams.concat(Stream.of(e), Arrays.stream(e.getSuppressed()))
.anyMatch(klazz::isInstance);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ public static String[][] selectedStringArraysFromMap(
public static Map<String, String> selectedStringsFromMap(
Map<String, ?> map, String encoding, String... keys) {

map = new CaseInsensitiveMap(map);
Map<String, String> selected = new CaseInsensitiveMap();
map = new CaseInsensitiveMap<>(map);
Map<String, String> selected = new CaseInsensitiveMap<>();
for (String key : keys) {
Object value = map.get(key);
if (value != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public static SeedRequest createRequest(
}

/** Matcher for an {@link HttpServletResponse} that checks its status. */
@SuppressWarnings("PMD.UseDiamondOperator")
public static Matcher<HttpServletResponse> hasStatus(HttpStatus expected) {
return new BaseMatcher<HttpServletResponse>() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ public void testGetExisting() throws Exception {
assertThat(retrieved, isPresent());
}

@SuppressWarnings("unchecked")
@SuppressWarnings({"unchecked", "PMD.UnnecessaryCast"})
@Test
public void testCantModifyReturnedCollection() throws Exception {
I info = getGoodInfo("test", 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ protected GridSetConfiguration getSecondConfig() throws Exception {

@Override
protected Matcher<GridSet> infoEquals(GridSet expected) {
return new CustomMatcher<GridSet>(
return new CustomMatcher<>(
"GridSet matching " + expected.getName() + " with " + expected.getDescription()) {

@Override
Expand All @@ -53,7 +53,7 @@ public boolean matches(Object item) {

@Override
protected Matcher<GridSet> infoEquals(int expected) {
return new CustomMatcher<GridSet>("GridSet with value " + expected) {
return new CustomMatcher<>("GridSet with value " + expected) {

@Override
public boolean matches(Object item) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected String getExistingInfo() {

@Override
protected Matcher<BlobStoreInfo> infoEquals(BlobStoreInfo expected) {
return new CustomMatcher<BlobStoreInfo>("BlobStoreInfo Matcher") {
return new CustomMatcher<>("BlobStoreInfo Matcher") {
@Override
public boolean matches(Object item) {
return expected.equals(item);
Expand All @@ -147,7 +147,7 @@ public boolean matches(Object item) {

@Override
protected Matcher<BlobStoreInfo> infoEquals(int expected) {
return new CustomMatcher<BlobStoreInfo>("BlobStoreInfo with value " + expected) {
return new CustomMatcher<>("BlobStoreInfo with value " + expected) {

@Override
public boolean matches(Object item) {
Expand Down
Loading

0 comments on commit 8d37f42

Please sign in to comment.