Switch order of literals to prevent NullPointerException

This commit is contained in:
pixeebot[bot] 2024-02-02 00:29:18 +00:00
parent 36c277961f
commit 95471a2fba
16 changed files with 40 additions and 40 deletions

View File

@ -16,7 +16,7 @@ public class PropSync {
Map<String, String> enProps = linesToProps(enLines);
for (File file : files) {
if (!file.getName().equals("messages_en_GB.properties")) {
if (!"messages_en_GB.properties".equals(file.getName())) {
System.out.println("Processing file: " + file.getName());
List<String> lines;
try {

View File

@ -25,7 +25,7 @@ public class SPdfApplication {
public void init() {
// Check if the BROWSER_OPEN environment variable is set to true
String browserOpenEnv = env.getProperty("BROWSER_OPEN");
boolean browserOpen = browserOpenEnv != null && browserOpenEnv.equalsIgnoreCase("true");
boolean browserOpen = browserOpenEnv != null && "true".equalsIgnoreCase(browserOpenEnv);
if (browserOpen) {
try {

View File

@ -84,7 +84,7 @@ public class ConfigInitializer
for (String line : templateLines) {
String key = extractKey.apply(line);
if (line.trim().equalsIgnoreCase("AutomaticallyGenerated:")) {
if ("AutomaticallyGenerated:".equalsIgnoreCase(line.trim())) {
insideAutoGenerated = true;
mergedLines.add(line);
continue;

View File

@ -55,7 +55,7 @@ public class ConvertImgPDFController {
colorTypeResult = ImageType.BINARY;
}
// returns bytes for image
boolean singleImage = singleOrMultiple.equals("single");
boolean singleImage = "single".equals(singleOrMultiple);
byte[] result = null;
String filename = Filenames.toSimpleFileName(file.getOriginalFilename()).replaceFirst("[.][^.]+$", "");
try {
@ -114,6 +114,6 @@ public class ConvertImgPDFController {
private String getMediaType(String imageFormat) {
String mimeType = URLConnection.guessContentTypeFromName("." + imageFormat);
return mimeType.equals("null") ? "application/octet-stream" : mimeType;
return "null".equals(mimeType) ? "application/octet-stream" : mimeType;
}
}

View File

@ -74,7 +74,7 @@ public class ExtractImageScansController {
List<String> images = new ArrayList<>();
// Check if input file is a PDF
if (extension.equalsIgnoreCase("pdf")) {
if ("pdf".equalsIgnoreCase(extension)) {
// Load PDF document
try (PDDocument document = Loader.loadPDF(form.getFileInput().getBytes())) {
PDFRenderer pdfRenderer = new PDFRenderer(document);

View File

@ -86,19 +86,19 @@ public class ExtractImagesController {
// Convert image to desired format
RenderedImage renderedImage = image.getImage();
BufferedImage bufferedImage = null;
if (format.equalsIgnoreCase("png")) {
if ("png".equalsIgnoreCase(format)) {
bufferedImage =
new BufferedImage(
renderedImage.getWidth(),
renderedImage.getHeight(),
BufferedImage.TYPE_INT_ARGB);
} else if (format.equalsIgnoreCase("jpeg") || format.equalsIgnoreCase("jpg")) {
} else if ("jpeg".equalsIgnoreCase(format) || "jpg".equalsIgnoreCase(format)) {
bufferedImage =
new BufferedImage(
renderedImage.getWidth(),
renderedImage.getHeight(),
BufferedImage.TYPE_INT_RGB);
} else if (format.equalsIgnoreCase("gif")) {
} else if ("gif".equalsIgnoreCase(format)) {
bufferedImage =
new BufferedImage(
renderedImage.getWidth(),

View File

@ -110,15 +110,15 @@ public class MetadataController {
for (Entry<String, String> entry : allRequestParams.entrySet()) {
String key = entry.getKey();
// Check if the key is a standard metadata key
if (!key.equalsIgnoreCase("Author")
&& !key.equalsIgnoreCase("CreationDate")
&& !key.equalsIgnoreCase("Creator")
&& !key.equalsIgnoreCase("Keywords")
&& !key.equalsIgnoreCase("modificationDate")
&& !key.equalsIgnoreCase("Producer")
&& !key.equalsIgnoreCase("Subject")
&& !key.equalsIgnoreCase("Title")
&& !key.equalsIgnoreCase("Trapped")
if (!"Author".equalsIgnoreCase(key)
&& !"CreationDate".equalsIgnoreCase(key)
&& !"Creator".equalsIgnoreCase(key)
&& !"Keywords".equalsIgnoreCase(key)
&& !"modificationDate".equalsIgnoreCase(key)
&& !"Producer".equalsIgnoreCase(key)
&& !"Subject".equalsIgnoreCase(key)
&& !"Title".equalsIgnoreCase(key)
&& !"Trapped".equalsIgnoreCase(key)
&& !key.contains("customKey")
&& !key.contains("customValue")) {
info.setCustomMetadataValue(key, entry.getValue());

View File

@ -75,7 +75,7 @@ public class OCRController {
throw new IOException("Please select at least one language.");
}
if (!ocrRenderType.equals("hocr") && !ocrRenderType.equals("sandwich")) {
if (!"hocr".equals(ocrRenderType) && !"sandwich".equals(ocrRenderType)) {
throw new IOException("ocrRenderType wrong");
}
@ -128,7 +128,7 @@ public class OCRController {
if (cleanFinal != null && cleanFinal) {
command.add("--clean-final");
}
if (ocrType != null && !ocrType.equals("")) {
if (ocrType != null && !"".equals(ocrType)) {
if ("skip-text".equals(ocrType)) {
command.add("--skip-text");
} else if ("force-ocr".equals(ocrType)) {

View File

@ -96,7 +96,7 @@ public class StampController {
graphicsState.setNonStrokingAlphaConstant(opacity);
contentStream.setGraphicsStateParameters(graphicsState);
if (watermarkType.equalsIgnoreCase("text")) {
if ("text".equalsIgnoreCase(watermarkType)) {
addTextStamp(
contentStream,
watermarkText,
@ -110,7 +110,7 @@ public class StampController {
overrideY,
marginFactor,
customColor);
} else if (watermarkType.equalsIgnoreCase("image")) {
} else if ("image".equalsIgnoreCase(watermarkType)) {
addImageStamp(
contentStream,
watermarkImage,
@ -167,7 +167,7 @@ public class StampController {
break;
}
if (!resourceDir.equals("")) {
if (!"".equals(resourceDir)) {
ClassPathResource classPathResource = new ClassPathResource(resourceDir);
String fileExtension = resourceDir.substring(resourceDir.lastIndexOf("."));
File tempFile = Files.createTempFile("NotoSansFont", fileExtension).toFile();

View File

@ -98,7 +98,7 @@ public class PipelineProcessor {
for (Resource file : outputFiles) {
boolean hasInputFileType = false;
for (String extension : inputFileTypes) {
if (extension.equals("ALL") || file.getFilename().endsWith(extension)) {
if ("ALL".equals(extension) || file.getFilename().endsWith(extension)) {
hasInputFileType = true;
MultiValueMap<String, Object> body = new LinkedMultiValueMap<>();
body.add("fileInput", file);

View File

@ -77,7 +77,7 @@ public class WatermarkController {
graphicsState.setNonStrokingAlphaConstant(opacity);
contentStream.setGraphicsStateParameters(graphicsState);
if (watermarkType.equalsIgnoreCase("text")) {
if ("text".equalsIgnoreCase(watermarkType)) {
addTextWatermark(
contentStream,
watermarkText,
@ -88,7 +88,7 @@ public class WatermarkController {
heightSpacer,
fontSize,
alphabet);
} else if (watermarkType.equalsIgnoreCase("image")) {
} else if ("image".equalsIgnoreCase(watermarkType)) {
addImageWatermark(
contentStream,
watermarkImage,
@ -141,7 +141,7 @@ public class WatermarkController {
break;
}
if (!resourceDir.equals("")) {
if (!"".equals(resourceDir)) {
ClassPathResource classPathResource = new ClassPathResource(resourceDir);
String fileExtension = resourceDir.substring(resourceDir.lastIndexOf("."));
File tempFile = Files.createTempFile("NotoSansFont", fileExtension).toFile();

View File

@ -84,7 +84,7 @@ public class MetricsController {
for (Meter meter : meterRegistry.getMeters()) {
if (meter.getId().getName().equals("http.requests")) {
String method = meter.getId().getTag("method");
if (method != null && method.equals("GET")) {
if (method != null && "GET".equals(method)) {
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
if (!endpoint.get().startsWith("/")) {
@ -129,7 +129,7 @@ public class MetricsController {
for (Meter meter : meterRegistry.getMeters()) {
if (meter.getId().getName().equals("http.requests")) {
String method = meter.getId().getTag("method");
if (method != null && method.equals("GET")) {
if (method != null && "GET".equals(method)) {
String uri = meter.getId().getTag("uri");
if (uri != null) {
double currentCount = counts.getOrDefault(uri, 0.0);
@ -197,7 +197,7 @@ public class MetricsController {
for (Meter meter : meterRegistry.getMeters()) {
if (meter.getId().getName().equals("http.requests")) {
String method = meter.getId().getTag("method");
if (method != null && method.equals("POST")) {
if (method != null && "POST".equals(method)) {
if (endpoint.isPresent() && !endpoint.get().isBlank()) {
if (!endpoint.get().startsWith("/")) {
endpoint = Optional.of("/" + endpoint.get());
@ -235,7 +235,7 @@ public class MetricsController {
for (Meter meter : meterRegistry.getMeters()) {
if (meter.getId().getName().equals("http.requests")) {
String method = meter.getId().getTag("method");
if (method != null && method.equals("POST")) {
if (method != null && "POST".equals(method)) {
String uri = meter.getId().getTag("uri");
if (uri != null) {
double currentCount = counts.getOrDefault(uri, 0.0);

View File

@ -173,7 +173,7 @@ public class FileToPdf {
// Prioritize 'index.html' if it exists, otherwise use the first .html file
for (Path htmlFile : htmlFiles) {
if (htmlFile.getFileName().toString().equals("index.html")) {
if ("index.html".equals(htmlFile.getFileName().toString())) {
return htmlFile;
}
}

View File

@ -122,7 +122,7 @@ public class GeneralUtils {
// loop through the page order array
for (String element : pageOrderArr) {
if (element.equalsIgnoreCase("all")) {
if ("all".equalsIgnoreCase(element)) {
for (int i = 0; i < totalPages; i++) {
newPageOrder.add(i);
}
@ -137,11 +137,11 @@ public class GeneralUtils {
if (element.contains("n")) {
String[] parts = element.split("n");
if (!parts[0].equals("") && parts[0] != null) {
if (!"".equals(parts[0]) && parts[0] != null) {
coefficient = Integer.parseInt(parts[0]);
coefficientExists = true;
}
if (parts.length > 1 && !parts[1].equals("") && parts[1] != null) {
if (parts.length > 1 && !"".equals(parts[1]) && parts[1] != null) {
constant = Integer.parseInt(parts[1]);
constantExists = true;
}

View File

@ -88,7 +88,7 @@ public class PDFToFile {
if (outputFiles.size() == 1) {
// Return single output file
File outputFile = outputFiles.get(0);
if (outputFormat.equals("txt:Text")) {
if ("txt:Text".equals(outputFormat)) {
outputFormat = "txt";
}
fileName = pdfBaseName + "." + outputFormat;

View File

@ -133,7 +133,7 @@ public class PdfUtils {
PDFTextStripper textStripper = new PDFTextStripper();
String pdfText = "";
if (pagesToCheck == null || pagesToCheck.equals("all")) {
if (pagesToCheck == null || "all".equals(pagesToCheck)) {
pdfText = textStripper.getText(pdfDocument);
} else {
// remove whitespaces
@ -219,8 +219,8 @@ public class PdfUtils {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
if (singleImage) {
if (imageType.toLowerCase().equals("tiff")
|| imageType.toLowerCase().equals("tif")) {
if ("tiff".equals(imageType.toLowerCase())
|| "tif".equals(imageType.toLowerCase())) {
// Write the images to the output stream as a TIFF with multiple frames
ImageWriter writer = ImageIO.getImageWritersByFormatName("tiff").next();
ImageWriteParam param = writer.getDefaultWriteParam();
@ -321,7 +321,7 @@ public class PdfUtils {
ImageProcessingUtils.convertColorType(image, colorType);
// Use JPEGFactory if it's JPEG since JPEG is lossy
PDImageXObject pdImage =
(contentType != null && contentType.equals("image/jpeg"))
(contentType != null && "image/jpeg".equals(contentType))
? JPEGFactory.createFromImage(doc, convertedImage)
: LosslessFactory.createFromImage(doc, convertedImage);
addImageToDocument(doc, pdImage, fitOption, autoRotate);