示例#1
0
  /** @return null if no work was done, otherwise returns the re-parented data */
  private Object performCardinalityAdjustment(
      String inputKey,
      Object input,
      WalkedPath walkedPath,
      Map parentContainer,
      LiteralPathElement thisLevel) {

    // Add our the LiteralPathElement for this level, so that write path References can use it as
    // &(0,0)
    walkedPath.add(thisLevel);

    Object returnValue = null;
    if (cardinalityRelationship == CardinalityRelationship.MANY) {
      if (input instanceof List) {
        returnValue = input;
      } else if (input instanceof Map
          || input instanceof String
          || input instanceof Number
          || input instanceof Boolean) {
        Object one = parentContainer.remove(inputKey);
        returnValue = new ArrayList<Object>();
        ((List) returnValue).add(one);
      } else if (input == null) {
        returnValue = Collections.emptyList();
      }
      parentContainer.put(inputKey, returnValue);
    } else if (cardinalityRelationship == CardinalityRelationship.ONE) {
      if (input instanceof List) {
        if (!((List) input).isEmpty()) {
          returnValue = ((List) input).get(0);
        }
        parentContainer.put(inputKey, returnValue);
      }
    }

    walkedPath.removeLast();

    return returnValue;
  }
示例#2
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.");
    }
  }