Search in sources :

Example 1 with LinkedMap

use of org.apache.commons.collections4.map.LinkedMap in project cuba by cuba-platform.

the class CollectionDatasourceImpl method includeItemFirst.

@Override
public void includeItemFirst(T item) {
    checkNotNullArgument(item, "item is null");
    internalIncludeItem(item, () -> {
        LinkedMap tmpMap = (LinkedMap) data.clone();
        data.clear();
        data.put(item.getId(), item);
        data.putAll(tmpMap);
    });
}
Also used : LinkedMap(org.apache.commons.collections4.map.LinkedMap)

Example 2 with LinkedMap

use of org.apache.commons.collections4.map.LinkedMap in project cuba by cuba-platform.

the class GroupDelegate method doGroup.

protected void doGroup() {
    roots = new LinkedList<>();
    parents = new LinkedHashMap<>();
    children = new HashMap<>();
    groupItems = new HashMap<>();
    itemGroups = new HashMap<>();
    final Collection<K> itemIds = datasource.getItemIds();
    for (final K id : itemIds) {
        final T item = datasource.getItem(id);
        GroupInfo<MetaPropertyPath> groupInfo = groupItems(0, null, roots, item, new LinkedMap());
        if (groupInfo == null) {
            throw new IllegalStateException("Item group cannot be NULL");
        }
        List<K> itemsIds = groupItems.computeIfAbsent(groupInfo, k -> new ArrayList<>());
        itemsIds.add(id);
    }
}
Also used : MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) LinkedMap(org.apache.commons.collections4.map.LinkedMap)

Example 3 with LinkedMap

use of org.apache.commons.collections4.map.LinkedMap in project MPW by shineangelic.

the class PoolDbHelper method getLastHomeStats.

public LinkedMap<Date, HomeStats> getLastHomeStats(int limit) {
    LinkedMap<Date, HomeStats> ret = new LinkedMap<>();
    int cnt = 0;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(DataBaseContract.HomeStats_.TABLE_NAME, new String[] { DataBaseContract.HomeStats_._ID, DataBaseContract.HomeStats_.COLUMN_NAME_DTM, DataBaseContract.HomeStats_.COLUMN_NAME_JSON }, null, // String[] selectionArgs
    null, null, // HAVING
    null, DataBaseContract.HomeStats_.COLUMN_NAME_DTM + " DESC", // 2 results to do compare
    "" + limit);
    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        Gson gson = builder.create();
        do {
            try {
                HomeStats retrieved = gson.fromJson(cursor.getString(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_JSON)), HomeStats.class);
                cnt++;
                // Adding contact to list
                Date curDate = new Date(cursor.getLong(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_DTM)));
                ret.put(curDate, retrieved);
            } catch (Exception ce) {
                Log.e(TAG, "Cant read HomeStats entry: " + ce.getMessage());
            }
        } while (cursor.moveToNext());
    }
    Log.i(TAG, "SELECT DONE. WALLET HISTORY SIZE: " + cnt);
    cursor.close();
    return ret;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Gson(com.google.gson.Gson) HomeStats(it.angelic.mpw.model.jsonpojos.home.HomeStats) Cursor(android.database.Cursor) LinkedMap(org.apache.commons.collections4.map.LinkedMap) Date(java.util.Date)

Example 4 with LinkedMap

use of org.apache.commons.collections4.map.LinkedMap in project MPW by shineangelic.

the class PoolDbHelper method getLastWallets.

public LinkedMap<Date, Wallet> getLastWallets(int limit) {
    LinkedMap<Date, Wallet> ret = new LinkedMap<>();
    int cnt = 0;
    SQLiteDatabase db = this.getReadableDatabase();
    Cursor cursor = db.query(DataBaseContract.Wallet_.TABLE_NAME, new String[] { DataBaseContract.Wallet_._ID, DataBaseContract.Wallet_.COLUMN_NAME_DTM, DataBaseContract.Wallet_.COLUMN_NAME_JSON }, null, // String[] selectionArgs
    null, null, // HAVING
    null, DataBaseContract.Wallet_.COLUMN_NAME_DTM + " DESC", // 2 results to do compare
    "" + limit);
    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        Gson gson = builder.create();
        do {
            try {
                Wallet retrieved = gson.fromJson(cursor.getString(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_JSON)), Wallet.class);
                cnt++;
                // Adding contact to list
                Date curDate = new Date(cursor.getLong(cursor.getColumnIndexOrThrow(DataBaseContract.Wallet_.COLUMN_NAME_DTM)));
                ret.put(curDate, retrieved);
            } catch (Exception ce) {
                Log.e(TAG, "Cant read wallet entry: " + ce.getMessage());
            }
        } while (cursor.moveToNext());
    }
    Log.i(TAG, "SELECT DONE. WALLET HISTORY SIZE: " + cnt);
    cursor.close();
    return ret;
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Gson(com.google.gson.Gson) Cursor(android.database.Cursor) LinkedMap(org.apache.commons.collections4.map.LinkedMap) Date(java.util.Date)

