diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java index 89a97883c2..dba00a0451 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractFileResolvingResource.java @@ -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(); diff --git a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java index 471e4ae518..2931a3bc09 100644 --- a/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/AbstractResource.java @@ -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()))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java index 6e38d88812..76103d206f 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ByteArrayResource.java @@ -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))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java index 6f33be9ab1..69cb22e4ad 100644 --- a/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/ClassPathResource.java @@ -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())); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java index 3082732b63..0c2291b655 100644 --- a/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/DescriptiveResource.java @@ -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))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java index 3db024f0c4..4e5096f719 100644 --- a/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/FileSystemResource.java @@ -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))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java index 5a5eaa96e9..53bc149b04 100644 --- a/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/InputStreamResource.java @@ -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))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/PathResource.java b/spring-core/src/main/java/org/springframework/core/io/PathResource.java index 53debee25d..2a31bbfe4e 100644 --- a/spring-core/src/main/java/org/springframework/core/io/PathResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/PathResource.java @@ -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))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java index ddda76455c..d770aa9356 100644 --- a/spring-core/src/main/java/org/springframework/core/io/UrlResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/UrlResource.java @@ -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()))); } /** diff --git a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java index 3574a6e67c..aa8ed7c150 100644 --- a/spring-core/src/main/java/org/springframework/core/io/VfsResource.java +++ b/spring-core/src/main/java/org/springframework/core/io/VfsResource.java @@ -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 diff --git a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java index 28d87cad33..182630c143 100644 --- a/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java +++ b/spring-core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java @@ -808,7 +808,7 @@ public class PathMatchingResourcePatternResolver implements ResourcePatternResol Set result = new LinkedHashSet<>(); try (Stream 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()) {