Browse Source

use utility method to concatenate Strings

pull/110/head
Jochen Berger 9 years ago
parent
commit
d7c5fc34ea
  1. 12
      json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java
  2. 4
      json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java

12
json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java

@ -63,13 +63,13 @@ public class PathCompiler {
LinkedList<Predicate> filterList = new LinkedList<Predicate>(asList(filters));
if (trimmedPath.charAt(0) != '$' && trimmedPath.charAt(0) != '@') {
trimmedPath = "$." + trimmedPath;
trimmedPath = Utils.concat("$.", trimmedPath);
}
boolean isRootPath = (trimmedPath.charAt(0) == '$');
if (trimmedPath.charAt(0) == '@') {
trimmedPath = "$" + trimmedPath.substring(1);
trimmedPath = Utils.concat("$", trimmedPath.substring(1));
}
if (trimmedPath.length() > 1 &&
@ -78,10 +78,10 @@ public class PathCompiler {
throw new InvalidPathException("Invalid path " + trimmedPath);
}
String cacheKey = trimmedPath + isRootPath + filterList.toString();
String cacheKey = Utils.concat(trimmedPath, Boolean.toString(isRootPath), filterList.toString());
Path p = cache.get(cacheKey);
if (p != null) {
if (logger.isDebugEnabled()) logger.debug("Using cached path: " + cacheKey);
if (logger.isDebugEnabled()) logger.debug("Using cached path: {}", cacheKey);
return p;
}
@ -123,7 +123,7 @@ public class PathCompiler {
} else {
assertValidFieldChars(trimmedPath, i, positions);
fragment = PROPERTY_OPEN + trimmedPath.substring(i, i + positions) + PROPERTY_CLOSE;
fragment = Utils.concat(PROPERTY_OPEN, trimmedPath.substring(i, i + positions), PROPERTY_CLOSE);
}
i += positions;
}
@ -135,7 +135,7 @@ public class PathCompiler {
default:
positions = fastForward(trimmedPath, i);
fragment = PROPERTY_OPEN + trimmedPath.substring(i, i + positions) + PROPERTY_CLOSE;
fragment = Utils.concat(PROPERTY_OPEN, trimmedPath.substring(i, i + positions), PROPERTY_CLOSE);
i += positions;
break;
}

4
json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java

@ -40,7 +40,7 @@ public abstract class PathToken {
if(properties.size() == 1) {
String property = properties.get(0);
String evalPath = currentPath + "['" + property + "']";
String evalPath = Utils.concat(currentPath, "['", property, "']");
Object propertyVal = readObjectProperty(property, model, ctx);
if(propertyVal == JsonProvider.UNDEFINED){
if(isLeaf()) {
@ -115,7 +115,7 @@ public abstract class PathToken {
void handleArrayIndex(int index, String currentPath, Object model, EvaluationContextImpl ctx) {
String evalPath = currentPath + "[" + index + "]";
String evalPath = Utils.concat(currentPath, "[", String.valueOf(index), "]");
PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, index) : PathRef.NO_OP;
try {
Object evalHit = ctx.jsonProvider().getArrayIndex(model, index);

Loading…
Cancel
Save