Refactor this code by leaving the names of methods, variables and classes the same, without adding or deleting existing methods, variables and classes, making the code different according to the following rules:
1. Replace the use of imported library methods with alternative code that performs the same function
2. If possible, rearrange the order of execution of functions, loops, and conditions so that they do not affect the result of execution
3. if it is possible to import a new library and shorten long methods by using a library method, use it 
4. use alternative ways of storing data
5. Group ungrouped data
6. If data is grouped in this code, then distribute it throughout the code, ungroup it
7. Identify standard algorithms and if possible use similar algorithm without performance loss. For example, replace bubble sorting with quick sorting
8. If possible, ignore encapsulation by implementing the method inside the executable class rather than in another class
9. Use encapsulation if it has been implemented for a method inside a class or interface when you can move it to another class
10. Remove type generalization by making type specialization
11. For implemented specialized types, do type generalization
12. Instead of pull up and push down, implement methods locally in the class
13. Use pull up and push down instead of already implemented local use of methods
14. Remove overloading and polymorphism, rewrite methods without using these paradigms
15. If possible, use overloading and polymorphism if it is possible but not implemented in the code
```Java
public int travelDirectionUni(Direction dir, Map<String, BoardEntity> boardData, int boardSize) {
        int curX = entityPosition.getX();
        int curY = entityPosition.getY();
        int score = 0;
        String startKey = curY + "_" + curX;
        String key = curY + "_" + curX;
        switch (dir) {
            case N:
                while (curX > 0) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(key)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curX--;
                    } else if (boardData.get(key) instanceof Insect) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curX--;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curX--;
                    }
                }
                boardData.remove(startKey);
                return score;
            case E:
                while (curY < boardSize + 1) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(key)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curY++;
                    } else if (boardData.get(key) instanceof Insect) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curY++;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curY++;
                    }
                }
                boardData.remove(startKey);
                return score;
            case S:
                while (curX < boardSize + 1) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(key)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curX++;
                    } else if (boardData.get(key) instanceof Insect && !key.equals(startKey)) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curX++;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curX++;
                    }
                }
                boardData.remove(startKey);
                return score;
            case W:
                while (curY > 0) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(key)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curY--;
                    } else if (boardData.get(key) instanceof Insect) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curY--;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curY--;
                    }
                }
                boardData.remove(startKey);
                return score;
            case NE:
                while (curY < boardSize + 1 && curX > 0) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(curY + "_" + curX)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curX--;
                        curY++;
                    } else if (boardData.get(key) instanceof Insect) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curX--;
                            curY++;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curX--;
                        curY++;
                    }
                }
                boardData.remove(startKey);
                return score;
            case SE:
                while (curX < boardSize + 1 && curY < boardSize + 1) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(curY + "_" + curX)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curX++;
                        curY++;
                    } else if (boardData.get(key) instanceof Insect) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curX++;
                            curY++;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curX++;
                        curY++;
                    }
                }
                boardData.remove(startKey);
                return score;
            case SW:
                while (curY > 0 && curX < boardSize + 1) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(curY + "_" + curX)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curX++;
                        curY--;
                    } else if (boardData.get(key) instanceof Insect) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curX++;
                            curY--;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curX++;
                        curY--;
                    }
                }
                boardData.remove(startKey);
                return score;
            default:
                while (curX > 0 && curY > 0) {
                    key = curY + "_" + curX;
                    if (boardData.get(key) instanceof FoodPoint && !key.equals(startKey)) {
                        score += ((FoodPoint) boardData.get(curY + "_" + curX)).getValue();
                        boardData.remove(key); //remove foodpoint
                        curX--;
                        curY--;
                    } else if (boardData.get(key) instanceof Insect) {
                        if (this.color.name().equals(((Insect) boardData.get(key)).getColor().name())) {
                            curX--;
                            curY--;
                        } else {
                            boardData.remove(startKey);
                            return score;
                        }
                    } else {
                        curX--;
                        curY--;
                    }
                }
                boardData.remove(startKey);
                return score;
        }
```