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.

ValueMap.java 3.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /**
  17. *
  18. */
  19. package com.vaadin.client;
  20. import java.util.HashSet;
  21. import java.util.Set;
  22. import com.google.gwt.core.client.JavaScriptObject;
  23. import com.google.gwt.core.client.JsArray;
  24. import com.google.gwt.core.client.JsArrayString;
  25. public final class ValueMap extends JavaScriptObject {
  26. protected ValueMap() {
  27. }
  28. public native double getRawNumber(final String name)
  29. /*-{
  30. return this[name];
  31. }-*/;
  32. public native int getInt(final String name)
  33. /*-{
  34. return this[name];
  35. }-*/;
  36. public native boolean getBoolean(final String name)
  37. /*-{
  38. return Boolean(this[name]);
  39. }-*/;
  40. public native String getString(String name)
  41. /*-{
  42. return this[name];
  43. }-*/;
  44. public native JsArrayString getKeyArray()
  45. /*-{
  46. var a = new Array();
  47. var attr = this;
  48. for(var j in attr) {
  49. // workaround for the infamous chrome hosted mode hack (__gwt_ObjectId)
  50. if(attr.hasOwnProperty(j))
  51. a.push(j);
  52. }
  53. return a;
  54. }-*/;
  55. public Set<String> getKeySet() {
  56. final HashSet<String> attrs = new HashSet<String>();
  57. JsArrayString attributeNamesArray = getKeyArray();
  58. for (int i = 0; i < attributeNamesArray.length(); i++) {
  59. attrs.add(attributeNamesArray.get(i));
  60. }
  61. return attrs;
  62. }
  63. public native JsArrayString getJSStringArray(String name)
  64. /*-{
  65. return this[name];
  66. }-*/;
  67. public native JsArray<ValueMap> getJSValueMapArray(String name)
  68. /*-{
  69. return this[name];
  70. }-*/;
  71. public String[] getStringArray(final String name) {
  72. JsArrayString stringArrayAttribute = getJSStringArray(name);
  73. final String[] s = new String[stringArrayAttribute.length()];
  74. for (int i = 0; i < stringArrayAttribute.length(); i++) {
  75. s[i] = stringArrayAttribute.get(i);
  76. }
  77. return s;
  78. }
  79. public int[] getIntArray(final String name) {
  80. JsArrayString stringArrayAttribute = getJSStringArray(name);
  81. final int[] s = new int[stringArrayAttribute.length()];
  82. for (int i = 0; i < stringArrayAttribute.length(); i++) {
  83. s[i] = Integer.parseInt(stringArrayAttribute.get(i));
  84. }
  85. return s;
  86. }
  87. public native boolean containsKey(final String name)
  88. /*-{
  89. return name in this;
  90. }-*/;
  91. public native ValueMap getValueMap(String name)
  92. /*-{
  93. return this[name];
  94. }-*/;
  95. public native String getAsString(String name)
  96. /*-{
  97. return '' + this[name];
  98. }-*/;
  99. public native JavaScriptObject getJavaScriptObject(String name)
  100. /*-{
  101. return this[name];
  102. }-*/;
  103. }