State Explosion Problem Java Code