code: public static String normalize(final String token) {
      String normalizedToken = "";
  
      char currentCharacter;
      int prevCharType = -1;
      char charType = '~';
      boolean addedStar = false;
      for (int i = 0; i < token.length(); i++) {
  
        currentCharacter = token.charAt(i);
        if (currentCharacter >= 'A' && currentCharacter <= 'Z') {
          charType = 'X';
        } else if (currentCharacter >= 'a' && currentCharacter <= 'z') {
          charType = 'x';
        } else if (currentCharacter >= '0' && currentCharacter <= '9') {
          charType = 'd';
        } else {
          charType = currentCharacter;
        }
  
        if (charType == prevCharType) {
          if (!addedStar) {
            normalizedToken += "*";
            addedStar = true;
          }
        } else {
          addedStar = false;
          normalizedToken += charType;
        }
        prevCharType = charType;
      }
      return normalizedToken;
    }
docs: Normalize upper case, lower case, digits and duplicate characters.
  
  @param token
  the token to be normalized
  @return the normalized token