Search in sources :

Example 1 with DistrictRanking

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

the class DistrictTeamDeserializer method deserialize.

@Override
public DistrictRanking deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    final JsonObject object = json.getAsJsonObject();
    final DistrictRanking districtTeam = new DistrictRanking();
    if (!isNull(object.get("team_key"))) {
        districtTeam.setTeamKey(object.get("team_key").getAsString());
    }
    if (!isNull(object.get("rank"))) {
        districtTeam.setRank(object.get("rank").getAsInt());
    }
    if (!isNull(object.get("rookie_bonus"))) {
        districtTeam.setRookieBonus(object.get("rookie_bonus").getAsInt());
    }
    if (!isNull(object.get("point_total"))) {
        districtTeam.setPointTotal(object.get("point_total").getAsInt());
    }
    if (!isNull(object.get("event_points"))) {
        districtTeam.setEventPoints(context.deserialize(object.get("event_points"), new TypeToken<List<DistrictPointBreakdown>>() {
        }.getType()));
    }
    return districtTeam;
}
Also used : JsonObject(com.google.gson.JsonObject) List(java.util.List) DistrictRanking(com.thebluealliance.androidclient.models.DistrictRanking)

Example 2 with DistrictRanking

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

the class ModelInflater method inflateDistrictTeam.

public static DistrictRanking inflateDistrictTeam(Cursor data, Gson gson) {
    DistrictRanking districtTeam = new DistrictRanking();
    IDistrictEventPoints[] events = new IDistrictEventPoints[3];
    for (int i = 0; i < data.getColumnCount(); i++) {
        switch(data.getColumnName(i)) {
            case DistrictTeamsTable.KEY:
                districtTeam.setKey(data.getString(i));
                break;
            case DistrictTeamsTable.TEAM_KEY:
                districtTeam.setTeamKey(data.getString(i));
                break;
            case DistrictTeamsTable.DISTRICT_KEY:
                districtTeam.setDistrictKey(data.getString(i));
                break;
            case DistrictTeamsTable.RANK:
                districtTeam.setRank(data.getInt(i));
                break;
            case DistrictTeamsTable.EVENT1_POINTS:
                events[0] = gson.fromJson(data.getString(i), IDistrictEventPoints.class);
                break;
            case DistrictTeamsTable.EVENT2_POINTS:
                events[1] = gson.fromJson(data.getString(i), IDistrictEventPoints.class);
                break;
            case DistrictTeamsTable.CMP_POINTS:
                events[2] = gson.fromJson(data.getString(i), IDistrictEventPoints.class);
                break;
            case DistrictTeamsTable.ROOKIE_POINTS:
                districtTeam.setRookieBonus(data.getInt(i));
                break;
            case DistrictTeamsTable.TOTAL_POINTS:
                districtTeam.setPointTotal(data.getInt(i));
                break;
            case DistrictTeamsTable.LAST_MODIFIED:
                districtTeam.setLastModified(data.getLong(i));
                break;
            default:
        }
    }
    List<IDistrictEventPoints> eventPoints = new ArrayList<>();
    for (IDistrictEventPoints event : events) {
        if (event == null)
            break;
        eventPoints.add(event);
    }
    districtTeam.setEventPoints(eventPoints);
    return districtTeam;
}
Also used : IDistrictEventPoints(com.thebluealliance.api.model.IDistrictEventPoints) ArrayList(java.util.ArrayList) DistrictRanking(com.thebluealliance.androidclient.models.DistrictRanking)

Example 3 with DistrictRanking

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

the class DistrictTeamListWriterTest method testDistrictTeamListWriter.

@Test
public void testDistrictTeamListWriter() {
    mWriter.write(mDistrictTeams, 0L);
    SQLiteDatabase db = mDb.getWritableDatabase();
    for (DistrictRanking districtTeam : mDistrictTeams) {
        verify(db).insert(Database.TABLE_DISTRICTTEAMS, null, districtTeam.getParams(mGson));
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) DistrictRanking(com.thebluealliance.androidclient.models.DistrictRanking) Test(org.junit.Test)

Example 4 with DistrictRanking

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

the class DistrictTeamsTableTest method testUpdate.

@Test
public void testUpdate() {
    DistrictRanking result = DbTableTestDriver.testUpdate(mTable, mDistrictTeams.get(0), dt -> dt.setRank(1124), mGson);
    assertNotNull(result);
    assertEquals(1124, result.getRank().intValue());
}
Also used : DistrictRanking(com.thebluealliance.androidclient.models.DistrictRanking) Test(org.junit.Test)

Example 5 with DistrictRanking

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

the class DistrictTeamExtractorTest method testDistrictTeamExtractor.

@Test
public void testDistrictTeamExtractor() {
    DistrictRanking extracted = mExtractor.call(mDistrictTeams);
    assertNotNull(extracted);
    assertEquals(extracted.getTeamKey(), mSearchTeamKey);
}
Also used : DistrictRanking(com.thebluealliance.androidclient.models.DistrictRanking) Test(org.junit.Test)

Aggregations

DistrictRanking (com.thebluealliance.androidclient.models.DistrictRanking)8 Test (org.junit.Test)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 JsonObject (com.google.gson.JsonObject)1 DistrictTeamListElement (com.thebluealliance.androidclient.listitems.DistrictTeamListElement)1 Team (com.thebluealliance.androidclient.models.Team)1 IDistrictEventPoints (com.thebluealliance.api.model.IDistrictEventPoints)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1