Commit bcfa674b authored by Jeffrey Phillips Freeman's avatar Jeffrey Phillips Freeman 💥 Committed by GitHub
Browse files

docs: Added syntax highlighting to readme.

parent 4edd7b68
......@@ -84,55 +84,59 @@ instruct Ferma to dynamically construct byte-code to implement the abstract meth
In untyped mode there is no automatic typing. Whatever class is explicitly indicated is the type that will be
instantiated when performing queries. Lets start with a simple example domain.
public class Person extends AbstractVertexFrame {
public String getName() {
return getProperty("name");
}
public void setName(String name) {
setProperty("name", name);
}
public List<? extends Knows> getKnowsList() {
return traverse((v) -> v.outE("knows")).toList(Knows.class);
}
public Knows addKnows(Person friend) {
return addEdge("knows", friend, Knows.class);
}
}
public class Knows extends EdgeFrame {
public void setYears(int years) {
setProperty("years", years);
}
public int getYears() {
return getProperty("years");
}
}
```java
public class Person extends AbstractVertexFrame {
public String getName() {
return getProperty("name");
}
public void setName(String name) {
setProperty("name", name);
}
public List<? extends Knows> getKnowsList() {
return traverse((v) -> v.outE("knows")).toList(Knows.class);
}
public Knows addKnows(Person friend) {
return addEdge("knows", friend, Knows.class);
}
}
public class Knows extends EdgeFrame {
public void setYears(int years) {
setProperty("years", years);
}
public int getYears() {
return getProperty("years");
}
}
```
And here is how you interact with the framed elements:
public void testUntyped() {
Graph g = new TinkerGraph();
```java
public void testUntyped() {
Graph g = new TinkerGraph();
// implies untyped mode
FramedGraph fg = new DelegatingFramedGraph(g);
// implies untyped mode
FramedGraph fg = new DelegatingFramedGraph(g);
Person p1 = fg.addFramedVertex(Person.class);
p1.setName("Jeff");
Person p1 = fg.addFramedVertex(Person.class);
p1.setName("Jeff");
Person p2 = fg.addFramedVertex(Person.class);
p2.setName("Julia");
Knows knows = p1.addKnows(p2);
knows.setYears(15);
Person p2 = fg.addFramedVertex(Person.class);
p2.setName("Julia");
Knows knows = p1.addKnows(p2);
knows.setYears(15);
Person jeff = fg.traverse((g) -> g.v().has("name", "Jeff")).next(Person.class);
Person jeff = fg.traverse((g) -> g.v().has("name", "Jeff")).next(Person.class);
Assert.assertEquals("Jeff", jeff.getName());
}
Assert.assertEquals("Jeff", jeff.getName());
}
```
### Simple Mode Example
......@@ -143,29 +147,33 @@ reading from the graph.
Say we extend the Person class with the Programmer class.
public class Programmer extends Person {
}
```java
public class Programmer extends Person {
}
```
Using simple mode will save the type of Java class the element was created with for use later:
public void testSimpleTyping() {
Graph g = new TinkerGraph();
// implies simple mode
FramedGraph fg = new DelegatingFramedGraph(g, true, false);
Person p1 = fg.addFramedVertex(Programmer.class);
p1.setName("Jeff");
Person p2 = fg.addFramedVertex(Person.class);
p2.setName("Julia");
Person jeff = fg.traverse((g) -> g.v().has("name", "Jeff")).next(Person.class);
Person julia = fg.traverse((g) -> g.v().has("name", "Julia")).next(Person.class);
Assert.assertEquals(Programmer.class, jeff.getClass());
Assert.assertEquals(Person.class, julia.getClass());
}
```java
public void testSimpleTyping() {
Graph g = new TinkerGraph();
// implies simple mode
FramedGraph fg = new DelegatingFramedGraph(g, true, false);
Person p1 = fg.addFramedVertex(Programmer.class);
p1.setName("Jeff");
Person p2 = fg.addFramedVertex(Person.class);
p2.setName("Julia");
Person jeff = fg.traverse((g) -> g.v().has("name", "Jeff")).next(Person.class);
Person julia = fg.traverse((g) -> g.v().has("name", "Julia")).next(Person.class);
Assert.assertEquals(Programmer.class, jeff.getClass());
Assert.assertEquals(Person.class, julia.getClass());
}
```
### Annotated Mode Example
......@@ -177,71 +185,74 @@ power to determine parent-child relationships at runtime.
The same example as above done with annotations would look something like this.
public abstract class Person extends AbstractVertexFrame {
@Property("name")
public abstract String getName();
```java
public abstract class Person extends AbstractVertexFrame {
@Property("name")
public abstract String getName();
@Property("name")
public abstract void setName(String name);
@Property("name")
public abstract void setName(String name);
@Adjacency("knows")
public abstract Iterator<Person> getKnowsPeople();
@Adjacency("knows")
public abstract Iterator<Person> getKnowsPeople();
@Incidence("knows")
public abstract Iterator<Knows> getKnows();
@Incidence("knows")
public abstract Iterator<Knows> getKnows();
@Incidence("knows")
public abstract Knows addKnows(Person friend);
@Incidence("knows")
public abstract Knows addKnows(Person friend);
public List<Person> getFriendsNamedBill() {
return traverse((v) -> v.out("knows").has("name", "bill").toList(Person.class);
}
}
public List<Person> getFriendsNamedBill() {
return traverse((v) -> v.out("knows").has("name", "bill").toList(Person.class);
}
}
public abstract class Knows extends AbstractEdgeFrame {
@Property("years")
public abstract void setYears(int years);
public abstract class Knows extends AbstractEdgeFrame {
@Property("years")
public abstract void setYears(int years);
@Property("years")
public abstract int getYears();
@Property("years")
public abstract int getYears();
@InVertex
public abstract Person getIn();
@InVertex
public abstract Person getIn();
@OutVertex
public abstract Person getIn();
}
@OutVertex
public abstract Person getIn();
}
public abstract class Programmer extends Person {
}
public abstract class Programmer extends Person {
}
```
If we pass a collection of Class objects to the FramedGraph constructor then the annotated type resolver will be used.
In this mode you want to tell the engine what classes you will be using so it can handle type resolution properly and
construct the byte-code for any abstract annotated methods.
public void testAnnotatedTyping() {
Set<Class<?>> types = new HashSet<Class<?>>(Arrays.asList(new Class<?>[]{
Person.class,
Programmer.class,
Knows.class}));
Graph g = new TinkerGraph();
```java
public void testAnnotatedTyping() {
Set<Class<?>> types = new HashSet<Class<?>>(Arrays.asList(new Class<?>[]{
Person.class,
Programmer.class,
Knows.class}));
Graph g = new TinkerGraph();
//implies annotated mode
FramedGraph fg = new DelegatingFramedGraph(g, true, types);
//implies annotated mode
FramedGraph fg = new DelegatingFramedGraph(g, true, types);
Person p1 = fg.addFramedVertex(Programmer.class);
p1.setName("Jeff");
Person p1 = fg.addFramedVertex(Programmer.class);
p1.setName("Jeff");
Person p2 = fg.addFramedVertex(Person.class);
p2.setName("Julia");
Person p2 = fg.addFramedVertex(Person.class);
p2.setName("Julia");
Person jeff = fg.traverse((g) -> g.v().has("name", "Jeff")).next(Person.class);
Person julia = fg.traverse((g) -> g.v().has("name", "Julia")).next(Person.class);
Person jeff = fg.traverse((g) -> g.v().has("name", "Jeff")).next(Person.class);
Person julia = fg.traverse((g) -> g.v().has("name", "Julia")).next(Person.class);
Assert.assertEquals(Programmer.class, jeff.getClass());
Assert.assertEquals(Person.class, julia.getClass());
}
Assert.assertEquals(Programmer.class, jeff.getClass());
Assert.assertEquals(Person.class, julia.getClass());
}
```
## Obtaining the Source
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment