Mistři v programování na #hovnokod

Java #66

private int checkTerm(PatternTerm term, int arr[],
      int symbNum, boolean isEditing) {
    if (term.count != INFINITY) {
      int endIdx = Math.min(symbNum + term.count, arr.length);
        int count = 0;
        switch(term.termType) {
          case DIGIT: {
            for(int i = symbNum; i < endIdx; i++) {
              if (!Character.isDigit((char)arr[i]))
                return -1;
              count++;
            }
            break;
          }
          case LETTER: {
            for(int i = symbNum; i < endIdx; i++) {
              if (!Character.isLetter((char)arr[i]))
                return -1;
              count++;
            }
            break;
          }
          case LETTERORDIGIT: {
            for(int i = symbNum; i < endIdx; i++) {
              if (!Character.isLetterOrDigit((char)arr[i]))
                return -1;
              count++;
            }
            break;
          }
          case CHARACTER: {
            for(int i = symbNum; i < endIdx; i++) {
              if (arr[i] != term.value)
                return -1;
              count++;
            }
            break;
          }
      }
      if (!isEditing && count != term.count)
        return -1;
      
      symbNum+=term.count;
    } else {
      int i = 0;
      switch(term.termType) {
        case DIGIT: {
          while (((symbNum + i) < arr.length) &&
              Character.isDigit((char)arr[symbNum + i])) i++;
          break;
        }
        case LETTER: {
          while (((symbNum + i) < arr.length) &&
              Character.isLetter((char)arr[symbNum + i])) i++;
          break;
        }
        case LETTERORDIGIT: {
          while (((symbNum + i) < arr.length) &&
              Character.isLetterOrDigit((char)arr[symbNum + i])) i++;
          break;
        }
        case CHARACTER: {
          while (((symbNum + i) < arr.length) &&
              (arr[symbNum + i] == term.value)) i++;
          break;
        }
      }
      symbNum+=i;
    }
    return symbNum;
  }

Anonymous,