Пример #1
0
  /**
   * Input is the part of the implicit name printed by this mask
   *
   * @param levelString output part of implicit name
   * @return id-nr for current level or -1, if id could not be parsed
   */
  public int getNumberOfLevelString(String levelString) {

    if (names == null) {

      if (!isOutputAllowed(levelString)) {
        return -1; // For robustness of this function
      }

      levelString = levelString.substring(pre.length()); // cut pre-text from inception
      levelString =
          levelString.substring(
              0, levelString.length() - post.length()); // cut post-text from end of levelstring

      final char[] chars = levelString.toCharArray();

      int i = 0;
      while (i < chars.length && chars[i] < '0' || chars[i] > '9') {
        i++;
      }

      // No digit at all?
      if (i == chars.length) {
        return -1;
      }

      String number = String.valueOf(chars[i]);
      i++;
      while (i < chars.length && chars[i] >= '0' && chars[i] <= '9') {
        number += chars[i];
        i++;
      }

      return Integer.parseInt(number);

    } else { // special names defined, search position of levelstring within names, map position to
             // id
      int pos = 0;
      for (final String name : names) {
        if (name.equals(levelString)) {

          if (scheme.getList() != null) {

            if (numbers == null) {
              numbers = LMLCheck.getNumbersFromNumberlist(scheme.getList());
            }

            return numbers[pos];
          } else {
            return scheme.getMin().intValue() + scheme.getStep().intValue() * pos;
          }
        }
        pos++;
      }
    }
    // No matches
    return -1;
  }