I want to build a HashMap<Integer,Linkedlist<long[]>>
from another nested hashmap.
I have some doubts about hashmap's merge function: the function seems to accept just bi-functions which arguments are of the same type.
This implies that when I use the following approach to build this hashmap... (using a function that takes two argument of different type)
private static long[] map2longarray(Int2IntMap map){
//convert hashmap into a long array
}
private static void writeQueryTrace(Long2ObjectOpenHashMap<Int2ObjectOpenHashMap<Int2IntLinkedOpenHashMap>> fqt){
Int2ObjectOpenHashMap<LinkedList<long[]>> toPrint = new Int2ObjectOpenHashMap<>();
Int2ObjectOpenHashMap<Int2IntLinkedOpenHashMap> pairQID;
Int2IntLinkedOpenHashMap QIdDocId;
for(long pair: fqt.keySet()){
pairQID = fqt.get(pair);
for(int qID: pairQID.keySet()) {
toPrint.merge(qID, map2longarray(pairQID.get(qID)), UnigramQualityModel::mergeList); //<-------ERROR HERE!!!!
}
}
}
private static LinkedList<long[]> mergeList(long [] a, LinkedList<long[]> longs) {
longs.addLast(a);
return longs;
}
...I get the following error:
Invalid method reference: LinkedList<long[]> cannot be converted to long[]
At this point I modified the map2array function wrapping the long[] array into a LinkedList:
private static LinkedList<long[]> map2longarray(Int2IntMap map){
//convert the map into a long array but WRAPPING IT IN A LINKED LIST
}
private static void writeQueryTrace(Long2ObjectOpenHashMap<Int2ObjectOpenHashMap<Int2IntLinkedOpenHashMap>> fqt){
//same function as before
}
private static LinkedList<long[]> mergeList(LinkedList<long[]> a, LinkedList<long[]> longs) {
longs.addLast(a.getFirst());
return longs;
}
While this version works, at each operation it creates a linked list which is both unnecessary and inefficient: is there a way to avoid the creation of the linked list and stick with the original approach?