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.

HierarchicalQuery.java 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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.data.provider;
  17. import java.util.Comparator;
  18. import java.util.List;
  19. import java.util.Optional;
  20. /**
  21. * Immutable hierarchical query object used to request data from a backend.
  22. * Contains the parent node, index limits, sorting and filtering information.
  23. *
  24. * @param <T>
  25. * bean type
  26. * @param <F>
  27. * filter type
  28. *
  29. * @since 8.0
  30. */
  31. public class HierarchicalQuery<T, F> extends Query<T, F> {
  32. private final T parent;
  33. /**
  34. * Constructs a new hierarchical query object with given filter and parent
  35. * node.
  36. *
  37. * @param filter
  38. * filtering for fetching; can be <code>null</code>
  39. * @param parent
  40. * the hierarchical parent object, can be <code>null</code>
  41. */
  42. public HierarchicalQuery(F filter, T parent) {
  43. super(filter);
  44. this.parent = parent;
  45. }
  46. /**
  47. * Constructs a new hierarchical query object with given offset, limit,
  48. * sorting and filtering.
  49. *
  50. * @param offset
  51. * first index to fetch
  52. * @param limit
  53. * fetched item count
  54. * @param sortOrders
  55. * sorting order for fetching; used for sorting backends
  56. * @param inMemorySorting
  57. * comparator for sorting in-memory data
  58. * @param filter
  59. * filtering for fetching; can be <code>null</code>
  60. * @param parent
  61. * the hierarchical parent object, can be <code>null</code>
  62. */
  63. public HierarchicalQuery(int offset, int limit,
  64. List<QuerySortOrder> sortOrders, Comparator<T> inMemorySorting,
  65. F filter, T parent) {
  66. super(offset, limit, sortOrders, inMemorySorting, filter);
  67. this.parent = parent;
  68. }
  69. /**
  70. * Get the hierarchical parent object, can be <code>null</code>.
  71. *
  72. * @return the hierarchical parent object, can be <code>null</code>
  73. */
  74. public T getParent() {
  75. return parent;
  76. }
  77. /**
  78. * Get an Optional of the hierarchical parent object.
  79. *
  80. * @see #getParent()
  81. * @return the result of {@link #getParent()} wrapped by an Optional
  82. */
  83. public Optional<T> getParentOptional() {
  84. return Optional.ofNullable(parent);
  85. }
  86. }