Change-Id: Ic0a8f5ced9139a0f712aac917b6a5841b8e1b0abtags/8.0.0.alpha1
@@ -29,7 +29,7 @@ import java.util.stream.Stream; | |||
* @param <T> | |||
* data type | |||
* | |||
* @see InMemoryDataSource | |||
* @see ListDataSource | |||
* @see BackEndDataSource | |||
*/ | |||
public interface DataSource<T> extends Function<Query, Stream<T>>, | |||
@@ -53,21 +53,21 @@ public interface DataSource<T> extends Function<Query, Stream<T>>, | |||
int size(Query t); | |||
/** | |||
* This method creates a new {@link InMemoryDataSource} from a given | |||
* Collection. The InMemoryDataSource creates a protective List copy of all | |||
* 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 | |||
*/ | |||
public static <T> InMemoryDataSource<T> create(Collection<T> data) { | |||
return new InMemoryDataSource<>(data); | |||
public static <T> ListDataSource<T> create(Collection<T> data) { | |||
return new ListDataSource<>(data); | |||
} | |||
/** | |||
* This method creates a new {@link InMemoryDataSource} from given | |||
* objects.The InMemoryDataSource creates a protective List copy of all the | |||
* 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 | |||
@@ -75,7 +75,7 @@ public interface DataSource<T> extends Function<Query, Stream<T>>, | |||
* @return in-memory data source | |||
*/ | |||
@SafeVarargs | |||
public static <T> InMemoryDataSource<T> create(T... data) { | |||
return new InMemoryDataSource<>(Arrays.asList(data)); | |||
public static <T> ListDataSource<T> create(T... data) { | |||
return new ListDataSource<>(Arrays.asList(data)); | |||
} | |||
} |
@@ -29,7 +29,7 @@ import java.util.stream.Stream; | |||
* @param <T> | |||
* data type | |||
*/ | |||
public class InMemoryDataSource<T> implements DataSource<T> { | |||
public class ListDataSource<T> implements DataSource<T> { | |||
private Function<Query, Stream<T>> request; | |||
private int size; | |||
@@ -41,21 +41,21 @@ public class InMemoryDataSource<T> implements DataSource<T> { | |||
* @param collection | |||
* initial data | |||
*/ | |||
public InMemoryDataSource(Collection<T> collection) { | |||
public ListDataSource(Collection<T> collection) { | |||
final List<T> backend = new ArrayList<>(collection); | |||
request = query -> backend.stream(); | |||
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 | |||
* variants of a base data source with actual data. | |||
* | |||
* @param request | |||
* request for the new data source | |||
*/ | |||
protected InMemoryDataSource(Function<Query, Stream<T>> request) { | |||
protected ListDataSource(Function<Query, Stream<T>> request) { | |||
this.request = request; | |||
} | |||
@@ -71,8 +71,8 @@ public class InMemoryDataSource<T> implements DataSource<T> { | |||
* a {@link Comparator} providing the needed sorting order | |||
* @return new data source with modified sorting | |||
*/ | |||
public InMemoryDataSource<T> sortingBy(Comparator<T> sortOrder) { | |||
return new InMemoryDataSource<>(q -> request.apply(q) | |||
public ListDataSource<T> sortingBy(Comparator<T> sortOrder) { | |||
return new ListDataSource<>(q -> request.apply(q) | |||
.sorted(sortOrder)); | |||
} | |||
@@ -86,7 +86,7 @@ public class InMemoryDataSource<T> implements DataSource<T> { | |||
* the type of the Comparable sort key | |||
* @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) { | |||
return sortingBy(Comparator.comparing(sortOrder)); | |||
} |
@@ -7,16 +7,16 @@ import java.util.List; | |||
import java.util.stream.Collectors; | |||
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 org.junit.Assert; | |||
import org.junit.Before; | |||
import org.junit.Test; | |||
public class InMemoryDataSourceTest { | |||
public class ListDataSourceTest { | |||
private InMemoryDataSource<StrBean> dataSource; | |||
private ListDataSource<StrBean> dataSource; | |||
private List<StrBean> data; | |||
@Before |