private DataNodeIdentifier pickHeaviestLoad(DataNodeIdentifier otherNode) { DataNodeIdentifier replacementNode = null; PriorityBlockingQueue<DataNodeStatusPair> invertedStatusQueue = new PriorityBlockingQueue<DataNodeStatusPair>( datanodeStatuses.size(), new Comparator<DataNodeStatusPair>() { public int compare(DataNodeStatusPair a, DataNodeStatusPair b) { return -1 * a.compareTo(b); } }); for (DataNodeStatusPair each : datanodeStatuses) { invertedStatusQueue.put(each); } while (replacementNode == null) { DataNodeStatusPair next = invertedStatusQueue.poll(); DataNodeIdentifier nextId = next.getIdentifier(); if (!nextId.equals(otherNode)) { replacementNode = nextId; } } return replacementNode; }