在我的SQLite中,实际上有375个数据,但是当我尝试迭代该数据并将其成功分配给hashmap时,仅分配了226个数据,下面的代码有什么问题吗?
class PublishersState {
val publishersList = Collections.synchronizedList<Flux<String>>(mutableListOf()) // adding sync list for storing publishers
val outputProcessor = DirectProcessor.create<String>()
fun addNewPublisher(publisher: Flux<String>) {
val cached = publisher.cache(1) // caching the last item for a new publisher
publishersList.add(cached)
cached.subscribe(outputProcessor)
}
fun getAllPublishersState(): Flux<String> = publishersList
.toFlux()
.reduce(outputProcessor as Flux<String>) { acc, flux -> acc.mergeWith(flux.take(1)) } // merging the last item of each publisher with outputProcessor
.flatMapMany { it }
}
答案 0 :(得分:0)
您有多个条目,其中一个KEY_LANG
。您可以在地图值中存储STRING
而不是一个STRING
的列表
public static HashMap<String, ArrayList<String>> getLanguage() {
HashMap<String, ArrayList<String>> hashMap = new HashMap<>();
Cursor cursor = database.query(DB_TABLE,
null,
null,
null,
null,
null,
_ID + " ASC",
null);
//cursor.moveToFirst();
System.out.println("Cursor count" + cursor.getCount());
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
String key = cursor.getString(cursor.getColumnIndex(KEY_LANG));
String value = cursor.getString(cursor.getColumnIndex(STRING));
if (hashMap.containsKey(key)) {
hashMap.get(key).add(value);
} else {
ArrayList<String> list = new ArrayList<>();
list.add(value);
hashMap.put(key, list);
}
}
return hashMap;
}