Closed laughedelic closed 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:
V,VT
pairs, because V
is now an inner class Vertex
of VT
VT.Vertex
anywhere! :weary: (unless VT
is a concrete class, like User
)VT extends VertexType<VT, G,RV,RE>
, everywhere we want to refer to its Vertex
inner class, we have to write VertexType<VT, G,RV,RE>.Vertex
:-1:VT
's parameters if we are going to return a value that uses them, because we cannot return VertexType<VT, ?,RV,RE>.Vertex
This approach has its advantages and disadvantages:
VertexType<VT, G,RV,RE>.Vertex
everywhere makes this approach quite verbose. Although it's only in the library inner code. Once you define schema, you don't need to worry about it. You will get your TwitterSchema<RV,RE>.Tweet.Vertex
.VT.Vertex
instead of VertexType<VT,G,RV,RE>.Vertex
), even if the "unchecked call" warning has to be suppressed (in .fromRaw()
TypedGraph
class (move here things from GraphSchema
)UntypedGraph
with default impl-sLinkGraph
with explicit references to the two graph it's connectingI 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.
Yup, http://stackoverflow.com/a/14755312/614394
It's not exactly the same with mutually recursive parameters, though.
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.
self()
protectedVertexType<VT, ...>.Vertex
everywhere)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.
@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
.
Replaced by #62
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.