org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree Java Examples
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkergraph-gremlin with Apache License 2.0 | 6 votes |
@Test @org.junit.Ignore("https://issues.apache.org/jira/browse/TINKERPOP-1509") public void deserializersTestsTree() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Tree t = tg.traversal().V().out().out().tree().next(); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, t); final String json = out.toString(); final Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //Map's equals should check each component of the tree recursively //on each it will call "equals()" which for Vertices will compare ids, which //is ok. Complete vertex deser is checked elsewhere. assertEquals(t, treeRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example #2
Source File: GryoMessageSerializerV1d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldSerializeTree() throws Exception { final Graph g = TinkerFactory.createModern(); final Tree t = g.traversal().V().out().out().tree().by("name").next(); final ResponseMessage response = convertBinary(t); assertCommon(response); final Tree deserialized = (Tree) response.getResult().getData(); assertEquals(t, deserialized); assertThat(deserialized.containsKey("marko"), is(true)); assertEquals(1, deserialized.size()); final Tree markoChildren = (Tree) deserialized.get("marko"); assertThat(markoChildren.containsKey("josh"), is(true)); assertEquals(1, markoChildren.size()); final Tree joshChildren = (Tree) markoChildren.get("josh"); assertThat(joshChildren.containsKey("lop"), is(true)); assertThat(joshChildren.containsKey("ripple"), is(true)); assertEquals(2, joshChildren.size()); }
Example #3
Source File: GraphSONSerializersV1d0.java From tinkerpop with Apache License 2.0 | 6 votes |
private static void ser(final Tree tree, final JsonGenerator jsonGenerator, final TypeSerializer typeSerializer) throws IOException { jsonGenerator.writeStartObject(); if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName()); Set<Map.Entry<Element, Tree>> set = tree.entrySet(); for(Map.Entry<Element, Tree> entry : set) { jsonGenerator.writeObjectFieldStart(entry.getKey().id().toString()); if (typeSerializer != null) jsonGenerator.writeStringField(GraphSONTokens.CLASS, HashMap.class.getName()); jsonGenerator.writeObjectField(GraphSONTokens.KEY, entry.getKey()); jsonGenerator.writeObjectField(GraphSONTokens.VALUE, entry.getValue()); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndObject(); }
Example #4
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTree() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V1_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Tree before = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, before); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Tree after = gryoReader.readObject(inputStream, Tree.class); assertNotNull(after); //The following assertions should be sufficent. assertThat("Type does not match", after, instanceOf(Tree.class)); assertEquals("The objects differ", after, before); }
Example #5
Source File: AbstractTypedCompatibilityTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test public void shouldReadWriteTree() throws Exception { final String resourceName = "tree"; assumeCompatibility(resourceName); final Tree resource = findModelEntryObject(resourceName); final Tree fromStatic = read(getCompatibility().readFromResource(resourceName), Tree.class); final Tree recycled = read(write(fromStatic, Tree.class), Tree.class); assertNotSame(fromStatic, recycled); assertEquals(resource.size(), fromStatic.size()); assertVertex((Vertex) resource.keySet().iterator().next(), (Vertex) fromStatic.keySet().iterator().next()); assertEquals(resource.getLeafObjects().size(), fromStatic.getLeafObjects().size()); assertVertex((Vertex) resource.getLeafObjects().get(0), (Vertex) fromStatic.getLeafObjects().get(0)); assertEquals(resource.getObjectsAtDepth(1).size(), fromStatic.getObjectsAtDepth(1).size()); assertVertex((Vertex) resource.getObjectsAtDepth(1).get(0), (Vertex) fromStatic.getObjectsAtDepth(1).get(0)); assertEquals(resource.size(), recycled.size()); assertVertex((Vertex) resource.keySet().iterator().next(), (Vertex) recycled.keySet().iterator().next()); assertEquals(resource.getLeafObjects().size(), recycled.getLeafObjects().size()); assertVertex((Vertex) resource.getLeafObjects().get(0), (Vertex) recycled.getLeafObjects().get(0)); assertEquals(resource.getObjectsAtDepth(1).size(), recycled.getObjectsAtDepth(1).size()); assertVertex((Vertex) resource.getObjectsAtDepth(1).get(0), (Vertex) recycled.getObjectsAtDepth(1).get(0)); }
Example #6
Source File: SerializationTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTree() throws Exception { final GryoIo gryoIo = graph.io(GryoIo.build(GryoVersion.V3_0)); final GryoWriter gryoWriter = gryoIo.writer().create(); final GryoReader gryoReader = gryoIo.reader().create(); final Tree before = g.V(convertToVertexId("marko")).out().properties("name").tree().next(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gryoWriter.writeObject(outputStream, before); final ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray()); final Tree after = gryoReader.readObject(inputStream, Tree.class); assertNotNull(after); //The following assertions should be sufficent. assertThat("Type does not match", after, instanceOf(Tree.class)); assertEquals("The objects differ", after, before); }
Example #7
Source File: TinkerGraphGraphSONSerializerV2d0Test.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @org.junit.Ignore("https://issues.apache.org/jira/browse/TINKERPOP-1509") public void deserializersTestsTree() { final TinkerGraph tg = TinkerFactory.createModern(); final GraphWriter writer = getWriter(defaultMapperV2d0); final GraphReader reader = getReader(defaultMapperV2d0); final Tree t = tg.traversal().V().out().out().tree().next(); try (final ByteArrayOutputStream out = new ByteArrayOutputStream()) { writer.writeObject(out, t); final String json = out.toString(); final Tree treeRead = (Tree)reader.readObject(new ByteArrayInputStream(json.getBytes()), Object.class); //Map's equals should check each component of the tree recursively //on each it will call "equals()" which for Vertices will compare ids, which //is ok. Complete vertex deser is checked elsewhere. assertEquals(t, treeRead); } catch (IOException e) { e.printStackTrace(); fail("Should not have thrown exception: " + e.getMessage()); } }
Example #8
Source File: GraphSONSerializersV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final Tree tree, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException, JsonGenerationException { jsonGenerator.writeStartArray(); final Set<Map.Entry<Element, Tree>> set = tree.entrySet(); for (Map.Entry<Element, Tree> entry : set) { jsonGenerator.writeStartObject(); jsonGenerator.writeObjectField(GraphSONTokens.KEY, entry.getKey()); jsonGenerator.writeObjectField(GraphSONTokens.VALUE, entry.getValue()); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); }
Example #9
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_out_out_out_tree() { final Traversal<Vertex, Tree> traversal = get_g_V_out_out_out_tree(); printTraversalForm(traversal); final Tree tree = traversal.next(); assertTrue(tree.isEmpty()); assertFalse(traversal.hasNext()); }
Example #10
Source File: TreeSerializer.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected void writeValue(final Tree value, final Buffer buffer, final GraphBinaryWriter context) throws IOException { buffer.writeInt(value.size()); for (Object key : value.keySet()) { context.write(key, buffer); context.writeValue(value.get(key), buffer, false); } }
Example #11
Source File: GraphSONSerializersV2d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public void serialize(final Tree tree, final JsonGenerator jsonGenerator, final SerializerProvider serializerProvider) throws IOException, JsonGenerationException { jsonGenerator.writeStartArray(); final Set<Map.Entry<Element, Tree>> set = tree.entrySet(); for (Map.Entry<Element, Tree> entry : set) { jsonGenerator.writeStartObject(); jsonGenerator.writeObjectField(GraphSONTokens.KEY, entry.getKey()); jsonGenerator.writeObjectField(GraphSONTokens.VALUE, entry.getValue()); jsonGenerator.writeEndObject(); } jsonGenerator.writeEndArray(); }
Example #12
Source File: GraphSONSerializersV3d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Tree deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final List<Map> data = deserializationContext.readValue(jsonParser, List.class); final Tree t = new Tree(); for (Map<String, Object> entry : data) { t.put(entry.get(GraphSONTokens.KEY), entry.get(GraphSONTokens.VALUE)); } return t; }
Example #13
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_VX1X_out_out_tree_byXnameX() { final Traversal<Vertex, Tree> traversal = get_g_VX1X_out_out_tree_byXnameX(convertToVertexId("marko")); printTraversalForm(traversal); assertCommonA(traversal); }
Example #14
Source File: GraphSONTypeIdResolver.java From tinkerpop with Apache License 2.0 | 5 votes |
public GraphSONTypeIdResolver addCustomType(final String name, final Class clasz) { if (Tree.class.isAssignableFrom(clasz)) { // there is a special case for Tree which extends a Map, but has only 1 parametrized type, // and for which creating a default type is failing because it may fall into a // a self-referencing never-ending loop. Temporarily we force Tree<Element> // which should cover all the usage TinkerPop would do of the Trees anyway. idToType.put(name, TypeFactory.defaultInstance().constructType(new TypeReference<Tree<? extends Element>>() {})); } else { idToType.put(name, TypeFactory.defaultInstance().constructType(clasz)); } typeToId.put(clasz, name); return this; }
Example #15
Source File: TypeSerializerFailureTests.java From tinkerpop with Apache License 2.0 | 5 votes |
@Parameterized.Parameters(name = "Value={0}") public static Collection input() { final Bytecode.Binding b = new Bytecode.Binding(null, "b"); final ReferenceVertex vertex = new ReferenceVertex("a vertex", null); final Bytecode bytecode = new Bytecode(); bytecode.addStep(null); final BulkSet<Object> bulkSet = new BulkSet<>(); bulkSet.add(vertex, 1L); final MutableMetrics metrics = new MutableMetrics("a metric", null); final Tree<Vertex> tree = new Tree<>(); tree.put(vertex, null); // Provide instances that are malformed for serialization to fail return Arrays.asList( b, vertex, Collections.singletonMap("one", b), bulkSet, bytecode, Collections.singletonList(vertex), new ReferenceEdge("an edge", null, vertex, vertex), Lambda.supplier(null), metrics, new DefaultTraversalMetrics(1L, Collections.singletonList(metrics)), new DefaultRemoteTraverser<>(new Object(), 1L), tree, new ReferenceVertexProperty<>("a prop", null, "value"), new InvalidPath() ); }
Example #16
Source File: GraphSONSerializersV2d0.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override public Tree deserialize(final JsonParser jsonParser, final DeserializationContext deserializationContext) throws IOException, JsonProcessingException { final List<Map> data = deserializationContext.readValue(jsonParser, List.class); final Tree t = new Tree(); for (Map<String, Object> entry : data) { t.put(entry.get(GraphSONTokens.KEY), entry.get(GraphSONTokens.VALUE)); } return t; }
Example #17
Source File: TreeSerializer.java From tinkerpop with Apache License 2.0 | 5 votes |
@Override protected Tree readValue(final Buffer buffer, final GraphBinaryReader context) throws IOException { final int length = buffer.readInt(); final Tree result = new Tree(); for (int i = 0; i < length; i++) { result.put(context.read(buffer), context.readValue(buffer, Tree.class, false)); } return result; }
Example #18
Source File: SortedTree.java From sqlg with MIT License | 5 votes |
@SuppressWarnings("WeakerAccess") public void addTree(final Tree<T> tree) { tree.forEach((k, v) -> { if (this.containsKey(k)) { this.get(k).addTree(v); } else { SortedTree<T> sortedTree = new SortedTree<>(this.comparator()); this.put(k, sortedTree); sortedTree.addTree(v); } }); }
Example #19
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
private void assertCommonC(Traversal<Vertex, Tree> traversal) { final Tree tree = traversal.next(); assertFalse(traversal.hasNext()); assertEquals(1, tree.size()); assertTrue(tree.containsKey(convertToVertex(graph, "marko"))); assertEquals(1, ((Map) tree.get(convertToVertex(graph, "marko"))).size()); assertTrue(((Map) tree.get(convertToVertex(graph, "marko"))).containsKey(convertToVertex(graph, "josh"))); assertTrue(((Map) ((Map) tree.get(convertToVertex(graph, "marko"))).get(convertToVertex(graph, "josh"))).containsKey(convertToVertex(graph, "lop"))); assertTrue(((Map) ((Map) tree.get(convertToVertex(graph, "marko"))).get(convertToVertex(graph, "josh"))).containsKey(convertToVertex(graph, "ripple"))); }
Example #20
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_out_out_treeXaX_capXaX() { final Traversal<Vertex, Tree> traversal = get_g_V_out_out_treeXaX_capXaX(); printTraversalForm(traversal); assertCommonC(traversal); }
Example #21
Source File: TreeSupplierTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldSupplyNewTreeOnEachInvocation() { final Tree<Object> l1 = TreeSupplier.instance().get(); final Tree<Object> l2 = TreeSupplier.instance().get(); final Tree<Object> l3 = TreeSupplier.instance().get(); assertNotSame(l1, l2); assertNotSame(l1, l3); assertNotSame(l2, l3); }
Example #22
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_out_out_tree() { final Traversal<Vertex, Tree> traversal = get_g_V_out_out_tree(); printTraversalForm(traversal); assertCommonC(traversal); }
Example #23
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
private void assertCommonB(Traversal<Vertex, Tree> traversal) { final Tree tree = traversal.next(); assertFalse(traversal.hasNext()); assertEquals(1, tree.size()); assertTrue(tree.containsKey(convertToVertexId("marko"))); assertEquals(1, ((Map) tree.get(convertToVertexId("marko"))).size()); assertTrue(((Map) tree.get(convertToVertexId("marko"))).containsKey(convertToVertexId("josh"))); assertTrue(((Map) ((Map) tree.get(convertToVertexId("marko"))).get(convertToVertexId("josh"))).containsKey(convertToVertexId("lop"))); assertTrue(((Map) ((Map) tree.get(convertToVertexId("marko"))).get(convertToVertexId("josh"))).containsKey(convertToVertexId("ripple"))); }
Example #24
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_out_out_treeXaX_byXidX_capXaX() { final Traversal<Vertex, Tree> traversal = get_g_V_out_out_treeXaX_byXidX_capXaX(); printTraversalForm(traversal); assertCommonB(traversal); }
Example #25
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_out_out_tree_byXidX() { final Traversal<Vertex, Tree> traversal = get_g_V_out_out_tree_byXidX(); printTraversalForm(traversal); assertCommonB(traversal); }
Example #26
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
private static void assertCommonA(final Traversal<Vertex, Tree> traversal) { final Tree tree = traversal.next(); assertFalse(traversal.hasNext()); assertEquals(1, tree.size()); assertTrue(tree.containsKey("marko")); assertEquals(1, ((Map) tree.get("marko")).size()); assertTrue(((Map) tree.get("marko")).containsKey("josh")); assertTrue(((Map) ((Map) tree.get("marko")).get("josh")).containsKey("lop")); assertTrue(((Map) ((Map) tree.get("marko")).get("josh")).containsKey("ripple")); }
Example #27
Source File: TreeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_VX1X_out_out_treeXaX_byXnameX_both_both_capXaX() { final Traversal<Vertex, Tree> traversal = get_g_VX1X_out_out_treeXaX_byXnameX_both_both_capXaX(convertToVertexId("marko")); printTraversalForm(traversal); assertCommonA(traversal); }
Example #28
Source File: GraphSONMessageSerializerV1d0Test.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test public void shouldSerializeToJsonTree() throws Exception { final TinkerGraph graph = TinkerFactory.createClassic(); final GraphTraversalSource g = graph.traversal(); final Tree t = g.V(1).out().properties("name").tree().next(); final String results = SERIALIZER.serializeResponseAsString(ResponseMessage.build(msg).result(t).create()); final JsonNode json = mapper.readTree(results); assertNotNull(json); assertEquals(msg.getRequestId().toString(), json.get(SerTokens.TOKEN_REQUEST).asText()); final JsonNode converted = json.get(SerTokens.TOKEN_RESULT).get(SerTokens.TOKEN_DATA); assertNotNull(converted); //check the first object and it's properties assertEquals(1, converted.get("1").get("key").get("id").asInt()); assertEquals("marko", converted.get("1").get("key").get("properties").get("name").get(0).get("value").asText()); //check objects tree structure //check Vertex property assertEquals("vadas", converted.get("1") .get("value") .get("2") .get("value") .get("3").get("key").get("value").asText()); assertEquals("name", converted.get("1") .get("value") .get("2") .get("value") .get("3").get("key").get("label").asText()); // check subitem assertEquals("lop", converted.get("1") .get("value") .get("3") .get("key") .get("properties").get("name").get(0).get("value").asText()); }
Example #29
Source File: TestIoAgain.java From sqlg with MIT License | 4 votes |
@Test @LoadGraphWith(LoadGraphWith.GraphData.MODERN) public void shouldSerializeTree() throws Exception { loadModern(); final org.apache.tinkerpop.shaded.jackson.databind.ObjectMapper mapper = this.sqlgGraph.io(GraphSONIo.build(GraphSONVersion.V1_0)).mapper().version(GraphSONVersion.V1_0).create().createMapper(); Traversal<Vertex, Tree> traversal = this.sqlgGraph.traversal().V(convertToVertexId("marko")).out().properties("name").tree(); printTraversalForm(traversal); Tree t = traversal.next(); final String json = mapper.writeValueAsString(t); final HashMap<String, Object> m = (HashMap<String, Object>) mapper.readValue(json, mapTypeReference); // Check Structure assertEquals(1, m.size()); assertTrue(m.containsKey(convertToVertexId("marko").toString())); // Check Structure n+1 final HashMap<String, Object> branch = (HashMap<String, Object>) m.get(convertToVertexId("marko").toString()); assertEquals(2, branch.size()); assertTrue(branch.containsKey(GraphSONTokens.KEY)); assertTrue(branch.containsKey(GraphSONTokens.VALUE)); //Check n+1 key (traversed element) final HashMap<String, Object> branchKey = (HashMap<String, Object>) branch.get(GraphSONTokens.KEY); assertTrue(branchKey.containsKey(GraphSONTokens.ID)); assertTrue(branchKey.containsKey(GraphSONTokens.LABEL)); assertTrue(branchKey.containsKey(GraphSONTokens.TYPE)); assertTrue(branchKey.containsKey(GraphSONTokens.PROPERTIES)); assertEquals(convertToVertexId("marko").toString(), branchKey.get(GraphSONTokens.ID).toString()); assertEquals("person", branchKey.get(GraphSONTokens.LABEL)); assertEquals("vertex", branchKey.get(GraphSONTokens.TYPE)); final HashMap<String, List<HashMap<String, Object>>> branchKeyProps = (HashMap<String, List<HashMap<String, Object>>>) branchKey.get(GraphSONTokens.PROPERTIES); assertEquals("marko", branchKeyProps.get("name").get(0).get("value")); assertEquals(29, branchKeyProps.get("age").get(0).get("value")); //Check n+1 value (traversed element) final HashMap<String, Object> branchValue = (HashMap<String, Object>) branch.get(GraphSONTokens.VALUE); assertEquals(3, branchValue.size()); assertTrue(branchValue.containsKey(convertToVertexId("vadas").toString())); assertTrue(branchValue.containsKey(convertToVertexId("lop").toString())); assertTrue(branchValue.containsKey(convertToVertexId("josh").toString())); // Check that vp[] functioned properly final HashMap<String, HashMap<String, Object>> branch2 = (HashMap<String, HashMap<String, Object>>) branchValue.get(convertToVertexId("vadas").toString()); assertTrue(branch2.containsKey(GraphSONTokens.KEY)); assertTrue(branch2.containsKey(GraphSONTokens.VALUE)); final Map.Entry entry = branch2.get(GraphSONTokens.VALUE).entrySet().iterator().next(); final HashMap<String, HashMap<String, Object>> branch2Prop = (HashMap<String, HashMap<String, Object>>) entry.getValue(); assertTrue(branch2Prop.get(GraphSONTokens.KEY).containsKey(GraphSONTokens.ID)); assertTrue(branch2Prop.get(GraphSONTokens.KEY).containsKey(GraphSONTokens.VALUE)); assertTrue(branch2Prop.get(GraphSONTokens.KEY).containsKey(GraphSONTokens.LABEL)); assertEquals("name", branch2Prop.get(GraphSONTokens.KEY).get(GraphSONTokens.LABEL)); assertEquals("vadas", branch2Prop.get(GraphSONTokens.KEY).get(GraphSONTokens.VALUE)); assertEquals(entry.getKey().toString(), branch2Prop.get(GraphSONTokens.KEY).get(GraphSONTokens.ID).toString()); }
Example #30
Source File: SortedTree.java From sqlg with MIT License | 4 votes |
public static void main(String[] args) { Tree<String> tree = new Tree<>(); Tree<String> aTree = new Tree<>(); tree.put("a", aTree); Tree<String> bTree = new Tree<>(); tree.put("b", bTree); Tree<String> abTree = new Tree<>(); aTree.put("ab", abTree); Tree<String> bbTree = new Tree<>(); bTree.put("bb", bbTree); System.out.println(tree); SortedTree<String> sortedTree = new SortedTree<>((o1, o2) -> o1.compareTo(o2) * -1); sortedTree.addTree(tree); System.out.println(sortedTree); }