Skip to content

Make ListWidget builder method take Iterable instead of List #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public static <T, V extends IValueWidget<T> & IWidget, W extends ListWidget<T, V
return new ListWidget<>(valueToWidgetMapper, IValueWidget::getWidgetValue);
}

public static <T, I extends IWidget, W extends ListWidget<T, I, W>> ListWidget<T, I, W> builder(List<T> list, Function<T, I> creator) {
public static <T, I extends IWidget, W extends ListWidget<T, I, W>> ListWidget<T, I, W> builder(Iterable<T> iterable, Function<T, I> creator) {
Map<T, I> map = new Object2ObjectOpenHashMap<>();
Map<I, T> map_reverse = new Object2ObjectOpenHashMap<>();
ListWidget<T, I, W> listWidget = new ListWidget<>(map::get, map_reverse::get);
for (T t : list) {
for (T t : iterable) {
I widget = creator.apply(t);
map.put(t, widget);
map_reverse.put(widget, t);
Expand Down Expand Up @@ -82,6 +82,10 @@ public boolean add(T value, int index) {
return false;
}

public boolean add(T value) {
return add(value, getChildren().size());
}

@Nullable
public IWidget remove(T value) {
IWidget widget = this.valueToWidgetMapper.apply(value);
Expand Down