Search in sources :

Example 1 with RiderStageConnectionComparatorTimeInLead

use of ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorTimeInLead in project app by TourLive.

the class RiderStageConnectionRepository method appendTimeInLeadGroup.

@Override
public void appendTimeInLeadGroup(final RiderStageConnection riderStageConnection, int value) {
    Realm realm = Realm.getInstance(RadioTourApplication.getInstance());
    realm.executeTransaction((Realm db) -> {
        RiderStageConnection res = db.where(RiderStageConnection.class).equalTo("id", riderStageConnection.getId()).findFirst();
        res.appendTimeInLeadGroup(value);
        List<RiderStageConnection> cons = realm.copyFromRealm(db.where(RiderStageConnection.class).findAll());
        cons.sort(new RiderStageConnectionComparatorTimeInLead());
        for (int i = 0; i < cons.size(); i++) {
            db.where(RiderStageConnection.class).equalTo("id", cons.get(i).getId()).findFirst().getRiderRanking(RankingType.TIME_IN_LEAD).setRank(i + 1);
        }
    });
}
Also used : RiderStageConnection(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection) RiderStageConnectionComparatorTimeInLead(ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorTimeInLead) Realm(io.realm.Realm)

Aggregations

RiderStageConnection (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnection)1 RiderStageConnectionComparatorTimeInLead (ch.hsr.sa.radiotour.dataaccess.models.RiderStageConnectionComparatorTimeInLead)1 Realm (io.realm.Realm)1