public RootPathToken append(PathToken next) { this.tail = tail.appendTailToken(next); this.tokenCount++; return this; }
String property = properties.get(0); String evalPath = Utils.concat(currentPath, "['", property, "']"); Object propertyVal = readObjectProperty(property, model, ctx); if(propertyVal == JsonProvider.UNDEFINED){ if(isLeaf()) { if(ctx.options().contains(Option.DEFAULT_PATH_LEAF_TO_NULL)){ propertyVal = null; if (! (isUpstreamDefinite() && isTokenDefinite()) && !ctx.options().contains(Option.REQUIRE_PROPERTIES) || ctx.options().contains(Option.SUPPRESS_EXCEPTIONS)){ if (isLeaf()) { ctx.addResult(evalPath, pathRef, propertyVal); next().evaluate(evalPath, pathRef, propertyVal, ctx); assert isLeaf() : "non-leaf multi props handled elsewhere"; if(hasProperty(property, model, ctx)) { propertyVal = readObjectProperty(property, model, ctx); if(propertyVal == JsonProvider.UNDEFINED){ if(ctx.options().contains(Option.DEFAULT_PATH_LEAF_TO_NULL)) {
@Override public String toString() { if (isLeaf()) { return getPathFragment(); } else { return getPathFragment() + next().toString(); } }
boolean isUpstreamDefinite() { if (upstreamDefinite == null) { upstreamDefinite = isRoot() || prev.isTokenDefinite() && prev.isUpstreamDefinite(); } return upstreamDefinite; }
public static void walkArray(PathToken pt, String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx, Predicate predicate) { if (predicate.matches(model)) { if (pt.isLeaf()) { pt.evaluate(currentPath, parent, model, ctx); } else { PathToken next = pt.next(); Iterable<?> models = ctx.jsonProvider().toIterable(model); int idx = 0; for (Object evalModel : models) { String evalPath = currentPath + "[" + idx + "]"; next.evaluate(evalPath, parent, evalModel, ctx); idx++; } } } Iterable<?> models = ctx.jsonProvider().toIterable(model); int idx = 0; for (Object evalModel : models) { String evalPath = currentPath + "[" + idx + "]"; walk(pt, evalPath, PathRef.create(model, idx), evalModel, ctx, predicate); idx++; } }
public boolean isPathDefinite() { if(definite != null){ return definite.booleanValue(); } boolean isDefinite = isTokenDefinite(); if (isDefinite && !isLeaf()) { isDefinite = next.isPathDefinite(); } definite = isDefinite; return isDefinite; }
try { Object evalHit = ctx.jsonProvider().getArrayIndex(model, effectiveIndex); if (isLeaf()) { checkAndFillArrayElements(ctx, ctx.getParent(), evalHit, effectiveIndex); if (null == curr) { curr = ctx.configuration().jsonProvider().createMap(); checkAndFillArrayElements(ctx, old, curr, effectiveIndex); next().evaluate(evalPath, pathRef, evalHit, ctx);
@Override public void evaluate(String currentPath, PathRef pathRef, Object model, EvaluationContextImpl ctx) { if (isLeaf()) { PathRef op = ctx.forUpdate() ? pathRef : PathRef.NO_OP; ctx.addResult(rootToken, op, model); } else { next().evaluate(rootToken, pathRef, model, ctx); } }
@Test public void is_upstream_definite_in_simple_case() { assertThat(makePathReturningTail(makePPT("foo")).isUpstreamDefinite()).isTrue(); assertThat(makePathReturningTail(makePPT("foo"), makePPT("bar")).isUpstreamDefinite()).isTrue(); assertThat(makePathReturningTail(makePPT("foo", "foo2"), makePPT("bar")).isUpstreamDefinite()).isFalse(); assertThat(makePathReturningTail(new WildcardPathToken(), makePPT("bar")).isUpstreamDefinite()).isFalse(); assertThat(makePathReturningTail(new ScanPathToken(), makePPT("bar")).isUpstreamDefinite()).isFalse(); }
PathToken next() { if (isLeaf()) { throw new IllegalStateException("Current path token is a leaf"); } return next; }
protected void handleArrayIndex(int index, String currentPath, Object model, EvaluationContextImpl ctx) { String evalPath = Utils.concat(currentPath, "[", String.valueOf(index), "]"); PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, index) : PathRef.NO_OP; int effectiveIndex = index < 0 ? ctx.jsonProvider().length(model) + index : index; try { Object evalHit = ctx.jsonProvider().getArrayIndex(model, effectiveIndex); if (isLeaf()) { ctx.addResult(evalPath, pathRef, evalHit); } else { next().evaluate(evalPath, pathRef, evalHit, ctx); } } catch (IndexOutOfBoundsException e) { } }
boolean isUpstreamDefinite() { if (upstreamDefinite == null) { upstreamDefinite = isRoot() || prev.isTokenDefinite() && prev.isUpstreamDefinite(); } return upstreamDefinite; }
public boolean isPathDefinite() { if(definite != null){ return definite.booleanValue(); } boolean isDefinite = isTokenDefinite(); if (isDefinite && !isLeaf()) { isDefinite = next.isPathDefinite(); } definite = isDefinite; return isDefinite; }
@Override public void evaluate(String currentPath, PathRef parent, Object model, EvaluationContextImpl ctx) { PathFunction pathFunction = PathFunctionFactory.newFunction(functionName); evaluateParameters(currentPath, parent, model, ctx); Object result = pathFunction.invoke(currentPath, parent, model, ctx, functionParams); ctx.addResult(currentPath + "." + functionName, parent, result); if (!isLeaf()) { next().evaluate(currentPath, parent, result, ctx); } }
@Test public void is_upstream_definite_in_complex_case() { assertThat(makePathReturningTail(makePPT("foo"), makePPT("bar"), makePPT("baz")).isUpstreamDefinite()).isTrue(); assertThat(makePathReturningTail(makePPT("foo"), new WildcardPathToken()).isUpstreamDefinite()).isTrue(); assertThat(makePathReturningTail(new WildcardPathToken(), makePPT("bar"), makePPT("baz")).isUpstreamDefinite()).isFalse(); }
PathToken next() { if (isLeaf()) { throw new IllegalStateException("Current path token is a leaf"); } return next; }