mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-15 11:00:47 +02:00
refactor: replace switch statements with modern switch expressions for better readability (#4095)
Co-authored-by: Copilot <[email protected]> Co-authored-by: Anthony Stirling <[email protected]>
This commit is contained in:
co-authored by
Copilot
Anthony Stirling
parent
d01b853335
commit
413cd0c697
@@ -85,19 +85,16 @@ public class ImageProcessingUtils {
|
||||
return 0;
|
||||
}
|
||||
int orientationTag = directory.getInt(ExifSubIFDDirectory.TAG_ORIENTATION);
|
||||
switch (orientationTag) {
|
||||
case 1:
|
||||
return 0;
|
||||
case 6:
|
||||
return 90;
|
||||
case 3:
|
||||
return 180;
|
||||
case 8:
|
||||
return 270;
|
||||
default:
|
||||
return switch (orientationTag) {
|
||||
case 1 -> 0;
|
||||
case 6 -> 90;
|
||||
case 3 -> 180;
|
||||
case 8 -> 270;
|
||||
default -> {
|
||||
log.warn("Unknown orientation tag: {}", orientationTag);
|
||||
return 0;
|
||||
}
|
||||
yield 0;
|
||||
}
|
||||
};
|
||||
} catch (ImageProcessingException | MetadataException e) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -631,16 +631,13 @@ public class PdfUtils {
|
||||
int actualPageCount = pdfDocument.getNumberOfPages();
|
||||
pdfDocument.close();
|
||||
|
||||
switch (comparator.toLowerCase()) {
|
||||
case "greater":
|
||||
return actualPageCount > pageCount;
|
||||
case "equal":
|
||||
return actualPageCount == pageCount;
|
||||
case "less":
|
||||
return actualPageCount < pageCount;
|
||||
default:
|
||||
return switch (comparator.toLowerCase()) {
|
||||
case "greater" -> actualPageCount > pageCount;
|
||||
case "equal" -> actualPageCount == pageCount;
|
||||
case "less" -> actualPageCount < pageCount;
|
||||
default ->
|
||||
throw ExceptionUtils.createInvalidArgumentException("comparator", comparator);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public boolean pageSize(PDDocument pdfDocument, String expectedPageSize) throws IOException {
|
||||
@@ -662,9 +659,15 @@ public class PdfUtils {
|
||||
return actualPageWidth == expectedPageWidth && actualPageHeight == expectedPageHeight;
|
||||
}
|
||||
|
||||
/** Key for storing the dimensions of a rendered image in a map. */
|
||||
private record PdfRenderSettingsKey(float mediaBoxWidth, float mediaBoxHeight, int rotation) {}
|
||||
/**
|
||||
* Key for storing the dimensions of a rendered image in a map.
|
||||
*/
|
||||
private record PdfRenderSettingsKey(float mediaBoxWidth, float mediaBoxHeight, int rotation) {
|
||||
}
|
||||
|
||||
/** Value for storing the dimensions of a rendered image in a map. */
|
||||
private record PdfImageDimensionValue(int width, int height) {}
|
||||
/**
|
||||
* Value for storing the dimensions of a rendered image in a map.
|
||||
*/
|
||||
private record PdfImageDimensionValue(int width, int height) {
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user