bio4j / angulillos

Java 8 library for strongly typed graph data
GNU Affero General Public License v3.0
7 stars 2 forks source link

Don't use properties through the element values #62

Closed laughedelic closed 8 years ago

laughedelic commented 8 years ago

I've already started some changes in master accidentally. Starting from what we had before the #58:

We can add properties as the members of the User value-type and add setter/getter methods, then the syntax for working with them would change from

Tweetter<RV,RE>.User bob =
  g.addVertex(g.user)
   .set(g.user.name, "Bob");

String name = bob.get(g.user.name);

bob.set(g.user.age, 42);

to

Tweetter<RV,RE>.User bob =
  g.addVertex(g.user)
   .name.set("Bob");

String name = bob.name.get();

bob.age.set(42);

which doesn't look too bad and is more concise than the old one. Btw, I've tried to make them instances of Supplier<X> (for the .get() method) and Function<V,X> (for .apply()) hoping that it will allow for syntax like bob.name("Bob") instead of bob.name.apply("Bob"), but it seems that Java doesn't have any shortcuts "( :-1:

The schema definition becomes much more clear than before and almost doesn't have boilerplate code:

public final class User extends Vertex<User> {
  @Override public final User self() { return this; }
  private User(RV raw) { super(raw, user); }

  public final Property<String> name = property("name", String.class);
  public final Property<Integer> age = property("age", Integer.class);
}

public final VertexType<User> user = new VertexType<>(User::new);

No any significant changes to the inner code needed. Only the GraphSchema class.

laughedelic commented 8 years ago

@eparejatobes please, take a look :pray:

After all my suffering in #58 and #60 and experimenting with things in #61 and some other branches that don't worth to be pushed here, I can say that what I have here is the best option I can get (again, I was trying really hard, you know :neutral_face:).

Using inner classes as in #58 doesn't help to simplify the API and it has a major disadvantage: it's hard to override methods in them. I'm even not sure if it's possible to do in any reasonable way, because if you subclass and have a more precise User.Vertex type, all its non-overriden API methods still return the type of the inner class from its parent.

Therefore I think it's better to use inner classes only on the level of the schema definition (i.e. VertexType/EdgeType inside of a TypedGraph/GraphSchema).

Putting all things in one file doesn't help anything, see https://github.com/bio4j/angulillos/pull/60#issuecomment-205377558.

So, what we have here:

If you are fine with this approach, I will cherry-pick good things from #58, especially the auto-schema-related stuff from #59.

We can already try this with some Bio4j graph. The Titan implementation should work (modulo the schema creation).

UPD: currently angulillos-titan compiles without any changes.

eparejatobes commented 8 years ago

@laughedelic I'm going to look at this tonight/tomorrow morning.

laughedelic commented 8 years ago

What I'm working on here:

laughedelic commented 8 years ago
laughedelic commented 8 years ago

I'm merging and releasing it as v0.7.0