porting of SequenceMatcher from python version to java version