AbstractListDataView extends AbstractDataView<T> implements ListDataView<T, AbstractListDataView<T>> { @Override public AbstractListDataView<T> addItems(Collection<T> items) { Objects.requireNonNull(items, NULL_COLLECTION_ERROR_MESSAGE); if (!items.isEmpty()) { final ListDataProvider<T> dataProvider = getDataProvider(); Collection<T> backendItems = dataProvider.getItems(); items.stream() .filter(this::contains) .forEach(item -> removeItemIfPresent(item, dataProvider)); backendItems.addAll(items); dataProvider.refreshAll(); } return this; } AbstractListDataView(
            SerializableSupplier<? extends DataProvider<T, ?>> dataProviderSupplier,
            Component component); @Override int getItemCount(); @Override T getItem(int index); @Override Optional<T> getNextItem(T item); @Override Optional<T> getPreviousItem(T item); @Override AbstractListDataView<T> addFilter(SerializablePredicate<T> filter); @Override AbstractListDataView<T> removeFilters(); @Override AbstractListDataView<T> setFilter(SerializablePredicate<T> filter); @Override AbstractListDataView<T> setSortComparator(
            SerializableComparator<T> sortComparator); @Override AbstractListDataView<T> addSortComparator(
            SerializableComparator<T> sortComparator); @Override AbstractListDataView<T> removeSorting(); @Override AbstractListDataView<T> setSortOrder(
            ValueProvider<T, V1> valueProvider, SortDirection sortDirection); @Override AbstractListDataView<T> addSortOrder(
            ValueProvider<T, V1> valueProvider, SortDirection sortDirection); @Override boolean contains(T item); @Override AbstractListDataView<T> addItem(T item); @Override AbstractListDataView<T> addItems(Collection<T> items); @Override AbstractListDataView<T> addItemAfter(T item, T after); @Override AbstractListDataView<T> addItemBefore(T item, T before); @Override AbstractListDataView<T> addItemsAfter(Collection<T> items, T after); @Override AbstractListDataView<T> addItemsBefore(Collection<T> items,
            T before); @Override AbstractListDataView<T> removeItem(T item); @Override AbstractListDataView<T> removeItems(Collection<T> items);  }
@Test public void addItems_someItemsAlreadyInList_allItemsAreMovedAtTheEndAndOrdered() { dataView.addItems(Arrays.asList("first", "newOne", "newTwo")); Assert.assertArrayEquals( new String[] { "middle", "last", "first", "newOne", "newTwo" }, dataView.getItems().toArray(String[]::new)); }
@Test public void addItems_nullCollectionPassed_throwsException() { exceptionRule.expect(NullPointerException.class); exceptionRule.expectMessage("Items collection cannot be null"); dataView.addItems(null); }
@Test public void addItems_emptyCollectionPassed_dataNotChanged() { dataView.addItems(Collections.emptyList()); Assert.assertArrayEquals(new String[] { "first", "middle", "last" }, dataView.getItems().toArray(String[]::new)); }
@Test public void addItems_allItemsAreAdded() { dataView.addItems(Arrays.asList("newOne", "newTwo", "newThree")); Assert.assertArrayEquals( new String[] { "first", "middle", "last", "newOne", "newTwo", "newThree" }, dataView.getItems().toArray(String[]::new)); }