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.

FastStringSet.java 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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.Collection;
  18. import com.google.gwt.core.client.JavaScriptObject;
  19. import com.google.gwt.core.client.JsArrayString;
  20. public final class FastStringSet extends JavaScriptObject {
  21. protected FastStringSet() {
  22. // JSO constructor
  23. }
  24. public native boolean contains(String string)
  25. /*-{
  26. return this.hasOwnProperty(string);
  27. }-*/;
  28. public native void add(String string)
  29. /*-{
  30. this[string] = true;
  31. }-*/;
  32. public native void addAll(JsArrayString array)
  33. /*-{
  34. for (var i = 0; i < array.length; i++) {
  35. this[array[i]] = true;
  36. }
  37. }-*/;
  38. public native void addAll(FastStringSet set)
  39. /*-{
  40. for (var string in set) {
  41. if (Object.hasOwnProperty.call(set, string)) {
  42. this[string] = true;
  43. }
  44. }
  45. }-*/;
  46. public native JsArrayString dump()
  47. /*-{
  48. var array = [];
  49. for (var string in this) {
  50. if (this.hasOwnProperty(string)) {
  51. array.push(string);
  52. }
  53. }
  54. return array;
  55. }-*/;
  56. public native void remove(String string)
  57. /*-{
  58. delete this[string];
  59. }-*/;
  60. public native boolean isEmpty()
  61. /*-{
  62. for (var string in this) {
  63. if (this.hasOwnProperty(string)) {
  64. return false;
  65. }
  66. }
  67. return true;
  68. }-*/;
  69. public static FastStringSet create() {
  70. return JavaScriptObject.createObject().cast();
  71. }
  72. public native void addAllTo(Collection<String> target)
  73. /*-{
  74. for (var string in this) {
  75. if (Object.hasOwnProperty.call(this, string)) {
  76. target.@java.util.Collection::add(Ljava/lang/Object;)(string);
  77. }
  78. }
  79. }-*/;
  80. public native void removeAll(FastStringSet valuesToRemove)
  81. /*-{
  82. for (var string in valuesToRemove) {
  83. if (Object.hasOwnProperty.call(valuesToRemove, string)) {
  84. delete this[string];
  85. }
  86. }
  87. }-*/;
  88. }