Skip to content

Commit

Permalink
api: Allow obtaining a builder from ForwardingPointers
Browse files Browse the repository at this point in the history
  • Loading branch information
kezz committed Aug 29, 2021
1 parent 6041016 commit 5a6bd4c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public <T> boolean supports(final @NotNull Pointer<T> pointer) {

@Override
public @NotNull Pointers.Builder toBuilder() {
return new BuilderImpl(this);
return new BuilderImpl(new HashMap<>(this.pointers));
}

static final class BuilderImpl implements Builder {
Expand All @@ -85,8 +85,8 @@ static final class BuilderImpl implements Builder {
this.pointers = new HashMap<>();
}

BuilderImpl(final @NotNull PointersImpl pointers) {
this.pointers = new HashMap<>(pointers.pointers);
BuilderImpl(final @NotNull Map<Pointer<?>, Supplier<?>> pointers) {
this.pointers = pointers;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
import org.jetbrains.annotations.NotNull;

final class PointersSupplierImpl<T> implements PointersSupplier<T> {
Expand Down Expand Up @@ -73,7 +74,13 @@ public <T> boolean supports(final @NotNull Pointer<T> pointer) {

@Override
public @NotNull Pointers.Builder toBuilder() {
throw new UnsupportedOperationException();
final Map<Pointer<?>, Supplier<?>> pointers = new HashMap<>();

for (final Map.Entry<Pointer<?>, Function<U, ?>> entry : this.supplier.resolvers.entrySet()) {
pointers.put(entry.getKey(), () -> entry.getValue().apply(this.instance));
}

return new PointersImpl.BuilderImpl(pointers);
}
}

Expand Down

0 comments on commit 5a6bd4c

Please sign in to comment.