Пример #1
0
  @Override
  public String evaluate(WalkedPath walkedPath) {

    switch (arrayPathType) {
      case AUTO_EXPAND:
        return canonicalForm;

      case EXPLICIT_INDEX:
        return arrayIndex;

      case HASH:
        LiteralPathElement element =
            walkedPath.elementFromEnd(ref.getPathIndex()).getLiteralPathElement();
        Integer index = element.getHashCount();
        return index.toString();

      case TRANSPOSE:
        String key = transposePathElement.evaluate(walkedPath);
        return verifyStringIsNonNegativeInteger(key);

      case REFERENCE:
        LiteralPathElement lpe =
            walkedPath.elementFromEnd(ref.getPathIndex()).getLiteralPathElement();
        String keyPart;

        if (ref instanceof PathAndGroupReference) {
          keyPart = lpe.getSubKeyRef(((PathAndGroupReference) ref).getKeyGroup());
        } else {
          keyPart = lpe.getSubKeyRef(0);
        }

        return verifyStringIsNonNegativeInteger(keyPart);
      default:
        throw new IllegalStateException(
            "ArrayPathType enum added two without updating this switch statement.");
    }
  }