diff options
author | Cow <cow@volloeko.de> | 2020-07-05 05:42:45 +0200 |
---|---|---|
committer | Cow <cow@volloeko.de> | 2020-07-05 05:42:45 +0200 |
commit | 1b446698398c648b38311975a6cfd54859ea5cfe (patch) | |
tree | 521ecc4ce9ad968281094eb8c5453dca606931e3 /src/main/java/eu/olli/cowlection/data/LogEntry.java | |
parent | edaca1fd41a612c71c526ceb20b89c5dec2d81b3 (diff) | |
download | Cowlection-1b446698398c648b38311975a6cfd54859ea5cfe.tar.gz Cowlection-1b446698398c648b38311975a6cfd54859ea5cfe.tar.bz2 Cowlection-1b446698398c648b38311975a6cfd54859ea5cfe.zip |
Renamed mod to Cowlection
Bumped version to 1.8.9-0.7.0
Diffstat (limited to 'src/main/java/eu/olli/cowlection/data/LogEntry.java')
-rw-r--r-- | src/main/java/eu/olli/cowlection/data/LogEntry.java | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/src/main/java/eu/olli/cowlection/data/LogEntry.java b/src/main/java/eu/olli/cowlection/data/LogEntry.java new file mode 100644 index 0000000..2ccca3d --- /dev/null +++ b/src/main/java/eu/olli/cowlection/data/LogEntry.java @@ -0,0 +1,82 @@ +package eu.olli.cowlection.data; + +import net.minecraft.util.EnumChatFormatting; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import java.nio.file.Path; +import java.time.LocalDateTime; +import java.util.regex.Pattern; + +public class LogEntry { + private static final Pattern UTF_PARAGRAPH_SYMBOL = Pattern.compile("§"); + private LocalDateTime time; + private Path filePath; + private String message; + + public LogEntry(LocalDateTime time, Path filePath, String logEntry) { + this.time = time; + this.filePath = filePath; + this.message = logEntry; + } + + public LogEntry(String message) { + this.message = message; + } + + public LocalDateTime getTime() { + return time; + } + + public Path getFilePath() { + return filePath; + } + + public String getMessage() { + return message; + } + + public void addLogLine(String logLine) { + message += "\n" + logLine; + } + + public void removeFormatting() { + this.message = EnumChatFormatting.getTextWithoutFormattingCodes(message); + } + + public void fixWeirdCharacters() { + if (message.contains("§")) { + message = UTF_PARAGRAPH_SYMBOL.matcher(message).replaceAll("§"); + } + } + + /** + * Is this log entry a 'real' log entry or just an error message from the search process? + * + * @return true if error message, otherwise false + */ + public boolean isError() { + return time == null && filePath == null; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + LogEntry logEntry = (LogEntry) o; + return new EqualsBuilder() + .append(time, logEntry.time) + .append(filePath, logEntry.filePath) + .append(message, logEntry.message) + .isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder(17, 37) + .append(time) + .append(filePath) + .append(message) + .toHashCode(); + } +} |