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);
});
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations