Skip to content

Commit

Permalink
Improve listing and data source Javadocs a bit
Browse files Browse the repository at this point in the history
Change-Id: Ie3821df9bcb13af5f3955776a11d33fd2c16020e
  • Loading branch information
jdahlstrom authored and Ilia Motornyi committed Sep 7, 2016
1 parent d856282 commit 1d6b5a7
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 23 deletions.
Expand Up @@ -20,22 +20,26 @@
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();
}
5 changes: 3 additions & 2 deletions server/src/main/java/com/vaadin/data/Listing.java
Expand Up @@ -26,6 +26,7 @@
* A generic interface for components that show a list of data.
*
* @author Vaadin Ltd.
*
* @param <T>
* the item data type
* @param <SELECTIONMODEL>
Expand Down Expand Up @@ -62,7 +63,7 @@ public interface Listing<T, SELECTIONMODEL extends SelectionModel<T>>
* 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) {
Expand All @@ -75,7 +76,7 @@ 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));
}

Expand Down
35 changes: 21 additions & 14 deletions server/src/main/java/com/vaadin/server/data/DataSource.java
Expand Up @@ -25,12 +25,15 @@
* 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 {
Expand All @@ -56,26 +59,30 @@ public interface DataSource<T>
* 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));
}
}
}
10 changes: 6 additions & 4 deletions server/src/main/java/com/vaadin/server/data/ListDataSource.java
Expand Up @@ -19,6 +19,7 @@
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;

Expand All @@ -38,11 +39,12 @@ public class ListDataSource<T> implements DataSource<T> {
* 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();
}
Expand Down

0 comments on commit 1d6b5a7

Please sign in to comment.