io.github.stewseo.client.util.ListBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of yelp-fusion-client Show documentation
Show all versions of yelp-fusion-client Show documentation
java client to build api objects, handle http transport, and parse/deserialize/serialize json to/from json
package io.github.stewseo.client.util;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Function;
import java.util.function.Supplier;
public class ListBuilder implements ObjectBuilder> {
private final List list = new ArrayList<>();
private final Supplier builderCtor;
public static > ListBuilder of(Supplier builderCtor) {
return new ListBuilder<>(builderCtor);
}
public ListBuilder(Supplier builderCtor) {
this.builderCtor = builderCtor;
}
public ListBuilder add(T value) {
list.add(value);
return this;
}
public ListBuilder add(Function> fn) {
return add(fn.apply(builderCtor.get()).build());
}
public ListBuilder addAll(Iterable extends T> iterable) {
for (T item: iterable) {
list.add(item);
}
return this;
}
@Override
public List build() {
return list;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy