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.

DataKeyMapper.java 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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.io.Serializable;
  18. import com.vaadin.data.ValueProvider;
  19. /**
  20. * DataKeyMapper to map data objects to key strings.
  21. *
  22. * @since 8.0
  23. * @param <T>
  24. * data type
  25. */
  26. public interface DataKeyMapper<T> extends Serializable {
  27. /**
  28. * Gets the key for data object. If no key exists beforehand, a new key is
  29. * created.
  30. *
  31. * @param dataObject
  32. * data object for key mapping
  33. * @return key for given data object
  34. */
  35. String key(T dataObject);
  36. /**
  37. * Gets the data object identified by given key.
  38. *
  39. * @param key
  40. * key of a data object
  41. * @return identified data object; <code>null</code> if invalid key
  42. */
  43. T get(String key);
  44. /**
  45. * Removes a data object from the key mapping. The key is also dropped.
  46. * Dropped keys are not reused.
  47. *
  48. * @param dataObject
  49. * dropped data object
  50. */
  51. void remove(T dataObject);
  52. /**
  53. * Removes all data objects from the key mapping. The keys are also dropped.
  54. * Dropped keys are not reused.
  55. */
  56. void removeAll();
  57. /**
  58. * Updates any existing mappings of given data object. The equality of two
  59. * data objects is determined by the equality of their identifiers provided
  60. * by the given value provider.
  61. *
  62. * @param dataObject
  63. * the data object to update
  64. * @param identifierGetter
  65. * the function to get an identifier from a data object
  66. */
  67. void refresh(T dataObject, ValueProvider<T, Object> identifierGetter);
  68. }