Closed oleghailenko closed 6 years ago
This is normal behavior and expected (for several reasons). When you do a next call it will cast the object into that type regardless of what type it is in the graph, however if it is a subtype int he graph it will instantiate as the subtype.
To do what you want to do you have to invoke the typeresolver's hasType method which will filter only by type (it takes the class you want to filter by).
@oleghailenko Here is one of our unit tests that shows the proper way to do what your trying to do
@Test
public void testHasTypeParentFromPackage() {
final Graph godGraph = TinkerGraph.open();
final FramedGraph framedGraph = new DelegatingFramedGraph(godGraph, TEST_MODEL_PACKAGE);
//add a single node to the graph, a programmer.
framedGraph.addFramedVertex(Programmer.class);
//make sure the newly added node is actually a programmer
final Person programmer = framedGraph.traverse(input -> framedGraph.getTypeResolver().hasType(input.V(), Person.class)).next(Person.class);
Assert.assertTrue(programmer instanceof Programmer);
//change the type resolution to person
programmer.setTypeResolution(Person.class);
//make sure the newly added node is not actually a programmer
final Person person = framedGraph.traverse(input -> input.V()).next(Person.class);
Assert.assertFalse(person instanceof Programmer);
}
@oleghailenko closing this but feel free to continue to comment or reopen.
Hello guys. I have found some unexpected behaviour of using framed graph. Let's assume we have 2 classes
A
andB
. Each of them have the same propertyname
. In the graph are two objects: objectA
withname
=a
, and objectB
with name =b
. But if I am trying to traverse over graph to grab object withname
=b
and get object of kindA
using method next... I am getting objectA
. Here is code:Is it expected behavior? I did not found any information about this in the documentation.
I am using ferma version 3.2.1