Skip to content

Instantly share code, notes, and snippets.

@skiwi2
Created January 12, 2015 21:23
Show Gist options
  • Save skiwi2/d64cd2750fe29c83dd53 to your computer and use it in GitHub Desktop.
Save skiwi2/d64cd2750fe29c83dd53 to your computer and use it in GitHub Desktop.
package com.github.skiwi2.hearthmonitor.logapi.power;
import com.github.skiwi2.hearthmonitor.logapi.LogEntry;
import com.github.skiwi2.hearthmonitor.logapi.LogObject;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
/**
* @author Frank van Heeswijk
*/
public class CreateGameLogEntry implements LogEntry {
private final GameEntityLogEntry gameEntityLogEntry;
private final Set<PlayerLogEntry> playerLogEntries;
private CreateGameLogEntry(final Builder builder) {
this.gameEntityLogEntry = Objects.requireNonNull(builder.gameEntityLogEntry, "builder.gameEntityLogEntry");
this.playerLogEntries = Objects.requireNonNull(builder.playerLogEntries, "builder.playerLogEntries");
}
public GameEntityLogEntry getGameEntityLogEntry() {
return gameEntityLogEntry;
}
public Set<PlayerLogEntry> getPlayerLogEntries() {
return new HashSet<>(playerLogEntries);
}
public static class Builder {
private GameEntityLogEntry gameEntityLogEntry;
private Set<PlayerLogEntry> playerLogEntries = new HashSet<>();
public Builder gameEntityLogEntry(final GameEntityLogEntry gameEntityLogEntry) {
this.gameEntityLogEntry = Objects.requireNonNull(gameEntityLogEntry, "gameEntityLogEntry");
return this;
}
public Builder addPlayerLogEntry(final PlayerLogEntry playerLogEntry) {
Objects.requireNonNull(playerLogEntry, "playerLogEntry");
this.playerLogEntries.add(playerLogEntry);
return this;
}
public CreateGameLogEntry build() {
return new CreateGameLogEntry(this);
}
}
public static class GameEntityLogEntry implements LogEntry {
private final String entityId;
private final Map<String, String> tagValues;
private GameEntityLogEntry(final Builder builder) {
this.entityId = Objects.requireNonNull(builder.entityId, "builder.entityId");
this.tagValues = Objects.requireNonNull(builder.tagValues, "builder.tagValues");
}
public String getEntityId() {
return entityId;
}
public String getTagValue(final String tag) {
return tagValues.get(tag);
}
public Map<String, String> getTagValues() {
return new HashMap<>(tagValues);
}
public static class Builder {
private String entityId;
private Map<String, String> tagValues = new HashMap<>();
public Builder entityId(final String entityId) {
this.entityId = Objects.requireNonNull(entityId, "entityId");
return this;
}
public Builder addTagValuePair(final String tag, final String value) {
Objects.requireNonNull(tag, "tag");
Objects.requireNonNull(value, "value");
tagValues.put(tag, value);
return this;
}
public GameEntityLogEntry build() {
return new GameEntityLogEntry(this);
}
}
}
public static class PlayerLogEntry implements LogEntry {
private final String entityId;
private final String playerId;
private final GameAccountId gameAccountId;
private final Map<String, String> tagValues;
private PlayerLogEntry(final Builder builder) {
this.entityId = Objects.requireNonNull(builder.entityId, "builder.entityId");
this.playerId = Objects.requireNonNull(builder.playerId, "builder.playerId");
this.gameAccountId = Objects.requireNonNull(builder.gameAccountId, "builder.gameAccountId");
this.tagValues = Objects.requireNonNull(builder.tagValues, "builder.tagValues");
}
public String getEntityId() {
return entityId;
}
public String getPlayerId() {
return playerId;
}
public GameAccountId getGameAccountId() {
return gameAccountId;
}
public String getTagValue(final String tag) {
return tagValues.get(tag);
}
public Map<String, String> getTagValues() {
return new HashMap<>(tagValues);
}
public static class Builder {
private String entityId;
private String playerId;
private GameAccountId gameAccountId;
private Map<String, String> tagValues = new HashMap<>();
public Builder entityId(final String entityId) {
this.entityId = Objects.requireNonNull(entityId, "entityId");
return this;
}
public Builder playerId(final String playerId) {
this.playerId = Objects.requireNonNull(playerId, "playerId");
return this;
}
public Builder gameAccountId(final GameAccountId gameAccountId) {
this.gameAccountId = Objects.requireNonNull(gameAccountId, "gameAccountId");
return this;
}
public Builder addTagValuePair(final String tag, final String value) {
Objects.requireNonNull(tag, "tag");
Objects.requireNonNull(value, "value");
tagValues.put(tag, value);
return this;
}
public PlayerLogEntry build() {
return new PlayerLogEntry(this);
}
}
public static class GameAccountId implements LogObject {
private final String hi;
private final String lo;
private GameAccountId(final Builder builder) {
this.hi = Objects.requireNonNull(builder.hi, "builder.hi");
this.lo = Objects.requireNonNull(builder.lo, "builder.lo");
}
public String getHi() {
return hi;
}
public String getLo() {
return lo;
}
public static class Builder {
private String hi;
private String lo;
public Builder hi(final String hi) {
this.hi = Objects.requireNonNull(hi, "hi");
return this;
}
public Builder lo(final String hi) {
this.lo = Objects.requireNonNull(lo, "lo");
return this;
}
public GameAccountId build() {
return new GameAccountId(this);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment