@Override public @NonNull B mapChildrenDeep(final @NonNull Function<BuildableComponent<? ,?>, BuildableComponent<? ,?>> function) { if(this.children == EMPTY_COMPONENT_LIST) { return (B) this; } final ListIterator<Component> it = this.children.listIterator(); while(it.hasNext()) { final Component child = it.next(); if(!(child instanceof BuildableComponent)) { continue; } final BuildableComponent mappedChild = function.apply((BuildableComponent) child); if(mappedChild.children().isEmpty()) { if(child == mappedChild) { continue; } it.set(mappedChild); } else { final Builder<?, ?> builder = mappedChild.toBuilder(); builder.mapChildrenDeep(function); it.set(builder.build()); } } return (B) this; }
@Override @SuppressWarnings({"rawtypes", "unchecked"}) public @NonNull B mapChildrenDeep(final @NonNull Function<BuildableComponent<? ,?>, BuildableComponent<? ,?>> function) { if(this.children == EMPTY_COMPONENT_LIST) { return (B) this; } final ListIterator<Component> it = this.children.listIterator(); while(it.hasNext()) { final Component child = it.next(); if(!(child instanceof BuildableComponent)) { continue; } final BuildableComponent mappedChild = function.apply((BuildableComponent) child); if(mappedChild.children().isEmpty()) { if(child == mappedChild) { continue; } it.set(mappedChild); } else { final Builder<?, ?> builder = mappedChild.toBuilder(); builder.mapChildrenDeep(function); it.set(builder.build()); } } return (B) this; }
@Override @SuppressWarnings({"rawtypes", "unchecked"}) public @NonNull B mapChildrenDeep(final @NonNull Function<BuildableComponent<? ,?>, BuildableComponent<? ,?>> function) { if(this.children == EMPTY_COMPONENT_LIST) { return (B) this; } final ListIterator<Component> it = this.children.listIterator(); while(it.hasNext()) { final Component child = it.next(); if(!(child instanceof BuildableComponent)) { continue; } final BuildableComponent mappedChild = function.apply((BuildableComponent) child); if(mappedChild.children().isEmpty()) { if(child == mappedChild) { continue; } it.set(mappedChild); } else { final Builder<?, ?> builder = mappedChild.toBuilder(); builder.mapChildrenDeep(function); it.set(builder.build()); } } return (B) this; }
@Override @SuppressWarnings("unchecked") public @NonNull B applyDeep(final @NonNull Consumer<Builder<?, ?>> consumer) { this.apply(consumer); if(this.children == EMPTY_COMPONENT_LIST) { return (B) this; } final ListIterator<Component> it = this.children.listIterator(); while(it.hasNext()) { final Component child = it.next(); if(!(child instanceof BuildableComponent)) { continue; } final Builder<?, ?> childBuilder = ((BuildableComponent) child).toBuilder(); childBuilder.applyDeep(consumer); it.set(childBuilder.build()); } return (B) this; }
@Override @SuppressWarnings("unchecked") public @NonNull B applyDeep(final @NonNull Consumer<Builder<?, ?>> consumer) { this.apply(consumer); if(this.children == EMPTY_COMPONENT_LIST) { return (B) this; } final ListIterator<Component> it = this.children.listIterator(); while(it.hasNext()) { final Component child = it.next(); if(!(child instanceof BuildableComponent)) { continue; } final Builder<?, ?> childBuilder = ((BuildableComponent) child).toBuilder(); childBuilder.applyDeep(consumer); it.set(childBuilder.build()); } return (B) this; }
@Override public @NonNull B applyDeep(final @NonNull Consumer<Builder<?, ?>> consumer) { this.apply(consumer); if(this.children == EMPTY_COMPONENT_LIST) { return (B) this; } final ListIterator<Component> it = this.children.listIterator(); while(it.hasNext()) { final Component child = it.next(); if(!(child instanceof BuildableComponent)) { continue; } final Builder<?, ?> childBuilder = ((BuildableComponent) child).toBuilder(); childBuilder.applyDeep(consumer); it.set(childBuilder.build()); } return (B) this; }
@Test void testMergeDecorations() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeDecorations(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of(TextDecoration.BOLD, TextDecoration.State.TRUE)); assertNull(c1.clickEvent()); assertEquals(c0, c1.decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET)); }
@Test void testHoverEvent() { final C c0 = this.builder().build(); assertNull(c0.hoverEvent()); final C c1 = (C) c0.hoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, TextComponent.of("hover"))); assertNotNull(c1.hoverEvent()); assertEquals(c0, c1.hoverEvent(null)); }
@Test void testClickEvent() { final C c0 = this.builder().build(); assertNull(c0.clickEvent()); final C c1 = (C) c0.clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "foo")); assertNotNull(c1.clickEvent()); assertEquals(c0, c1.clickEvent(null)); }
@Test void testDecoration() { final C c0 = this.builder().build(); assertDecorations(c0, ImmutableMap.of()); final C c1 = (C) c0.decoration(TextDecoration.BOLD, true); assertDecorations(c1, ImmutableMap.of(TextDecoration.BOLD, TextDecoration.State.TRUE)); assertEquals(c0, c1.decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET)); }
@Test void testResetStyle() { final C c0 = this.builder() .color(TextColor.RED) .decoration(TextDecoration.BOLD, true) .clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo")) .build(); final C c1 = (C) c0.resetStyle(); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNull(c1.clickEvent()); assertEquals(c1, c0.color(null).decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET).clickEvent(null)); }
@Test void testMergeColor() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeColor(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertEquals(TextColor.RED, c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNull(c1.clickEvent()); assertEquals(c0, c1.color(null)); }
@Test void testColor() { final C c0 = this.builder().build(); assertNull(c0.color()); final C c1 = (C) c0.color(TextColor.GREEN); assertEquals(TextColor.GREEN, c1.color()); assertEquals(c0, c1.color(null)); }
@Test void testCopy() { final C c0 = this.builder().build(); final C c1 = (C) c0.copy(); assertEquals(c0, c1); }
@Test void testMergeEvents() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeEvents(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertNull(c1.color()); assertDecorations(c1, ImmutableMap.of()); assertNotNull(c1.clickEvent()); }
@Test void testMergeStyle() { final C c0 = this.builder().build(); assertNull(c0.color()); assertDecorations(c0, ImmutableMap.of()); assertNull(c0.clickEvent()); final C c1 = (C) c0.mergeStyle(TextComponent.of("xyz", TextColor.RED, ImmutableSet.of(TextDecoration.BOLD)).clickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/foo"))); assertEquals(TextColor.RED, c1.color()); assertDecorations(c1, ImmutableMap.of(TextDecoration.BOLD, TextDecoration.State.TRUE)); assertNotNull(c1.clickEvent()); assertEquals(c0, c1.color(null).decoration(TextDecoration.BOLD, TextDecoration.State.NOT_SET).clickEvent(null)); }
@Test void testInsertion() { final C c0 = this.builder().build(); assertNull(c0.insertion()); final C c1 = (C) c0.insertion("foo"); assertNotNull(c1.insertion()); assertEquals(c0, c1.insertion(null)); }