Skip to content

Commit a614e7b

Browse files
committed
format&clean example
1 parent 3f7dc2a commit a614e7b

13 files changed

+139
-142
lines changed

hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/Example1.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,6 @@
2121
import java.util.Iterator;
2222
import java.util.List;
2323

24-
import org.apache.tinkerpop.gremlin.process.traversal.P;
25-
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
26-
import org.apache.tinkerpop.gremlin.structure.Edge;
27-
import org.apache.tinkerpop.gremlin.structure.Graph;
28-
import org.apache.tinkerpop.gremlin.structure.T;
29-
import org.apache.tinkerpop.gremlin.structure.Vertex;
30-
import org.slf4j.Logger;
31-
3224
import org.apache.hugegraph.HugeFactory;
3325
import org.apache.hugegraph.HugeGraph;
3426
import org.apache.hugegraph.backend.BackendException;
@@ -45,6 +37,13 @@
4537
import org.apache.hugegraph.type.define.Directions;
4638
import org.apache.hugegraph.type.define.HugeKeys;
4739
import org.apache.hugegraph.util.Log;
40+
import org.apache.tinkerpop.gremlin.process.traversal.P;
41+
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
42+
import org.apache.tinkerpop.gremlin.structure.Edge;
43+
import org.apache.tinkerpop.gremlin.structure.Graph;
44+
import org.apache.tinkerpop.gremlin.structure.T;
45+
import org.apache.tinkerpop.gremlin.structure.Vertex;
46+
import org.slf4j.Logger;
4847

4948
public class Example1 {
5049

@@ -79,9 +78,9 @@ private static void thread(HugeGraph graph) throws InterruptedException {
7978
graph.tx().commit();
8079

8180
// New tx
82-
GraphTransaction tx = Whitebox.invoke(graph.getClass(),
83-
"openGraphTransaction",
84-
graph);
81+
GraphTransaction tx = Whitebox.invoke(graph.getClass(),
82+
"openGraphTransaction",
83+
graph);
8584

8685
tx.addVertex(T.label, "book", "name", "java-21");
8786
tx.addVertex(T.label, "book", "name", "java-22");
@@ -214,13 +213,13 @@ public static void loadData(final HugeGraph graph) {
214213
graph.tx().commit();
215214

216215
// must commit manually with new backend tx (independent of tinkerpop)
217-
GraphTransaction tx = Whitebox.invoke(graph.getClass(),
218-
"openGraphTransaction",
219-
graph);
216+
GraphTransaction tx = Whitebox.invoke(graph.getClass(),
217+
"openGraphTransaction",
218+
graph);
220219

221220
LOG.info("=============== addVertex ================");
222221
Vertex james = tx.addVertex(T.label, "author", "id", 1,
223-
"name", "James Gosling", "age", 62,
222+
"name", "James Gosling", "age", 62,
224223
"lived", "San Francisco Bay Area");
225224

226225
Vertex java = tx.addVertex(T.label, "language", "name", "java",

hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/Example2.java

+21-22
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919

2020
import java.util.List;
2121

22+
import org.apache.hugegraph.HugeFactory;
23+
import org.apache.hugegraph.HugeGraph;
24+
import org.apache.hugegraph.schema.SchemaManager;
25+
import org.apache.hugegraph.util.Log;
2226
import org.apache.tinkerpop.gremlin.process.traversal.P;
2327
import org.apache.tinkerpop.gremlin.process.traversal.Path;
2428
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
@@ -29,11 +33,6 @@
2933
import org.apache.tinkerpop.gremlin.structure.Vertex;
3034
import org.slf4j.Logger;
3135

32-
import org.apache.hugegraph.HugeFactory;
33-
import org.apache.hugegraph.HugeGraph;
34-
import org.apache.hugegraph.schema.SchemaManager;
35-
import org.apache.hugegraph.util.Log;
36-
3736
public class Example2 {
3837

3938
private static final Logger LOG = Log.logger(Example2.class);
@@ -93,7 +92,7 @@ public static void traversal(final HugeGraph graph) {
9392

9493
String person = graph.schema().getVertexLabel("person").id().asString();
9594
String software = graph.schema().getVertexLabel("software").id()
96-
.asString();
95+
.asString();
9796
String markoId = String.format("%s:%s", person, "marko");
9897
String joshId = String.format("%s:%s", person, "josh");
9998
String lopId = String.format("%s:%s", software, "lop");
@@ -122,30 +121,30 @@ public static void traversal(final HugeGraph graph) {
122121
assert paths.get(0).get(1).equals("lop");
123122

124123
LOG.info(">>>> query with out() optimize: {}",
125-
graph.traversal().V(markoId)
126-
.out()
127-
.out()
128-
.values("name").toList());
124+
graph.traversal().V(markoId)
125+
.out()
126+
.out()
127+
.values("name").toList());
129128

130129
LOG.info(">>>> query with out() optimize and path(): {}",
131-
graph.traversal().V()
132-
.out("knows")
133-
.out("created")
134-
.values("name")
135-
.path()
136-
.toList());
130+
graph.traversal().V()
131+
.out("knows")
132+
.out("created")
133+
.values("name")
134+
.path()
135+
.toList());
137136
}
138137

139138
public static List<Path> shortestPath(final HugeGraph graph,
140139
Object from, Object to,
141140
int maxDepth) {
142141
GraphTraversal<Vertex, Path> t = graph.traversal()
143-
.V(from)
144-
.repeat(__.out().simplePath())
145-
.until(__.hasId(to).or().loops().is(P.gt(maxDepth)))
146-
.hasId(to)
147-
.path().by("name")
148-
.limit(1);
142+
.V(from)
143+
.repeat(__.out().simplePath())
144+
.until(__.hasId(to).or().loops().is(P.gt(maxDepth)))
145+
.hasId(to)
146+
.path().by("name")
147+
.limit(1);
149148
return t.toList();
150149
}
151150

hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/Example3.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717

1818
package org.apache.hugegraph.example;
1919

20-
import org.apache.tinkerpop.gremlin.structure.T;
21-
import org.apache.tinkerpop.gremlin.structure.Vertex;
22-
import org.slf4j.Logger;
23-
2420
import org.apache.hugegraph.HugeFactory;
2521
import org.apache.hugegraph.HugeGraph;
2622
import org.apache.hugegraph.schema.SchemaManager;
2723
import org.apache.hugegraph.util.Log;
24+
import org.apache.tinkerpop.gremlin.structure.T;
25+
import org.apache.tinkerpop.gremlin.structure.Vertex;
26+
import org.slf4j.Logger;
2827

2928
public class Example3 {
3029

hugegraph-server/hugegraph-example/src/main/java/org/apache/hugegraph/example/ExampleUtil.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import org.slf4j.Logger;
3434

3535
public class ExampleUtil {
36+
3637
private static final Logger LOG = Log.logger(ExampleUtil.class);
3738

3839
private static boolean registered = false;
@@ -65,13 +66,13 @@ public static HugeGraph loadGraph(boolean needClear, boolean needProfile) {
6566
String conf = "hugegraph.properties";
6667
try {
6768
String path = ExampleUtil.class.getClassLoader()
68-
.getResource(conf).getPath();
69+
.getResource(conf).getPath();
6970
File file = new File(path);
7071
if (file.exists() && file.isFile()) {
7172
conf = path;
7273
}
7374
} catch (Exception ignored) {
74-
LOG.warn("loadGraph warn {} ",ignored);
75+
LOG.warn("loadGraph warn {} ", ignored);
7576
}
7677

7778
HugeGraph graph = HugeFactory.open(conf);

0 commit comments

Comments
 (0)