Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DataSource.java 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2000-2014 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.tokka.server.communication.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. import com.vaadin.tokka.event.Registration;
  23. /**
  24. * Minimal DataSource API for communication between the DataProvider and a back
  25. * end service.
  26. * <p>
  27. * FIXME: Missing Query class
  28. *
  29. * @since
  30. * @param <T>
  31. * data type
  32. */
  33. public interface DataSource<T> extends Function<Object, Stream<T>>,
  34. Serializable {
  35. /**
  36. * This method creates a new {@link InMemoryDataSource} from a given
  37. * Collection. The InMemoryDataSource creates a protective List copy of all
  38. * the contents in the Collection.
  39. *
  40. * @param data
  41. * collection of data
  42. * @return in-memory data source
  43. */
  44. public static <T> InMemoryDataSource<T> create(Collection<T> data) {
  45. return new InMemoryDataSource<>(data);
  46. }
  47. /**
  48. * This method creates a new {@link InMemoryDataSource} from given
  49. * objects.The InMemoryDataSource creates a protective List copy of all the
  50. * contents in the array.
  51. *
  52. * @param data
  53. * data objects
  54. * @return in-memory data source
  55. */
  56. @SafeVarargs
  57. public static <T> InMemoryDataSource<T> create(T... data) {
  58. return new InMemoryDataSource<>(Arrays.asList(data));
  59. }
  60. }