You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * Copyright 2000-2016 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.server.data;
  17. import java.io.Serializable;
  18. import java.util.Arrays;
  19. import java.util.Collection;
  20. import java.util.function.Function;
  21. import java.util.stream.Stream;
  22. /**
  23. * Minimal DataSource API for communication between the DataProvider and a back
  24. * end service.
  25. *
  26. * @author Vaadin Ltd.
  27. *
  28. * @param <T>
  29. * data type
  30. *
  31. * @see ListDataSource
  32. * @see BackEndDataSource
  33. *
  34. * @since 8.0
  35. */
  36. public interface DataSource<T>
  37. extends Function<Query, Stream<T>>, Serializable {
  38. /**
  39. * Gets whether the DataSource content all available in memory or does it
  40. * use some external backend.
  41. *
  42. * @return {@code true} if all data is in memory; {@code false} if not
  43. */
  44. boolean isInMemory();
  45. /**
  46. * Gets the amount of data in this DataSource.
  47. *
  48. * @param t
  49. * query with sorting and filtering
  50. * @return the size of the data source
  51. */
  52. int size(Query t);
  53. /**
  54. * This method creates a new {@link ListDataSource} from a given Collection.
  55. * The ListDataSource creates a protective List copy of all the contents in
  56. * the Collection.
  57. *
  58. * @param <T>
  59. * the data item type
  60. * @param items
  61. * the collection of data, not null
  62. * @return a new list data source
  63. */
  64. public static <T> ListDataSource<T> create(Collection<T> items) {
  65. return new ListDataSource<>(items);
  66. }
  67. /**
  68. * This method creates a new {@link ListDataSource} from given objects.The
  69. * ListDataSource creates a protective List copy of all the contents in the
  70. * array.
  71. *
  72. * @param <T>
  73. * the data item type
  74. * @param items
  75. * the data items
  76. * @return a new list data source
  77. */
  78. @SafeVarargs
  79. public static <T> ListDataSource<T> create(T... items) {
  80. return new ListDataSource<>(Arrays.asList(items));
  81. }
  82. }