File tree Expand file tree Collapse file tree 2 files changed +27
-3
lines changed
main/java/net/kyori/adventure/pointer
test/java/net/kyori/adventure/pointer Expand file tree Collapse file tree 2 files changed +27
-3
lines changed Original file line number Diff line number Diff line change 3333import org .jetbrains .annotations .Nullable ;
3434
3535final class PointersSupplierImpl <T > implements PointersSupplier <T > {
36- private final PointersSupplier <? super T > parent ;
36+ private final @ Nullable PointersSupplier <? super T > parent ;
3737 private final Map <Pointer <?>, Function <T , ?>> resolvers ;
3838
3939 PointersSupplierImpl (final @ NotNull BuilderImpl <T > builder ) {
@@ -87,7 +87,10 @@ static final class ForwardingPointers<U> implements Pointers {
8787
8888 // Fallback to the parent.
8989 if (resolver == null ) {
90- resolver = this .supplier .parent .resolver (pointer );
90+ final PointersSupplier <? super U > parent = this .supplier .parent ;
91+ if (parent != null ) {
92+ resolver = parent .resolver (pointer );
93+ }
9194 }
9295
9396 // Finally, wrap in an optional.
@@ -117,7 +120,7 @@ public <T> boolean supports(final @NotNull Pointer<T> pointer) {
117120 }
118121
119122 static final class BuilderImpl <T > implements Builder <T > {
120- private PointersSupplier <? super T > parent = null ;
123+ private @ Nullable PointersSupplier <? super T > parent = null ;
121124 private final Map <Pointer <?>, Function <T , ?>> resolvers ;
122125
123126 BuilderImpl () {
Original file line number Diff line number Diff line change @@ -90,4 +90,25 @@ public void ofPointersSuppliers() {
9090 assertEquals ("1" , rebuilt .get (p0 ).get ());
9191 assertEquals ("1" , rebuilt .get (p1 ).get ());
9292 }
93+
94+ @ Test
95+ public void ofPointersSuppliersWithNoParent () {
96+ final Pointer <String > p0 = Pointer .pointer (String .class , Key .key ("adventure:test1" ));
97+ final Pointer <String > p1 = Pointer .pointer (String .class , Key .key ("adventure:test2" ));
98+
99+ final PointersSupplier <Integer > supplier = PointersSupplier .<Integer >builder ()
100+ .resolving (p1 , (object ) -> "1" )
101+ .build ();
102+
103+ assertFalse (supplier .supports (p0 ));
104+ assertTrue (supplier .supports (p1 ));
105+
106+ final Pointers pointer = supplier .view (10 );
107+ assertFalse (pointer .get (p0 ).isPresent ());
108+ assertEquals ("1" , pointer .get (p1 ).get ());
109+
110+ final Pointers rebuilt = pointer .toBuilder ().withStatic (p0 , "1" ).build ();
111+ assertEquals ("1" , rebuilt .get (p0 ).get ());
112+ assertEquals ("1" , rebuilt .get (p1 ).get ());
113+ }
93114}
You can’t perform that action at this time.
0 commit comments