bio4j / angulillos

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

Classes all the way down #58

Closed laughedelic closed 8 years ago

laughedelic commented 8 years ago

This is more or less ready as a proof-of-the-concept. source/target, outE/outV, addVertex/addEdge are implemented and seem to work. See the test code for examples of usage.

laughedelic commented 8 years ago

Some summary of what we have with this approach. Actually, this version is not less verbose than what we have from #57:

This approach has its advantages and disadvantages:

laughedelic commented 8 years ago
laughedelic commented 8 years ago

I was looking for some information about self-reference pattern in Java and I found this SO answer plus some other places, where people write that the bound on the self-type parameter

class Foo<F extends Foo<F>>

is an illusion of safety and does not enforce F to be self-reference. I still can write

  public final class Tweet extends VertexType<User> {
    @Override public User self() { return user; }
    ...
  }

P.S. this just means that we cannot refer to the self-type in the abstract code when using something specific about its instance. So I'll just write VertexType<...>.Vertex where needed. It does not influence the way this is used (e.g. things like TwitterSchema<RV,RE>.User.Vertex will be fine and correct). I already had this before 758be84.

eparejatobes commented 8 years ago

Yup, http://stackoverflow.com/a/14755312/614394

It's not exactly the same with mutually recursive parameters, though.

eparejatobes commented 8 years ago

About the warnings: my somewhat cryptic (writing from my phone) comment https://github.com/bio4j/angulillos/pull/58#discussion_r57641702 tried to imply that for that you'd need to make everything inner classes. If so, it should probably work.

laughedelic commented 8 years ago
laughedelic commented 8 years ago

Good news @eparejatobes!!! We don't have to change anything related to the inner-classes.

I was about to fall asleep when I suddenly realised that the problem in the above mentioned example is in the misuse of the types there. First, there is

G extends TwitterSchema<RV,RE>

then

protected G g;

and then I was trying to create a user-vertex: g.user.addVertex() and of course it didn't match the type TwitterSchema<RV,RE>.User.Vertex, because its type is G.User.Vertex!

// This warns about unchecked conversion:
TwitterSchema<RV,RE>.User.Vertex tu = g.user.addVertex();

// This is correct:
G.User.Vertex gu = g.user.addVertex();

// This won't compile:
VertexType<G.User, G,RV,RE>.Vertex gu2 = g.user.addVertex();
// Neither this:
G.VertexType<G.User>.Vertex gu3 = g.user.addVertex();

I think that the warning message is just very confusing, showing as the "found" type com.bio4j.angulillos.VertexType.Vertex, which is being read literally just isn't true.

eparejatobes commented 8 years ago

@laughedelic but then you'd need to add suppress warnings to all methods, basically because we cannot know that G has the same RV,RE.

laughedelic commented 8 years ago

Replaced by #62