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

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