Search in sources :

Example 1 with RankingItem

use of com.thebluealliance.androidclient.models.RankingItem in project the-blue-alliance-android by the-blue-alliance.

the class TeamAtEventStatusDeserializer method deserialize.

@Override
public TeamAtEventStatus deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject data = json.getAsJsonObject();
    TeamAtEventStatus status = new TeamAtEventStatus();
    if (!isNull(data.get("alliance"))) {
        JsonObject allianceJson = data.getAsJsonObject("alliance");
        TeamAtEventStatus.TeamAtEventAlliance alliance = new TeamAtEventStatus.TeamAtEventAlliance();
        alliance.setName(allianceJson.get("name").getAsString());
        alliance.setNumber(allianceJson.get("number").getAsInt());
        alliance.setPick(allianceJson.get("pick").getAsInt());
        if (!isNull(allianceJson.get("backup"))) {
            alliance.setBackup(context.deserialize(allianceJson.get("backup"), IAllianceBackup.class));
        }
        status.setAlliance(alliance);
    }
    if (!isNull(data.get("alliance_status_str"))) {
        status.setAllianceStatusStr(data.get("alliance_status_str").getAsString());
    }
    if (!isNull(data.get("overall_status_str"))) {
        status.setOverallStatusStr(data.get("overall_status_str").getAsString());
    }
    if (!isNull(data.get("playoff_status_str"))) {
        status.setPlayoffStatusStr(data.get("playoff_status_str").getAsString());
    }
    if (!isNull(data.get("playoff"))) {
        JsonObject playoffJson = data.getAsJsonObject("playoff");
        TeamAtEventPlayoff playoff = context.deserialize(playoffJson, TeamAtEventPlayoff.class);
        status.setPlayoff(playoff);
    }
    if (!isNull(data.get("qual"))) {
        JsonObject qualJson = data.getAsJsonObject("qual");
        TeamAtEventStatus.TeamAtEventQual qual = new TeamAtEventStatus.TeamAtEventQual();
        RankingItem teamRank = context.deserialize(qualJson.get("ranking"), RankingItem.class);
        List<IRankingSortOrder> sortOrders = context.deserialize(qualJson.get("sort_order_info"), new TypeToken<List<IRankingSortOrder>>() {
        }.getType());
        qual.setRanking(teamRank);
        qual.setSortOrderInfo(sortOrders);
        qual.setNumTeams(qualJson.get("num_teams").getAsInt());
        qual.setStatus(qualJson.get("status").getAsString());
        status.setQual(qual);
    }
    return status;
}
Also used : IAllianceBackup(com.thebluealliance.api.model.IAllianceBackup) RankingItem(com.thebluealliance.androidclient.models.RankingItem) TypeToken(com.google.gson.reflect.TypeToken) TeamAtEventPlayoff(com.thebluealliance.androidclient.models.TeamAtEventStatus.TeamAtEventPlayoff) ITeamAtEventPlayoff(com.thebluealliance.api.model.ITeamAtEventPlayoff) IRankingSortOrder(com.thebluealliance.api.model.IRankingSortOrder) TeamAtEventStatus(com.thebluealliance.androidclient.models.TeamAtEventStatus) JsonObject(com.google.gson.JsonObject)

Example 2 with RankingItem

use of com.thebluealliance.androidclient.models.RankingItem in project the-blue-alliance-android by the-blue-alliance.

the class RankingItemDeserializer method serialize.

@Override
public JsonElement serialize(RankingItem src, Type typeOfSrc, JsonSerializationContext context) {
    JsonObject out = new JsonObject();
    out.add("dq", new JsonPrimitive(src.getDq()));
    out.add("matches_played", new JsonPrimitive(src.getMatchesPlayed()));
    out.add("rank", new JsonPrimitive(src.getRank()));
    out.add("team_key", new JsonPrimitive(src.getTeamKey()));
    if (src.getQualAverage() != null) {
        out.add("qual_average", new JsonPrimitive(src.getQualAverage()));
    } else {
        out.add("qual_average", JsonNull.INSTANCE);
    }
    if (src.getRecord() != null) {
        JsonElement record = context.serialize(src.getRecord(), RankingItem.TeamRecord.class);
        out.add("record", record);
    } else {
        out.add("record", JsonNull.INSTANCE);
    }
    JsonArray sortOrders = new JsonArray();
    for (int i = 0; i < src.getSortOrders().size(); i++) {
        sortOrders.add(src.getSortOrders().get(i));
    }
    out.add("sort_orders", sortOrders);
    return out;
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) RankingItem(com.thebluealliance.androidclient.models.RankingItem) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject)

Example 3 with RankingItem

use of com.thebluealliance.androidclient.models.RankingItem in project the-blue-alliance-android by the-blue-alliance.

the class RankingItemDeserializer method deserialize.

@Override
public RankingItem deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject data = json.getAsJsonObject();
    RankingItem rankItem = new RankingItem();
    rankItem.setDq(!isNull(data.get("dq")) ? data.get("dq").getAsInt() : 0);
    rankItem.setMatchesPlayed(data.get("matches_played").getAsInt());
    if (!isNull(data.get("rank"))) {
        rankItem.setRank(data.get("rank").getAsInt());
    } else {
        rankItem.setRank(-1);
    }
    rankItem.setTeamKey(data.get("team_key").getAsString());
    if (!isNull(data.get("qual_average"))) {
        rankItem.setQualAverage(data.get("qual_average").getAsDouble());
    }
    if (!isNull(data.get("record"))) {
        rankItem.setRecord(context.deserialize(data.get("record"), ITeamRecord.class));
    }
    List<Double> sortOrders = new ArrayList<>();
    if (!isNull(data.get("sort_orders"))) {
        JsonArray sortOrderJson = data.get("sort_orders").getAsJsonArray();
        for (int i = 0; i < sortOrderJson.size(); i++) {
            sortOrders.add(sortOrderJson.get(i).getAsDouble());
        }
    }
    rankItem.setSortOrders(sortOrders);
    List<Double> extraStats = new ArrayList<>();
    if (!isNull(data.get("extra_stats"))) {
        JsonArray extraStatsJson = data.get("extra_stats").getAsJsonArray();
        for (int i = 0; i < extraStatsJson.size(); i++) {
            extraStats.add(extraStatsJson.get(i).getAsDouble());
        }
    }
    rankItem.setExtraStats(extraStats);
    return rankItem;
}
Also used : JsonArray(com.google.gson.JsonArray) ITeamRecord(com.thebluealliance.api.model.ITeamRecord) RankingItem(com.thebluealliance.androidclient.models.RankingItem) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Aggregations

JsonObject (com.google.gson.JsonObject)3 RankingItem (com.thebluealliance.androidclient.models.RankingItem)3 JsonArray (com.google.gson.JsonArray)2 JsonElement (com.google.gson.JsonElement)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 TypeToken (com.google.gson.reflect.TypeToken)1 TeamAtEventStatus (com.thebluealliance.androidclient.models.TeamAtEventStatus)1 TeamAtEventPlayoff (com.thebluealliance.androidclient.models.TeamAtEventStatus.TeamAtEventPlayoff)1 IAllianceBackup (com.thebluealliance.api.model.IAllianceBackup)1 IRankingSortOrder (com.thebluealliance.api.model.IRankingSortOrder)1 ITeamAtEventPlayoff (com.thebluealliance.api.model.ITeamAtEventPlayoff)1 ITeamRecord (com.thebluealliance.api.model.ITeamRecord)1 ArrayList (java.util.ArrayList)1