Skip to content

Commit

Permalink
Use new equals template.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 11, 2024
1 parent 41e0a16 commit 8a7ee72
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 38 deletions.
32 changes: 9 additions & 23 deletions src/main/java/edu/hm/hafner/util/FilteredLog.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -220,7 +221,7 @@ public List<String> 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;
}
Expand Down Expand Up @@ -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);
}
}
21 changes: 7 additions & 14 deletions src/main/java/edu/hm/hafner/util/LineRange.java
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion src/main/java/edu/hm/hafner/util/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 8a7ee72

Please sign in to comment.