Browse Source

Code cleanup.

pull/183/merge
Kalle Stenflo 9 years ago
parent
commit
ebd19526d8
  1. 8
      gradle/binaryCompatibility.gradle
  2. 4
      json-path/src/main/java/com/jayway/jsonpath/EvaluationListener.java
  3. 17
      json-path/src/main/java/com/jayway/jsonpath/Filter.java
  4. 7
      json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java
  5. 5
      json-path/src/main/java/com/jayway/jsonpath/spi/cache/CacheProvider.java
  6. 1
      json-path/src/main/java/com/jayway/jsonpath/spi/cache/NOOPCache.java
  7. 2
      json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java
  8. 9
      json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java
  9. 6
      json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderTest.java
  10. 2
      json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java
  11. 2
      json-path/src/test/java/com/jayway/jsonpath/internal/UtilsTest.java
  12. 4
      json-path/src/test/resources/simplelogger.properties

8
gradle/binaryCompatibility.gradle

@ -38,7 +38,6 @@ task checkBinaryCompatibility {
if (JavaVersion.current().isJava7Compatible()) {
apply plugin: 'me.champeau.gradle.japicmp'
def referenceMinorVersion = '1.1.0'
def reportGenerator = { model ->
outputProcessor {
@ -61,14 +60,12 @@ if (JavaVersion.current().isJava7Compatible()) {
violations[c.fullyQualifiedName].error << "Class has been removed"
}
}
modifiedMethod { c, m ->
if (!skipMethod(c, m)) {
violations[c.fullyQualifiedName].warning << """<p>Method ${m.name} has been modified</p>
<p>From <pre>${m.oldMethod.get()?.longName}</pre> to <pre>${m.newMethod.get()?.longName}</pre></p>"""
}
}
newClass { c ->
if (!skipClass(c)) {
violations[c.fullyQualifiedName].info << "Class has been added"
@ -101,8 +98,8 @@ if (JavaVersion.current().isJava7Compatible()) {
task japicmp(type: me.champeau.gradle.ArtifactJapicmpTask) {
dependsOn jar
//baseline = "com.jayway.jsonpath:${project.name}:${referenceMinorVersion}@jar"
baseline = "com.jayway.jsonpath:${project.name}:+@jar"
//baseline = "com.jayway.jsonpath:${project.name}:+@jar" //latest release
baseline = 'com.jayway.jsonpath:json-path:2.0.0@jar'
to = jar.archivePath
accessModifier = 'protected'
onlyModified = true
@ -125,7 +122,6 @@ if (JavaVersion.current().isJava7Compatible()) {
engine.createTemplateByPath(templateFile).make(model).writeTo(wrt)
}
}
}
}

4
json-path/src/main/java/com/jayway/jsonpath/EvaluationListener.java

@ -27,7 +27,7 @@ public interface EvaluationListener {
*/
EvaluationContinuation resultFound(FoundResult found);
public static enum EvaluationContinuation {
enum EvaluationContinuation {
/**
* Evaluation continues
*/
@ -41,7 +41,7 @@ public interface EvaluationListener {
/**
*
*/
public interface FoundResult {
interface FoundResult {
/**
* the index of this result. First result i 0
* @return index

17
json-path/src/main/java/com/jayway/jsonpath/Filter.java

@ -57,7 +57,14 @@ public abstract class Filter implements Predicate {
return new AndFilter(this, other);
}
/**
* Parses a filter. The filter must match <code>[?(<filter>)]</code>, white spaces are ignored.
* @param filter filter string to parse
* @return the filter
*/
public static Filter parse(String filter){
return FilterCompiler.compile(filter);
}
private static final class SingleFilter extends Filter {
@ -173,13 +180,5 @@ public abstract class Filter implements Predicate {
sb.append(")]");
return sb.toString();
}
}
public static Filter parse(String filter){
return FilterCompiler.compile(filter);
}
}

7
json-path/src/main/java/com/jayway/jsonpath/internal/JsonReader.java

@ -47,7 +47,6 @@ public class JsonReader implements ParseContext, DocumentContext {
private final Configuration configuration;
private Object json;
private Object patch;
public JsonReader() {
this(Configuration.defaultConfiguration());
@ -138,15 +137,15 @@ public class JsonReader implements ParseContext, DocumentContext {
public <T> T read(String path, Predicate... filters) {
notEmpty(path, "path can not be null or empty");
Cache cache = CacheProvider.getCache();
path = path.trim();
LinkedList filterStack = new LinkedList<Predicate>(asList(filters));
String cacheKey = Utils.concat(path, filterStack.toString());
JsonPath jsonPath = cache.get(cacheKey);
if(jsonPath != null){
return read(jsonPath);
}else {
} else {
jsonPath = compile(path, filters);
cache.put(cacheKey, jsonPath);
return read(jsonPath);

5
json-path/src/main/java/com/jayway/jsonpath/spi/cache/CacheProvider.java vendored

@ -6,6 +6,7 @@ import static com.jayway.jsonpath.internal.Utils.notNull;
public class CacheProvider {
private static Cache cache;
private static boolean cachingEnabled;
public static void setCache(Cache cache){
notNull(cache, "Cache may not be null");
@ -15,6 +16,7 @@ public class CacheProvider {
} else {
CacheProvider.cache = cache;
}
cachingEnabled = !(CacheProvider.cache instanceof NOOPCache);
}
}
@ -31,6 +33,7 @@ public class CacheProvider {
private static Cache getDefaultCache(){
return new LRUCache(200);
return new LRUCache(400);
//return new NOOPCache();
}
}

1
json-path/src/main/java/com/jayway/jsonpath/spi/cache/NOOPCache.java vendored

@ -3,6 +3,7 @@ package com.jayway.jsonpath.spi.cache;
import com.jayway.jsonpath.JsonPath;
public class NOOPCache implements Cache {
@Override
public JsonPath get(String key) {
return null;

2
json-path/src/test/java/com/jayway/jsonpath/FilterCompilerTest.java

@ -62,7 +62,7 @@ public class FilterCompilerTest {
compile(filter);
throw new AssertionError("Expected " + filter + " to throw InvalidPathException");
} catch (InvalidPathException e){
e.printStackTrace();
//e.printStackTrace();
}
}
}

9
json-path/src/test/java/com/jayway/jsonpath/InlineFilterTest.java

@ -42,15 +42,6 @@ public class InlineFilterTest extends BaseTest {
}
@Test
public void document_queries_are_cached() {
Object read = reader.read("$.store.book[?(@.display-price <= $.max-price)]");
//System.out.println(read);
}
@Test
public void simple_inline_or_statement_evaluates() {

6
json-path/src/test/java/com/jayway/jsonpath/JacksonJsonNodeJsonProviderTest.java

@ -72,7 +72,11 @@ public class JacksonJsonNodeJsonProviderTest extends BaseTest {
@Test
public void list_of_numbers() {
ArrayNode objs = using(JACKSON_JSON_NODE_CONFIGURATION).parse(JSON_DOCUMENT).read("$.store.book[*].display-price");
System.out.println(objs.toString());
assertThat(objs.get(0).asDouble()).isEqualTo(8.95D);
assertThat(objs.get(1).asDouble()).isEqualTo(12.99D);
assertThat(objs.get(2).asDouble()).isEqualTo(8.99D);
assertThat(objs.get(3).asDouble()).isEqualTo(22.99D);
}
@Test

2
json-path/src/test/java/com/jayway/jsonpath/PathCompilerTest.java

@ -142,8 +142,6 @@ public class PathCompilerTest {
+ "}";
// message: it\ -> (after json escaping) -> "it\\" -> (after java escaping) -> "\"it\\\\\""
System.out.println(JsonPath.parse(json).json().toString());
List<String> result = JsonPath.read(json, "$.logs[?(@.message == 'it\\\\')].message");
assertThat(result).containsExactly("it\\");

2
json-path/src/test/java/com/jayway/jsonpath/internal/UtilsTest.java

@ -9,8 +9,6 @@ public class UtilsTest {
public void strings_can_be_escaped() {
String str = "it\\\\";
System.out.println(Utils.unescape(str));
System.out.println(Utils.escape(str, true));
}

4
json-path/src/test/resources/simplelogger.properties

@ -1,4 +1,4 @@
org.slf4j.simpleLogger.log.com.jayway=debug
org.slf4j.simpleLogger.log.com.jayway.jsonpath.internal.filter=trace
#org.slf4j.simpleLogger.log.com.jayway=debug
#org.slf4j.simpleLogger.log.com.jayway.jsonpath.internal.filter=trace

Loading…
Cancel
Save