String rotation check in java