@Override
    public boolean equals(Object obj) {
        if (obj == null || obj.getClass() != this.getClass()) {
            return false;
        }

        if (this == obj) {
            return true;
        }

        State state2 = (State) obj;
        if (this.isFinal ^ state2.isFinal()
                || this.getNumberOfConnectedStates() != state2.getNumberOfConnectedStates()) {
            return false;
        }

        if (getNumberOfConnectedStates() == 0) {
            return true;
        }

        for (Character ch : nextStates.keySet()) {
            if (!nextStates.get(ch).equals(state2.getNextState(ch))) {
                return false;
            }
        }
        
        return true;
    }