"Perfectly Spherical Houses in a Vacuum" - Day 3 - Advent of Code

import java.io.FileNotFoundException; import java.io.IOException; import java.util.HashSet;

public class DayThree {

public static void main(String[] args) throws FileNotFoundException, IOException {
    String input = IOUtils.readFile("Input.txt");
    Position santaPosition = new Position(0, 0);
    Position roboSantaPosition = new Position(0, 0);
    HashSet<Position> deliveredPositions = new HashSet<>();
    deliveredPositions.add(new Position(santaPosition));
    int i = 0;
    for (char c : input.toCharArray()) {
        if (i % 2 == 0) {
            moveSanta(c, santaPosition);
        } else {
            moveSanta(c, roboSantaPosition);
        }
        deliveredPositions.add(new Position(santaPosition));
        deliveredPositions.add(new Position(roboSantaPosition));
        i++;
    }
    System.out.println(Integer.toString(deliveredPositions.size()));
}

private static void moveSanta(char c, Position position) {
    switch (c) {
        case '^':
            position.moveNorth();
            break;
        case 'v':
            position.moveSouth();
            break;
        case '>':
            position.moveWest();
            break;
        case '<':
            position.moveEast();
            break;
        default:
            break;
    }
}

private static class Position {

    private int x;
    private int y;
    private volatile int hashCode;

    protected Position(int x, int y) {
        this.x = x;
        this.y = y;
    }

    protected Position(Position position) {
        this.x = position.x;
        this.y = position.y;
    }

    protected void moveNorth() {
        this.y++;
    }

    protected void moveSouth() {
        this.y--;
    }

    protected void moveEast() {
        this.x--;
    }

    protected void moveWest() {
        this.x++;
    }

    @Override
    public boolean equals(Object position) {
        if (position instanceof Position) {
            Position pos = (Position) position;
            return this.x == pos.x && this.y == pos.y;
        } else {
            return false;
        }
    }

    @Override
    public int hashCode() {
        int result = this.hashCode;
        if (result == 0) {
            result = 17;
            result = 31 * result + this.x;
            result = 31 * result + this.y;
            this.hashCode = result;
        }
        return result;
    }
}

}

/r/coding Thread Link - adventofcode.com