Use pattern matching for instanceof where appropriate

See gh-31475
This commit is contained in:
dreis2211
2022-06-20 18:14:16 +02:00
committed by Andy Wilkinson
parent a7b98e7312
commit 5db04da275
278 changed files with 1049 additions and 1126 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2022 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.
@@ -113,8 +113,8 @@ public class DefaultLaunchScript implements LaunchScript {
}
private String parseFilePropertyValue(Object propertyValue) throws IOException {
if (propertyValue instanceof File) {
return loadContent((File) propertyValue);
if (propertyValue instanceof File file) {
return loadContent(file);
}
return loadContent(new File(propertyValue.toString()));
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2021 the original author or authors.
* Copyright 2012-2022 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.
@@ -99,8 +99,8 @@ public class JarWriter extends AbstractJarWriter implements AutoCloseable {
}
private JarArchiveEntry asJarArchiveEntry(ZipEntry entry) throws ZipException {
if (entry instanceof JarArchiveEntry) {
return (JarArchiveEntry) entry;
if (entry instanceof JarArchiveEntry jarArchiveEntry) {
return jarArchiveEntry;
}
return new JarArchiveEntry(entry);
}

View File

@@ -205,8 +205,8 @@ public abstract class Packager {
private void writeLoaderClasses(AbstractJarWriter writer) throws IOException {
Layout layout = getLayout();
if (layout instanceof CustomLoaderLayout) {
((CustomLoaderLayout) getLayout()).writeLoadedClasses(writer);
if (layout instanceof CustomLoaderLayout customLoaderLayout) {
customLoaderLayout.writeLoadedClasses(writer);
}
else if (layout.isExecutable()) {
writer.writeLoaderClasses();
@@ -223,8 +223,8 @@ public abstract class Packager {
}
private EntryTransformer getEntityTransformer() {
if (getLayout() instanceof RepackagingLayout) {
return new RepackagingEntryTransformer((RepackagingLayout) getLayout());
if (getLayout() instanceof RepackagingLayout repackagingLayout) {
return new RepackagingEntryTransformer(repackagingLayout);
}
return EntryTransformer.NONE;
}
@@ -349,8 +349,8 @@ public abstract class Packager {
private void addBootAttributesForLayout(Attributes attributes) {
Layout layout = getLayout();
if (layout instanceof RepackagingLayout) {
attributes.putValue(BOOT_CLASSES_ATTRIBUTE, ((RepackagingLayout) layout).getRepackagedClassesLocation());
if (layout instanceof RepackagingLayout repackagingLayout) {
attributes.putValue(BOOT_CLASSES_ATTRIBUTE, repackagingLayout.getRepackagedClassesLocation());
}
else {
attributes.putValue(BOOT_CLASSES_ATTRIBUTE, layout.getClassesLocation());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2022 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.
@@ -60,8 +60,8 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
}
private InputStream getContentInputStream() throws FileNotFoundException {
if (this.content instanceof File) {
return new FileInputStream((File) this.content);
if (this.content instanceof File file) {
return new FileInputStream(file);
}
return new ByteArrayInputStream((byte[]) this.content);
}
@@ -110,8 +110,8 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
@Override
public void write(byte[] b, int off, int len) throws IOException {
int updatedSize = this.size + len;
if (updatedSize > THRESHOLD && this.outputStream instanceof ByteArrayOutputStream) {
this.outputStream = convertToFileOutputStream((ByteArrayOutputStream) this.outputStream);
if (updatedSize > THRESHOLD && this.outputStream instanceof ByteArrayOutputStream byteArrayOutputStream) {
this.outputStream = convertToFileOutputStream(byteArrayOutputStream);
}
this.outputStream.write(b, off, len);
this.size = updatedSize;
@@ -137,8 +137,8 @@ final class SizeCalculatingEntryWriter implements EntryWriter {
}
Object getContent() {
return (this.outputStream instanceof ByteArrayOutputStream)
? ((ByteArrayOutputStream) this.outputStream).toByteArray() : this.tempFile;
return (this.outputStream instanceof ByteArrayOutputStream byteArrayOutputStream)
? byteArrayOutputStream.toByteArray() : this.tempFile;
}
int getSize() {