Пример #1
0
  public ArrayPathElement(String key) {
    super(key);

    if (key.charAt(0) != '[' || key.charAt(key.length() - 1) != ']') {
      throw new SpecException("Invalid ArrayPathElement key:" + key);
    }

    ArrayPathType apt;
    PathReference r = null;
    TransposePathElement tpe = null;
    String aI = "";

    if (key.length() == 2) {
      apt = ArrayPathType.AUTO_EXPAND;
      canonicalForm = "[]";
    } else {
      String meat = key.substring(1, key.length() - 1); // trim the [ ]
      char firstChar = meat.charAt(0);

      if (AmpReference.TOKEN.equals(firstChar)) {
        r = new AmpReference(meat);
        apt = ArrayPathType.REFERENCE;

        canonicalForm = "[" + r.getCanonicalForm() + "]";
      } else if (HashReference.TOKEN.equals(firstChar)) {
        r = new HashReference(meat);
        apt = ArrayPathType.HASH;

        canonicalForm = "[" + r.getCanonicalForm() + "]";
      } else if ('@' == firstChar) {
        apt = ArrayPathType.TRANSPOSE;

        tpe = TransposePathElement.parse(meat);
        canonicalForm = "[" + tpe.getCanonicalForm() + "]";
      } else {
        aI = verifyStringIsNonNegativeInteger(meat);
        if (aI != null) {
          apt = ArrayPathType.EXPLICIT_INDEX;
          canonicalForm = "[" + aI + "]";
        } else {
          throw new SpecException("Bad explict array index:" + meat + " from key:" + key);
        }
      }
    }

    transposePathElement = tpe;
    arrayPathType = apt;
    ref = r;
    arrayIndex = aI;
  }