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.

FastStringMap.java 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 com.google.gwt.core.client.JavaScriptObject;
  18. import com.google.gwt.core.client.JsArrayString;
  19. public final class FastStringMap<T> extends JavaScriptObject {
  20. protected FastStringMap() {
  21. // JSO constructor
  22. }
  23. public native void put(String key, T value)
  24. /*-{
  25. this[key] = value;
  26. }-*/;
  27. public native T get(String key)
  28. /*-{
  29. return this[key];
  30. }-*/;
  31. public native boolean containsKey(String key)
  32. /*-{
  33. //Can't use this.hasOwnProperty in case that key is used
  34. return Object.hasOwnProperty.call(this, key);
  35. }-*/;
  36. public native void remove(String key)
  37. /*-{
  38. delete this[key];
  39. }-*/;
  40. public native JsArrayString getKeys()
  41. /*-{
  42. var keys = [];
  43. for (var key in this) {
  44. if (Object.hasOwnProperty.call(this, key)) {
  45. keys.push(key);
  46. }
  47. }
  48. return keys;
  49. }-*/;
  50. public native int size()
  51. /*-{
  52. var size = 0;
  53. for (var key in this) {
  54. if (Object.hasOwnProperty.call(this, key)) {
  55. size++;
  56. }
  57. }
  58. return size;
  59. }-*/;
  60. public static <T> FastStringMap<T> create() {
  61. return JavaScriptObject.createObject().cast();
  62. }
  63. }