I have a hashmap
with a queue object and I want to peek different objects in the different queue in the order they are located in queue each time i peek an object, typically consumer-producer problem;
public class MainQueue {
public static Map<Integer, SingleQueue> list = new ConcurrentHashMap<>();
public MainQueue() {
}
public Map getQueue() {
return this.list;
}
public void addToMainQueue(SendObject sfo) {
int ohashcode = sfo.hashCode();
if (!list.containsKey(ohashcode)) {
list.put(ohashcode, new SingleQueue());
list.get(ohashcode).addQueue(sfo);
} else {
list.get(ohashcode).addQueue(sfo);
}
}
public SendObject getFromQueue() {
???
return TempFax;
}
}
---------HashMap-------------
423532,queue1:{1,2,3,4,5,6,7,8,9}
564898,queue2:{a,b,c,d,e}
039894,queue3:{x,y,z}
When I call getFromQueue function, it should return '1' after I call, return 'a' after I call, return 'x'
finally= 1,a,x,2,b,y,3,c,z,4,d,5,e,6,7,8,9
How can I do this?
Based on your question you are interested in retrieving those elements in a FIFO order and you need some way to group them into hashcodes.
I suggest adding those SendObject into a single queue like LinkedList<SendObject>, this way you can poll() those elements one by one.
If you need to have some way to group different items into categories (or hashcodes in your case), you can add a Category field for example in SendObject so you can keep track of those.