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.

ComponentDetailMap.java 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Copyright 2000-2018 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.client;
  17. import java.util.ArrayList;
  18. import java.util.Collection;
  19. import java.util.List;
  20. import com.google.gwt.core.client.JavaScriptObject;
  21. final class ComponentDetailMap extends JavaScriptObject {
  22. protected ComponentDetailMap() {
  23. }
  24. static ComponentDetailMap create() {
  25. return (ComponentDetailMap) JavaScriptObject.createObject();
  26. }
  27. boolean isEmpty() {
  28. return size() == 0;
  29. }
  30. final native boolean containsKey(String key)
  31. /*-{
  32. return this.hasOwnProperty(key);
  33. }-*/;
  34. final native ComponentDetail get(String key)
  35. /*-{
  36. return this[key];
  37. }-*/;
  38. final native void put(String id, ComponentDetail value)
  39. /*-{
  40. this[id] = value;
  41. }-*/;
  42. final native void remove(String id)
  43. /*-{
  44. delete this[id];
  45. }-*/;
  46. final native int size()
  47. /*-{
  48. var count = 0;
  49. for (var key in this) {
  50. count++;
  51. }
  52. return count;
  53. }-*/;
  54. final native void clear()
  55. /*-{
  56. for (var key in this) {
  57. if (this.hasOwnProperty(key)) {
  58. delete this[key];
  59. }
  60. }
  61. }-*/;
  62. private final native void fillWithValues(Collection<ComponentDetail> list)
  63. /*-{
  64. for (var key in this) {
  65. // $entry not needed as function is not exported
  66. list.@java.util.Collection::add(Ljava/lang/Object;)(this[key]);
  67. }
  68. }-*/;
  69. final Collection<ComponentDetail> values() {
  70. List<ComponentDetail> list = new ArrayList<>();
  71. fillWithValues(list);
  72. return list;
  73. }
  74. public native JsArrayObject<ComponentDetail> valuesAsJsArray()
  75. /*-{
  76. var result = [];
  77. for (var key in this) {
  78. if (this.hasOwnProperty(key)) {
  79. result.push(this[key]);
  80. }
  81. }
  82. return result;
  83. }-*/;
  84. }