how to update the order of java priority queue after changing its elements value.
i need it in path choosing where the child path cost depend on the current one
Queue<String> lowerCostPath = new PriorityQueue<>();
lowerCostPath.add(path1);
lowerCostPath.add(path2);
lowerCostPath.add(path3);
lowerCostPath.add(path4);
lowerCostPath.add(path5);
while(!lowerCostPath.isEmpty()){
String current = lowerCostPath.poll();
if(pathType(current)=="water"){
lowerTheCost(current);
String[] changed = updateRelatedPathes(current);
for(String s : changed){
//lowerCostPath.changed(s); //how to inform queue about change
}
}
}
i searched the answers and one of them suggest to use observer pattern to inform the priority queue that a change occurred and it will update the order of its elements,
is it possible, if so how to do it, if not what was he meaning.
this is the link to the answer https://stackoverflow.com/a/715050/5418289