From 8a7ee72dd9a769d04258182354f8fc6d65373e61 Mon Sep 17 00:00:00 2001 From: Ulli Hafner Date: Wed, 11 Sep 2024 15:04:23 +0200 Subject: [PATCH] Use new equals template. --- .../java/edu/hm/hafner/util/FilteredLog.java | 32 ++++++------------- .../java/edu/hm/hafner/util/LineRange.java | 21 ++++-------- .../java/edu/hm/hafner/util/PathUtil.java | 2 +- 3 files changed, 17 insertions(+), 38 deletions(-) diff --git a/src/main/java/edu/hm/hafner/util/FilteredLog.java b/src/main/java/edu/hm/hafner/util/FilteredLog.java index 98f10b31..5b3afc42 100644 --- a/src/main/java/edu/hm/hafner/util/FilteredLog.java +++ b/src/main/java/edu/hm/hafner/util/FilteredLog.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Objects; import java.util.concurrent.locks.ReentrantLock; @@ -220,7 +221,7 @@ public List getErrorMessages() { } messages.addAll(errorMessages); if (lines > maxLines) { - messages.add(String.format(" ... skipped logging of %d additional errors ...", lines - maxLines)); + messages.add(String.format(Locale.ENGLISH, " ... skipped logging of %d additional errors ...", lines - maxLines)); } return messages; } @@ -269,31 +270,16 @@ public boolean equals(final Object o) { if (o == null || getClass() != o.getClass()) { return false; } - - FilteredLog log = (FilteredLog) o; - - if (maxLines != log.maxLines) { - return false; - } - if (lines != log.lines) { - return false; - } - if (!Objects.equals(title, log.title)) { - return false; - } - if (!infoMessages.equals(log.infoMessages)) { - return false; - } - return errorMessages.equals(log.errorMessages); + var that = (FilteredLog) o; + return maxLines == that.maxLines + && lines == that.lines + && Objects.equals(title, that.title) + && Objects.equals(infoMessages, that.infoMessages) + && Objects.equals(errorMessages, that.errorMessages); } @Override public int hashCode() { - int result = title != null ? title.hashCode() : 0; - result = 31 * result + maxLines; - result = 31 * result + lines; - result = 31 * result + infoMessages.hashCode(); - result = 31 * result + errorMessages.hashCode(); - return result; + return Objects.hash(title, maxLines, lines, infoMessages, errorMessages); } } diff --git a/src/main/java/edu/hm/hafner/util/LineRange.java b/src/main/java/edu/hm/hafner/util/LineRange.java index 16fea08b..67e81136 100644 --- a/src/main/java/edu/hm/hafner/util/LineRange.java +++ b/src/main/java/edu/hm/hafner/util/LineRange.java @@ -1,11 +1,11 @@ package edu.hm.hafner.util; import java.io.Serializable; +import java.util.Locale; import java.util.NavigableSet; +import java.util.Objects; import java.util.TreeSet; -import edu.umd.cs.findbugs.annotations.CheckForNull; - /** * A line range in a source file is defined by its first and last line. * @@ -101,31 +101,24 @@ public boolean isSingleLine() { } @Override - public boolean equals(@CheckForNull final Object o) { + public boolean equals(final Object o) { if (this == o) { return true; } if (o == null || getClass() != o.getClass()) { return false; } - - LineRange lineRange = (LineRange) o; - - if (start != lineRange.start) { - return false; - } - return end == lineRange.end; + var lineRange = (LineRange) o; + return start == lineRange.start && end == lineRange.end; } @Override public int hashCode() { - int result = start; - result = 31 * result + end; - return result; + return Objects.hash(start, end); } @Override public String toString() { - return String.format("[%d-%d]", start, end); + return String.format(Locale.ENGLISH, "[%d-%d]", start, end); } } diff --git a/src/main/java/edu/hm/hafner/util/PathUtil.java b/src/main/java/edu/hm/hafner/util/PathUtil.java index 9ccadb18..5e6f3242 100644 --- a/src/main/java/edu/hm/hafner/util/PathUtil.java +++ b/src/main/java/edu/hm/hafner/util/PathUtil.java @@ -263,7 +263,7 @@ public String createAbsolutePath(@CheckForNull final String directory, final Str */ public boolean isAbsolute(final String fileName) { try { - URI uri = new URI(fileName); + var uri = new URI(fileName); if (uri.isAbsolute()) { return true; }