synchronized (pendingMoves) { pendingMoves.addFirst(pendingMove);
if (pendingMove != null) { synchronized (pendingMoves) { pendingMoves.addFirst(pendingMove); }
        private void moveCommitted(Move move) {            MoveStatus ms;	    Move pendingMove = null;	    synchronized (pendingMoves) {		if (!pendingMoves.isEmpty()) {		    pendingMove = (Move)pendingMoves.removeFirst();		}	    }	    if (pendingMove != null) {                if (move instanceof RejectedMove) {                    /* moves are rejected in order hence only the first can                     * match*/                    if (((RejectedMove)move).getAttemptedMove()			    .equals(pendingMove)) {			if (debug)			    System.err.println("Logging rejected move " +				    ((RejectedMove) move).getAttemptedMove());                        /* Move was one of ours so we add it to the list of                         * rejected moves and remove it from the list of pending                         * moves */                        rejectedMoves.add(move);                        do {			    // undo all rejected moves                            if (!undoMoves()) {				assert false;                                break;                            }                            /* attempt to commit any moves which were previously                             * blocked */                            while (!approvedMoves.isEmpty()) {                                Move am = (Move)approvedMoves.getFirst();				if (am.doMove(world, am.getPrincipal()) !=					MoveStatus.MOVE_OK) {                                    break;                                }				if (debug)				    System.err.println("Committed queued move "					    + am);                                approvedMoves.removeFirst();                            }                        } while (!approvedMoves.isEmpty());                        return;                    }		    // rejected move was submitted  by another client.                } else if (move.equals(pendingMove)) {		    if (debug)			System.err.println("Precommitted move acknowledged "				+ "by server:" + move);                    // move succeeded and we have already executed it                    return;                }		// move succeeded but was submitted  by another client            }	    // Replace our pending move	    synchronized (pendingMoves) {		pendingMoves.addFirst(pendingMove);	    }            /* move must be from another client */            if (!(move instanceof RejectedMove)) {		if (debug && !(move instanceof TimeTickMove)) {		    System.err.println("committing unknown move " + move);		}		GameTime t = (GameTime) world.get(ITEM.TIME,			Player.AUTHORITATIVE);		TrainPath tp1 = null, tp2 = null;		if (move instanceof ChangeTrainMove) {		    tp1 = ((TrainModel) world.get(KEY.TRAINS,				((ChangeTrainMove) move).getIndex(),				move.getPrincipal())).getPosition(t);		}		ms = move.doMove(world, move.getPrincipal());		if (move instanceof ChangeTrainMove) {		    tp2 = ((TrainModel) world.get			    (KEY.TRAINS, ((ChangeTrainMove) move).getIndex(),			     move.getPrincipal()))			.getPosition(t);		    System.out.println("before = " + tp1 + ", after = " + tp2);		}                if (ms != MoveStatus.MOVE_OK) {                    if (debug) {                        System.out.println("Queueing blocked move " +			       move + " - " + ms.toString());                    }                    /* move could not be committed because of                     * a pre-commited move yet to be rejected by the server */                    approvedMoves.addLast(move);                } else {                    forwardMove(move, ms);                }                return;            } else {		if (debug) {		    System.err.println("received unknown rejected move!" +			    move);		}	    }        }