Skip to content

Commit

Permalink
Merge branch 'refactor-dom-builder'
Browse files Browse the repository at this point in the history
  • Loading branch information
wanglingsong committed Nov 12, 2015
2 parents e53ebc9 + b779b10 commit 97e518e
Show file tree
Hide file tree
Showing 16 changed files with 483 additions and 330 deletions.
2 changes: 1 addition & 1 deletion jsurfer-benchmark/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsurfer</artifactId>
<groupId>com.github.jsurfer</groupId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/*
* The MIT License
*
* Copyright (c) 2015 WANG Lingsong
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

package org.jsfr.json;

import com.google.common.io.Resources;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
import org.openjdk.jmh.annotations.State;
import org.openjdk.jmh.annotations.Threads;
import org.openjdk.jmh.annotations.Warmup;
import org.openjdk.jmh.infra.Blackhole;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

import java.nio.charset.StandardCharsets;
import java.util.Map;
import java.util.concurrent.TimeUnit;

@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(1)
@Fork(1)
@State(Scope.Benchmark)
public class BenchmarkCollectObject {

private JsonSurfer gsonSurfer;
private JsonSurfer jacksonSurfer;
private JsonSurfer simpleSurfer;
private SurfingConfiguration surfingConfiguration;
private String json;

@Setup
public void setup() throws Exception {
gsonSurfer = JsonSurfer.gson();
jacksonSurfer = JsonSurfer.jackson();
simpleSurfer = JsonSurfer.simple();
TypedJsonPathListener collectOneListener = new TypedJsonPathListener() {

private Blackhole blackhole = new Blackhole();

@Override
public void onTypedValue(Object value, ParsingContext context) throws Exception {
blackhole.consume(value);
}
};
surfingConfiguration = SurfingConfiguration.builder().bind("$.store.book[*]", Map.class, collectOneListener).build();
json = Resources.toString(Resources.getResource("sample.json"), StandardCharsets.UTF_8);
}


@Benchmark
public boolean benchmarkGsonWithJsonSurfer() {
gsonSurfer.surf(json, surfingConfiguration);
return true;
}

@Benchmark
public boolean benchmarkJacksonWithJsonSurfer() {
jacksonSurfer.surf(json, surfingConfiguration);
return true;
}

@Benchmark
public boolean benchmarkJsonSimpleWithJsonSurfer() {
simpleSurfer.surf(json, surfingConfiguration);
return true;
}

public static void main(String[] args) throws RunnerException {
Options opt = new OptionsBuilder()
.include(BenchmarkCollectObject.class.getSimpleName())
// .addProfiler(FlightRecordingProfiler.class)
.build();
new Runner(opt).run();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
* Created by Administrator on 2015/7/20 0020.
*/
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
* Created by Administrator on 2015/7/18 0018.
*/
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS)
@Threads(1)
Expand Down
2 changes: 1 addition & 1 deletion jsurfer-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>jsurfer</artifactId>
<groupId>com.github.jsurfer</groupId>
<version>1.2.6</version>
<version>1.2.7</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
39 changes: 0 additions & 39 deletions jsurfer-core/src/main/java/org/jsfr/json/BuilderFactory.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@
import java.util.Iterator;
import java.util.LinkedList;

/**
* Created by Administrator on 2015/3/21.
*/
class ContentDispatcher implements JsonSaxHandler {

private LinkedList<JsonSaxHandler> receiver = new LinkedList<JsonSaxHandler>();
Expand Down
31 changes: 4 additions & 27 deletions jsurfer-core/src/main/java/org/jsfr/json/JsonCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,13 @@

import java.util.Collection;

/**
* Created by Administrator on 2015/3/21.
*/
class JsonCollector extends JsonDomBuilder {

private ErrorHandlingStrategy errorHandlingStrategy;
private JsonPathListener[] jsonPathListeners;
private Collection<JsonPathListener> jsonPathListeners;
private ParsingContext context;

public JsonCollector(JsonPathListener[] jsonPathListeners, ParsingContext context, ErrorHandlingStrategy errorHandlingStrategy) {
public JsonCollector(Collection<JsonPathListener> jsonPathListeners, ParsingContext context, ErrorHandlingStrategy errorHandlingStrategy) {
this.jsonPathListeners = jsonPathListeners;
this.context = context;
this.errorHandlingStrategy = errorHandlingStrategy;
Expand All @@ -45,7 +42,7 @@ public JsonCollector(JsonPathListener[] jsonPathListeners, ParsingContext contex
public boolean endObject() {
super.endObject();
if (isInRoot()) {
Object result = getCurrentNode();
Object result = peekValue();
for (JsonPathListener jsonPathListener : jsonPathListeners) {
if (!context.isStopped()) {
try {
Expand All @@ -65,27 +62,7 @@ public boolean endObject() {
public boolean endArray() {
super.endArray();
if (isInRoot()) {
Object result = getCurrentNode();
for (JsonPathListener jsonPathListener : jsonPathListeners) {
if (!context.isStopped()) {
try {
jsonPathListener.onValue(result, context);
} catch (Exception e) {
errorHandlingStrategy.handleExceptionFromListener(e, context);
}
}
}
this.clear();
return false;
}
return true;
}

@Override
public boolean primitive(PrimitiveHolder value) {
super.primitive(value);
if (isInRoot()) {
Object result = getCurrentNode();
Object result = peekValue();
for (JsonPathListener jsonPathListener : jsonPathListeners) {
if (!context.isStopped()) {
try {
Expand Down
Loading

0 comments on commit 97e518e

Please sign in to comment.