io.github.robertograham.fortnite2.implementation.RawLeaderBoard Maven / Gradle / Ivy
The newest version!
package io.github.robertograham.fortnite2.implementation;
import io.github.robertograham.fortnite2.domain.LeaderBoardEntry;
import javax.json.JsonObject;
import javax.json.bind.adapter.JsonbAdapter;
import java.util.List;
import java.util.Objects;
final class RawLeaderBoard {
private final List leaderBoardEntries;
private RawLeaderBoard(final List leaderBoardEntries) {
this.leaderBoardEntries = leaderBoardEntries;
}
List leaderBoardEntries() {
return leaderBoardEntries;
}
@Override
public String toString() {
return "RawLeaderBoard{" +
"leaderBoardEntries=" + leaderBoardEntries +
'}';
}
@Override
public boolean equals(final Object object) {
if (this == object)
return true;
if (!(object instanceof RawLeaderBoard))
return false;
final var rawLeaderBoard = (RawLeaderBoard) object;
return leaderBoardEntries.equals(rawLeaderBoard.leaderBoardEntries);
}
@Override
public int hashCode() {
return Objects.hash(leaderBoardEntries);
}
enum Adapter implements JsonbAdapter {
INSTANCE;
@Override
public JsonObject adaptToJson(final RawLeaderBoard rawLeaderBoard) {
throw new UnsupportedOperationException();
}
@Override
public RawLeaderBoard adaptFromJson(final JsonObject jsonObject) {
return new RawLeaderBoard(
jsonObject.getJsonArray("entries")
.getValuesAs((final var jsonValue) -> {
final var leaderBoardEntryJsonObject = jsonValue.asJsonObject();
return new DefaultLeaderBoardEntry(
leaderBoardEntryJsonObject.getString("accountId"),
leaderBoardEntryJsonObject.getJsonNumber("value")
.longValueExact()
);
})
);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy