diff --git a/src/main/java/lsh/ext/gson/IBuilder0.java b/src/main/java/lsh/ext/gson/IBuilder0.java index 550b3933..52d45c0a 100644 --- a/src/main/java/lsh/ext/gson/IBuilder0.java +++ b/src/main/java/lsh/ext/gson/IBuilder0.java @@ -8,6 +8,12 @@ public interface IBuilder0 { R build(); + static IBuilder0 of( + final Supplier build + ) { + return build::get; + } + interface ILookup { Supplier> lookup(TypeToken typeToken); diff --git a/src/main/java/lsh/ext/gson/IBuilder1.java b/src/main/java/lsh/ext/gson/IBuilder1.java index 89fec1ff..a2f8f860 100644 --- a/src/main/java/lsh/ext/gson/IBuilder1.java +++ b/src/main/java/lsh/ext/gson/IBuilder1.java @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.function.BiConsumer; +import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Supplier; import java.util.stream.Collector; @@ -15,20 +16,27 @@ public interface IBuilder1 { R build(); - static > IBuilder1 of(final C collection) { + static IBuilder1 of( + final Consumer consume, + final Supplier build + ) { return new IBuilder1<>() { @Override - public void accept(final E e) { - collection.add(e); + public void accept(final A1 a1) { + consume.accept(a1); } @Override - public C build() { - return collection; + public R build() { + return build.get(); } }; } + static > IBuilder1 of(final C collection) { + return of(collection::add, () -> collection); + } + static > Supplier> from(final Supplier collectionFactory) { return () -> of(collectionFactory.get()); } diff --git a/src/main/java/lsh/ext/gson/IBuilder2.java b/src/main/java/lsh/ext/gson/IBuilder2.java index ad68316e..a89d7b94 100644 --- a/src/main/java/lsh/ext/gson/IBuilder2.java +++ b/src/main/java/lsh/ext/gson/IBuilder2.java @@ -16,20 +16,27 @@ public interface IBuilder2 { R build(); - static > IBuilder2 of(final M map) { + static IBuilder2 of( + final BiConsumer consume, + final Supplier build + ) { return new IBuilder2<>() { @Override - public void accept(final K k, final V v) { - map.put(k, v); + public void accept(final A1 a1, final A2 a2) { + consume.accept(a1, a2); } @Override - public M build() { - return map; + public R build() { + return build.get(); } }; } + static > IBuilder2 of(final M map) { + return of(map::put, () -> map); + } + static > Supplier> from(final Supplier factory) { return () -> of(factory.get()); }