int index = Collections.binarySearch(candidates, expandedPath, mpc);
int index = Collections.<MovePath>binarySearch(candidates, expandedPath, mpc);
    private void notSoLazyPathfinder(final Coords dest, final int type, final int timeLimit) {        long endTime = System.currentTimeMillis() + timeLimit;        int step = type;        if (step != MovePath.STEP_BACKWARDS) {            step = MovePath.STEP_FORWARDS;        }        MovePathComparator mpc = new MovePathComparator(dest, step == MovePath.STEP_BACKWARDS);        MovePath bestPath = (MovePath) this.clone();        HashMap discovered = new HashMap();        discovered.put(bestPath.getKey(), bestPath);        ArrayList candidates = new ArrayList();        candidates.add(bestPath);        boolean keepLooping = this.getFinalCoords().distance(dest) > 1;        int loopcount = 0;        while (candidates.size() > 0 && keepLooping) {            MovePath candidatePath = (MovePath) candidates.remove(0);            Coords startingPos = candidatePath.getFinalCoords();            int startingElev = candidatePath.getFinalElevation();                        if (candidatePath.getFinalCoords().distance(dest) == 1) {                bestPath = candidatePath;                keepLooping = false;                break;            }            Iterator adjacent = candidatePath.getNextMoves(step == STEP_BACKWARDS, step == STEP_FORWARDS).iterator();            while (adjacent.hasNext()) {                MovePath expandedPath = (MovePath) adjacent.next();                if (expandedPath.getLastStep().isMovementPossible(this.game, startingPos, startingElev)) {                    MovePath found = (MovePath) discovered.get(expandedPath.getKey());                    if (found != null && mpc.compare(found, expandedPath) <= 0) {                        continue;                    }                    int index = Collections.binarySearch(candidates, expandedPath, mpc);                    if (index < 0) {                        index = -index - 1;                    }                    candidates.add(index, expandedPath);                    discovered.put(expandedPath.getKey(), expandedPath);                    if (candidates.size() > 100) {                        candidates.remove(candidates.size() - 1);                    }                }            }            loopcount++;            if (loopcount % 256 == 0 && keepLooping && candidates.size() > 0) {                MovePath front = (MovePath)candidates.get(0);                if (front.getFinalCoords().distance(dest) < bestPath.getFinalCoords().distance(dest)) {                    bestPath = front;                    keepLooping = System.currentTimeMillis() < endTime;                } else {                    keepLooping = false;                }            }        } //end while        if (getFinalCoords().distance(dest) > bestPath.getFinalCoords().distance(dest)) {            //Make the path we found, this path.            this.steps = bestPath.steps;        }        if (!getFinalCoords().equals(dest)) {            lazyPathfinder(dest, type);        }    }