Example 5 with LinkedMap

use of org.apache.commons.collections4.map.LinkedMap in project MPW by shineangelic.

the class PoolQueryGrouper method groupAvgWalletQueryResult.

public static LinkedMap<Date, Wallet> groupAvgWalletQueryResult(LinkedMap<Date, Wallet> queryResult, GranularityEnum radioCheckedId) {
    if (queryResult.isEmpty())
        return queryResult;
    LinkedMap<Date, Wallet> ret = new LinkedMap<>();
    Calendar firstDate = Calendar.getInstance();
    firstDate.setTime(queryResult.keySet().iterator().next());
    Calendar firstDateOut = Calendar.getInstance();
    firstDateOut.setTime(firstDate.getTime());
    int calendarGranularity = Calendar.DATE;
    switch(radioCheckedId) {
        case DAY:
            break;
        case HOUR:
            calendarGranularity = Calendar.HOUR;
            break;
        case MINUTE:
            calendarGranularity = Calendar.MINUTE;
            break;
    }
    firstDateOut.add(calendarGranularity, 1);
    int divideCnt = 0;
    int totCnt = 0;
    Wallet avgSet = new Wallet();
    for (Date cursorDates : queryResult.keySet()) {
        Wallet current = queryResult.get(cursorDates);
        divideCnt++;
        totCnt++;
        // aggiorna medie
        avgSet.setHashrate(avgSet.getHashrate() + current.getHashrate());
        avgSet.setWorkersOnline(avgSet.getWorkersOnline() + current.getWorkersOnline());
        avgSet.getStats().setBalance(avgSet.getStats().getBalance() + current.getStats().getBalance());
        Calendar cursorDate = Calendar.getInstance();
        cursorDate.setTime(cursorDates);
        // Log.d(TAG, "cursorDate" + cursorDate.getTime());
        if (cursorDate.after(firstDateOut) || totCnt == queryResult.values().size()) {
            // Log.d(TAG, " calcola medie " + ret.keySet().size());
            // fase finita, calcola medie e vai
            avgSet.setHashrate(avgSet.getHashrate() / divideCnt);
            avgSet.setWorkersOnline(avgSet.getWorkersOnline() / divideCnt);
            avgSet.getStats().setBalance(avgSet.getStats().getBalance() / divideCnt);
            divideCnt = 0;
            ret.put(firstDate.getTime(), avgSet);
            avgSet = new Wallet();
            firstDate.setTime(cursorDate.getTime());
            firstDateOut.setTime(firstDate.getTime());
            firstDateOut.add(calendarGranularity, 1);
        }
    }
    return ret;
}
Also used : Wallet(it.angelic.mpw.model.jsonpojos.wallet.Wallet) Calendar(java.util.Calendar) LinkedMap(org.apache.commons.collections4.map.LinkedMap) Date(java.util.Date)

Aggregations

LinkedMap (org.apache.commons.collections4.map.LinkedMap)11 Date (java.util.Date)6 Gson (com.google.gson.Gson)5 Cursor (android.database.Cursor)4 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)4 HomeStats (it.angelic.mpw.model.jsonpojos.home.HomeStats)4 Wallet (it.angelic.mpw.model.jsonpojos.wallet.Wallet)4 Calendar (java.util.Calendar)4 GsonBuilder (com.google.gson.GsonBuilder)2 MyDateTypeAdapter (it.angelic.mpw.model.MyDateTypeAdapter)2 MyTimeStampTypeAdapter (it.angelic.mpw.model.MyTimeStampTypeAdapter)2 PoolDbHelper (it.angelic.mpw.model.db.PoolDbHelper)2 NotificationManager (android.app.NotificationManager)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 NavigationView (android.support.design.widget.NavigationView)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 ActionBarDrawerToggle (android.support.v7.app.ActionBarDrawerToggle)1 Toolbar (android.support.v7.widget.Toolbar)1