diff --git a/src/main/java/world/bentobox/bentobox/api/logs/LogEntry.java b/src/main/java/world/bentobox/bentobox/api/logs/LogEntry.java index 0109b938a..f637693b8 100644 --- a/src/main/java/world/bentobox/bentobox/api/logs/LogEntry.java +++ b/src/main/java/world/bentobox/bentobox/api/logs/LogEntry.java @@ -1,5 +1,7 @@ package world.bentobox.bentobox.api.logs; +import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; /** @@ -11,20 +13,14 @@ import java.util.Map; * @author Poslovitch */ public class LogEntry { - private long timestamp; - private String type; - private Map data; + private final long timestamp; + private final String type; + private final Map data; - public LogEntry(String type, Map data) { - this.timestamp = System.currentTimeMillis(); - this.type = type; - this.data = data; - } - - public LogEntry(long timestamp, String type, Map data) { - this.timestamp = timestamp; - this.type = type; - this.data = data; + private LogEntry(Builder builder) { + this.timestamp = builder.timestamp; + this.type = builder.type; + this.data = builder.data; } public long getTimestamp() { @@ -38,4 +34,41 @@ public class LogEntry { public Map getData() { return data; } + + public static class Builder { + private long timestamp; + private String type; + private Map data; + + public Builder(String type) { + this.timestamp = System.currentTimeMillis(); + this.type = type.toUpperCase(Locale.ENGLISH); + this.data = new LinkedHashMap<>(); + } + + public Builder timestamp(long timestamp) { + this.timestamp = timestamp; + return this; + } + + public Builder data(Map data) { + this.data = data; + return this; + } + + /** + * Puts this key and this value in the currently existing data map. + * @param key key to set + * @param value value to set + * @return the Builder instance + */ + public Builder data(String key, Object value) { + this.data.put(key, value); + return this; + } + + public LogEntry build() { + return new LogEntry(this); + } + } } diff --git a/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java b/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java index 624ade9c5..d6af820b6 100644 --- a/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java +++ b/src/main/java/world/bentobox/bentobox/database/objects/adapters/LogEntryListAdapter.java @@ -44,7 +44,7 @@ public class LogEntryListAdapter implements AdapterInterface, Lis String type = (String) entry.get(TYPE); Map data = (Map) entry.get(DATA); - result.add(new LogEntry(timestamp, type, data)); + result.add(new LogEntry.Builder(type).timestamp(timestamp).data(data).build()); } return result;