Skip to content

Commit

Permalink
Rename InMemoryDataSource into ListDataSource
Browse files Browse the repository at this point in the history
Change-Id: Ic0a8f5ced9139a0f712aac917b6a5841b8e1b0ab
  • Loading branch information
elmot authored and Teemu Suo-Anttila committed Aug 17, 2016
1 parent 7373b23 commit ecde311
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
18 changes: 9 additions & 9 deletions server/src/main/java/com/vaadin/server/data/DataSource.java
Expand Up @@ -29,7 +29,7 @@
* @param <T> * @param <T>
* data type * data type
* *
* @see InMemoryDataSource * @see ListDataSource
* @see BackEndDataSource * @see BackEndDataSource
*/ */
public interface DataSource<T> extends Function<Query, Stream<T>>, public interface DataSource<T> extends Function<Query, Stream<T>>,
Expand All @@ -53,29 +53,29 @@ public interface DataSource<T> extends Function<Query, Stream<T>>,
int size(Query t); int size(Query t);


/** /**
* This method creates a new {@link InMemoryDataSource} from a given * This method creates a new {@link ListDataSource} from a given
* Collection. The InMemoryDataSource creates a protective List copy of all * Collection. The ListDataSource creates a protective List copy of all
* the contents in the Collection. * the contents in the Collection.
* *
* @param data * @param data
* collection of data * collection of data
* @return in-memory data source * @return in-memory data source
*/ */
public static <T> InMemoryDataSource<T> create(Collection<T> data) { public static <T> ListDataSource<T> create(Collection<T> data) {
return new InMemoryDataSource<>(data); return new ListDataSource<>(data);
} }


/** /**
* This method creates a new {@link InMemoryDataSource} from given * This method creates a new {@link ListDataSource} from given
* objects.The InMemoryDataSource creates a protective List copy of all the * objects.The ListDataSource creates a protective List copy of all the
* contents in the array. * contents in the array.
* *
* @param data * @param data
* data objects * data objects
* @return in-memory data source * @return in-memory data source
*/ */
@SafeVarargs @SafeVarargs
public static <T> InMemoryDataSource<T> create(T... data) { public static <T> ListDataSource<T> create(T... data) {
return new InMemoryDataSource<>(Arrays.asList(data)); return new ListDataSource<>(Arrays.asList(data));
} }
} }
Expand Up @@ -29,7 +29,7 @@
* @param <T> * @param <T>
* data type * data type
*/ */
public class InMemoryDataSource<T> implements DataSource<T> { public class ListDataSource<T> implements DataSource<T> {


private Function<Query, Stream<T>> request; private Function<Query, Stream<T>> request;
private int size; private int size;
Expand All @@ -41,21 +41,21 @@ public class InMemoryDataSource<T> implements DataSource<T> {
* @param collection * @param collection
* initial data * initial data
*/ */
public InMemoryDataSource(Collection<T> collection) { public ListDataSource(Collection<T> collection) {
final List<T> backend = new ArrayList<>(collection); final List<T> backend = new ArrayList<>(collection);
request = query -> backend.stream(); request = query -> backend.stream();
size = backend.size(); size = backend.size();
} }


/** /**
* Chaining constructor for making modified {@link InMemoryDataSource}s. * Chaining constructor for making modified {@link ListDataSource}s.
* This Constructor is used internally for making sorted and filtered * This Constructor is used internally for making sorted and filtered
* variants of a base data source with actual data. * variants of a base data source with actual data.
* *
* @param request * @param request
* request for the new data source * request for the new data source
*/ */
protected InMemoryDataSource(Function<Query, Stream<T>> request) { protected ListDataSource(Function<Query, Stream<T>> request) {
this.request = request; this.request = request;
} }


Expand All @@ -71,8 +71,8 @@ public Stream<T> apply(Query query) {
* a {@link Comparator} providing the needed sorting order * a {@link Comparator} providing the needed sorting order
* @return new data source with modified sorting * @return new data source with modified sorting
*/ */
public InMemoryDataSource<T> sortingBy(Comparator<T> sortOrder) { public ListDataSource<T> sortingBy(Comparator<T> sortOrder) {
return new InMemoryDataSource<>(q -> request.apply(q) return new ListDataSource<>(q -> request.apply(q)
.sorted(sortOrder)); .sorted(sortOrder));
} }


Expand All @@ -86,7 +86,7 @@ public InMemoryDataSource<T> sortingBy(Comparator<T> sortOrder) {
* the type of the Comparable sort key * the type of the Comparable sort key
* @return new data source with modified sorting * @return new data source with modified sorting
*/ */
public <U extends Comparable<? super U>> InMemoryDataSource<T> sortingBy( public <U extends Comparable<? super U>> ListDataSource<T> sortingBy(
Function<T, U> sortOrder) { Function<T, U> sortOrder) {
return sortingBy(Comparator.comparing(sortOrder)); return sortingBy(Comparator.comparing(sortOrder));
} }
Expand Down
Expand Up @@ -7,16 +7,16 @@
import java.util.stream.Collectors; import java.util.stream.Collectors;


import com.vaadin.server.data.DataSource; import com.vaadin.server.data.DataSource;
import com.vaadin.server.data.InMemoryDataSource; import com.vaadin.server.data.ListDataSource;
import com.vaadin.server.data.Query; import com.vaadin.server.data.Query;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;




public class InMemoryDataSourceTest { public class ListDataSourceTest {


private InMemoryDataSource<StrBean> dataSource; private ListDataSource<StrBean> dataSource;
private List<StrBean> data; private List<StrBean> data;


@Before @Before
Expand Down

0 comments on commit ecde311

Please sign in to comment.