package org.joow.elevator2;

import org.joow.elevator.DoorState;

import java.util.concurrent.atomic.AtomicInteger;

public class Cabin {
    private final Integer floor;

    private final DoorState doorState;

    private final AtomicInteger move;

    public Cabin() {
        this(0);
    }

    public Cabin(final Integer floor) {
        this(floor, DoorState.CLOSED);
    }

    public Cabin(final int floor, final DoorState doorState) {
        this(floor, doorState, 0);
    }

    public Cabin(final int floor, final DoorState doorState, final Integer move) {
        this.floor = floor;
        this.doorState = doorState;
        this.move = new AtomicInteger(move);
    }

    public Integer floor() {
        return floor;
    }

    public Boolean areDoorsOpened() {
        return doorState == DoorState.OPENED;
    }

    public Integer move() {
        return move.get();
    }

    public Cabin moveTo(final int toFloor) {
        if (toFloor == floor) {
            return this;
        }

        if (areDoorsOpened()) {
            return closeDoors();
        } else if (toFloor > floor) {
            return new Cabin(floor + 1, doorState, move() + 1);
        } else {
            return new Cabin(floor - 1, doorState, move() + 1);
        }
    }

    public Cabin openDoors() {
        return changeDoorsState(DoorState.OPENED);
    }

    public Cabin closeDoors() {
        return changeDoorsState(DoorState.CLOSED);
    }

    private Cabin changeDoorsState(final DoorState newDoorState) {
        if (newDoorState == doorState) {
            return this;
        }

        if (doorState == DoorState.OPENED) {
            return new Cabin(floor, DoorState.CLOSED, move() + 1);
        } else {
            return new Cabin(floor, DoorState.OPENED, move() + 1);
        }
    }
}

@@ -63,59 +63,8 @@
 e;%0A%0A
-import java.util.concurrent.atomic.AtomicInteger;%0A%0A
 publ
@@ -172,22 +172,16 @@
 e final 
-Atomic
 Integer 
@@ -594,31 +594,12 @@
 e = 
-new AtomicInteger(
 move
-)
 ;%0A  
@@ -803,14 +803,8 @@
 move
-.get()
 ;%0A  

Remove useless usage of AtomicInteger.