import elemental.json.JsonObject;
/**
- * Marker interface for Connectors that have a {@link DataSource}.
+ * A marker interface for connectors that have a data source.
+ *
+ * @author Vaadin Ltd.
+ * @see DataSource
+ * @since 8.0
*/
public interface HasDataSource {
* Sets the data source for this Connector.
*
* @param dataSource
- * new data source
+ * the new data source, not null
*/
void setDataSource(DataSource<JsonObject> dataSource);
/**
* Gets the current data source for this Connector.
*
- * @return data source
+ * @return the data source, not null
*/
DataSource<JsonObject> getDataSource();
}
* A generic interface for components that show a list of data.
*
* @author Vaadin Ltd.
+ *
* @param <T>
* the item data type
* @param <SELECTIONMODEL>
* Sets the collection of data items of this listing.
*
* @param items
- * the data items to display
+ * the data items to display, not null
*
*/
default void setItems(Collection<T> items) {
* @param items
* the data items to display
*/
- default void setItems(T... items) {
+ default void setItems(@SuppressWarnings("unchecked") T... items) {
setDataSource(DataSource.create(items));
}
* Minimal DataSource API for communication between the DataProvider and a back
* end service.
*
- * @since
+ * @author Vaadin Ltd.
+ *
* @param <T>
* data type
*
* @see ListDataSource
* @see BackEndDataSource
+ *
+ * @since
*/
public interface DataSource<T>
extends Function<Query, Stream<T>>, Serializable {
* This method creates a new {@link ListDataSource} from a given Collection.
* The ListDataSource creates a protective List copy of all the contents in
* the Collection.
- *
- * @param data
- * collection of data
- * @return in-memory data source
+ *
+ * @param <T>
+ * the data item type
+ * @param items
+ * the collection of data, not null
+ * @return a new list data source
*/
- public static <T> ListDataSource<T> create(Collection<T> data) {
- return new ListDataSource<>(data);
+ public static <T> ListDataSource<T> create(Collection<T> items) {
+ return new ListDataSource<>(items);
}
/**
* This method creates a new {@link ListDataSource} from given objects.The
* ListDataSource creates a protective List copy of all the contents in the
* array.
- *
- * @param data
- * data objects
- * @return in-memory data source
+ *
+ * @param <T>
+ * the data item type
+ * @param items
+ * the data items
+ * @return a new list data source
*/
@SafeVarargs
- public static <T> ListDataSource<T> create(T... data) {
- return new ListDataSource<>(Arrays.asList(data));
+ public static <T> ListDataSource<T> create(T... items) {
+ return new ListDataSource<>(Arrays.asList(items));
}
-}
\ No newline at end of file
+}
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
+import java.util.Objects;
import java.util.function.Function;
import java.util.stream.Stream;
* Constructs a new ListDataSource. This method makes a protective copy of
* the contents of the Collection.
*
- * @param collection
- * initial data
+ * @param items
+ * the initial data, not null
*/
- public ListDataSource(Collection<T> collection) {
- final List<T> backend = new ArrayList<>(collection);
+ public ListDataSource(Collection<T> items) {
+ Objects.requireNonNull(items, "items cannot be null");
+ final List<T> backend = new ArrayList<>(items);
request = query -> backend.stream();
size = backend.size();
}