(SO says it won't improve performance though)
return nodes.size();
}
- public void remove(int index) {
- nodes.remove(index);
+ public void trim() {
+ if (nodes.size() > Common.BUCKET_SIZE)
+ nodes.subList(nodes.size() - Common.BUCKET_SIZE, nodes.size()).clear();
}
public void add(Contact contact) {
}
Collections.sort(nodes);
//Trim the list
- while (answer.size() > Common.BUCKET_SIZE) {
- answer.remove(answer.size() - 1);
- }
+ answer.trim();
+
return nbAdded;
}
//We sort the list
Collections.sort(answer.getNodes());
//We trim the list
- while (answer.size() > Common.BUCKET_SIZE) {
- answer.remove(answer.size() - 1); //TODO: Not the best thing.
- }
+ answer.trim();
+
return answer;
}