Use java to realize path-consistency