private static int solve(String s) {
        if (s == null || s.length() == 0)
            return 0;
        String[] ar = s.split("\n");
        int counter = 0;
        int x = ar.length / 2;
        int y = ar[0].length() / 2;
        Map<Integer, Set<Integer>> infected = new HashMap<>();

        for (int i = 0; i < ar.length; i++) {
            infected.put(i, new HashSet<>());
            for (int j = 0; j < ar[i].length(); j++) {
                if (ar[i].charAt(j) == '#') {
                    infected.get(i).add(j);
                }
            }
        }
        int direction = 1; // 1 up, -1 down, 2 right, -2 left
        for (int i = 0; i < 10_000; i++) {

            boolean isInfected = infected.containsKey(x) && infected.get(x).contains(y);

            if (isInfected) {
                if (direction == 1) {
                    direction = 2;
                } else if (direction == 2) {
                    direction = -1;
                } else if (direction == -1) {
                    direction = -2;
                } else {
                    direction = 1;
                }
            } else {
                if (direction == 1) {
                    direction = -2;
                } else if (direction == -2) {
                    direction = -1;
                } else if (direction == -1) {
                    direction = 2;
                } else {
                    direction = 1;
                }
            }

            if (!isInfected) {
                if (!infected.containsKey(x))
                    infected.put(x, new HashSet<>());

                if (infected.get(x).add(y))
                    counter++;
            } else {
                infected.get(x).remove(y);
            }

            if (Math.abs(direction) == 1) {
                x += -direction;
            } else {
                y += (direction > 0 ? 1 : -1);
            }
        }

        return counter;
    }
Why Did you create this class? what does it do?
src/adventofcode/SporificaVirus_22.java