Pattern matching in java