I have a list of 2D points (a custom Node class). I would like to pick a Node and say "Ehy, the 10 closest node in my list are those ten"
Now, what's the problem: I would like to make something like:
ArrayList<Node> nodes; //list of nodes
ArrayList<Node> topten; //list of nearest nodes
Node currentNode; //the current point
for (Node x : nodes){
if (x.distance(currentNode) < (topten.THE_FURTHER_POINT()).distance(currentNode))
topten.ADD(x);
}
I would like to know if there is already a Collection which have those pseudo-methods (THE_FURTHER_POINT and ADD) Those two methods should work like this:
THE_FURTHER_POINT: return the further point. The collection should be fixed-length, so this method should always return the last element (if I have 8 elements inside the topten, i should receive the node with index 7, if I have 10 elements I should receive the node with index 9)
ADD: everytime an elements is added, if the collection is full the latest elements get eliminated. The collection should be always ordinate, and this operation should be as quick as possibile (if I have 8 elements in the topten, I will end up with 9 elements after the add. if I have 10 elements, I will end up with 10 elements after the add)
Thank you a lot!