Polishing

This commit is contained in:
Sam Brannen
2023-03-02 16:22:42 +01:00
parent fe29e734ae
commit c0a1e1718e
11 changed files with 33 additions and 36 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -56,8 +56,7 @@ public abstract class AbstractFileResolvingResource extends AbstractResource {
// Try a URL connection content-length header
URLConnection con = url.openConnection();
customizeConnection(con);
HttpURLConnection httpCon =
(con instanceof HttpURLConnection ? (HttpURLConnection) con : null);
HttpURLConnection httpCon = (con instanceof HttpURLConnection huc ? huc : null);
if (httpCon != null) {
httpCon.setRequestMethod("HEAD");
int code = httpCon.getResponseCode();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -226,9 +226,9 @@ public abstract class AbstractResource implements Resource {
* @see #getDescription()
*/
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof Resource &&
((Resource) other).getDescription().equals(getDescription())));
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof Resource that &&
getDescription().equals(that.getDescription())));
}
/**

View File

@@ -129,9 +129,9 @@ public class ByteArrayResource extends AbstractResource {
* @see java.util.Arrays#equals(byte[], byte[])
*/
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof ByteArrayResource &&
Arrays.equals(((ByteArrayResource) other).byteArray, this.byteArray)));
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof ByteArrayResource that &&
Arrays.equals(this.byteArray, that.byteArray)));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -272,9 +272,9 @@ public class ClassPathResource extends AbstractFileResolvingResource {
if (this == obj) {
return true;
}
return ((obj instanceof ClassPathResource other) &&
this.absolutePath.equals(other.absolutePath) &&
ObjectUtils.nullSafeEquals(getClassLoader(), other.getClassLoader()));
return ((obj instanceof ClassPathResource that) &&
this.absolutePath.equals(that.absolutePath) &&
ObjectUtils.nullSafeEquals(getClassLoader(), that.getClassLoader()));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -72,9 +72,9 @@ public class DescriptiveResource extends AbstractResource {
* This implementation compares the underlying description String.
*/
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof DescriptiveResource &&
((DescriptiveResource) other).description.equals(this.description)));
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof DescriptiveResource that &&
this.description.equals(that.description)));
}
/**

View File

@@ -396,8 +396,7 @@ public class FileSystemResource extends AbstractResource implements WritableReso
*/
@Override
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof FileSystemResource other &&
this.path.equals(other.path)));
return (this == obj || (obj instanceof FileSystemResource that && this.path.equals(that.path)));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -115,9 +115,9 @@ public class InputStreamResource extends AbstractResource {
* This implementation compares the underlying InputStream.
*/
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof InputStreamResource &&
((InputStreamResource) other).inputStream.equals(this.inputStream)));
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof InputStreamResource that &&
this.inputStream.equals(that.inputStream)));
}
/**

View File

@@ -298,9 +298,8 @@ public class PathResource extends AbstractResource implements WritableResource {
* This implementation compares the underlying Path references.
*/
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof PathResource &&
this.path.equals(((PathResource) other).path)));
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof PathResource that && this.path.equals(that.path)));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -343,9 +343,9 @@ public class UrlResource extends AbstractFileResolvingResource {
* This implementation compares the underlying URL references.
*/
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof UrlResource resource &&
getCleanedUrl().equals(resource.getCleanedUrl())));
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof UrlResource that &&
getCleanedUrl().equals(that.getCleanedUrl())));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -130,9 +130,9 @@ public class VfsResource extends AbstractResource {
}
@Override
public boolean equals(@Nullable Object other) {
return (this == other || (other instanceof VfsResource &&
this.resource.equals(((VfsResource) other).resource)));
public boolean equals(@Nullable Object obj) {
return (this == obj || (obj instanceof VfsResource that &&
this.resource.equals(that.resource)));
}
@Override

View File

@@ -808,7 +808,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol
Set<Resource> result = new LinkedHashSet<>();
try (Stream<Path> files = Files.walk(rootPath)) {
files.filter(isMatchingFile).sorted().forEach(file -> result.add(new FileSystemResource(file)));
files.filter(isMatchingFile).sorted().map(FileSystemResource::new).forEach(result::add);
}
catch (Exception ex) {
if (logger.isWarnEnabled()) {