TabularData.java 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /* TabularData.java -- Tables of composite data structures.
  2. Copyright (C) 2006, 2007 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.management.openmbean;
  32. import java.util.Collection;
  33. import java.util.Set;
  34. /**
  35. * Provides an interface to a specific type of composite
  36. * data structure, where keys (the columns) map to the
  37. * {@link CompositeData} objects that form the rows of
  38. * the table.
  39. *
  40. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  41. * @since 1.5
  42. */
  43. public interface TabularData
  44. {
  45. /**
  46. * Calculates the index the specified {@link CompositeData} value
  47. * would have, if it was to be added to this {@link TabularData}
  48. * instance. This method includes a check that the type of the
  49. * given value is the same as the row type of this instance, but not
  50. * a check for existing instances of the given value. The value
  51. * must also not be <code>null</code>. Possible indices are
  52. * returned by the {@link TabularType#getIndexNames()} method of
  53. * this instance's tabular type. The returned indices are the
  54. * values of the fields in the supplied {@link CompositeData}
  55. * instance that match the names given in the {@link TabularType}.
  56. *
  57. * @param val the {@link CompositeData} value whose index should
  58. * be calculated.
  59. * @return the index the value would take on, if it were to be added.
  60. * @throws NullPointerException if the value is <code>null</code>.
  61. * @throws InvalidOpenTypeException if the value does not match the
  62. * row type of this instance.
  63. */
  64. Object[] calculateIndex(CompositeData val);
  65. /**
  66. * Removes all {@link CompositeData} values from the table.
  67. */
  68. void clear();
  69. /**
  70. * Returns true iff this instance of the {@link TabularData} class
  71. * contains a {@link CompositeData} value at the specified index.
  72. * In any other circumstance, including if the given key
  73. * is <code>null</code> or of the incorrect type, according to
  74. * the {@link TabularType} of this instance, this method returns
  75. * false.
  76. *
  77. * @param key the key to test for.
  78. * @return true if the key maps to a {@link CompositeData} value.
  79. */
  80. boolean containsKey(Object[] key);
  81. /**
  82. * Returns true iff this instance of the {@link TabularData} class
  83. * contains the specified {@link CompositeData} value.
  84. * In any other circumstance, including if the given value
  85. * is <code>null</code> or of the incorrect type, according to
  86. * the {@link TabularType} of this instance, this method returns
  87. * false.
  88. *
  89. * @param val the value to test for.
  90. * @return true if the value exists.
  91. */
  92. boolean containsValue(CompositeData val);
  93. /**
  94. * Compares the specified object with this object for equality.
  95. * The object is judged equivalent if it is non-null, and also
  96. * an instance of {@link TabularData} with the same row type,
  97. * and {@link CompositeData} values. The two compared instances may
  98. * be equivalent even if they represent different implementations
  99. * of {@link TabularData}.
  100. *
  101. * @param obj the object to compare for equality.
  102. * @return true if <code>obj</code> is equal to <code>this</code>.
  103. */
  104. boolean equals(Object obj);
  105. /**
  106. * Retrieves the {@link CompositeData} value for the specified
  107. * key, or <code>null</code> if no such mapping exists.
  108. *
  109. * @param key the key whose value should be returned.
  110. * @return the matching {@link CompositeData} value, or
  111. * <code>null</code> if one does not exist.
  112. * @throws NullPointerException if the key is <code>null</code>.
  113. * @throws InvalidKeyException if the key does not match
  114. * the {@link TabularType} of this
  115. * instance.
  116. */
  117. CompositeData get(Object[] key);
  118. /**
  119. * Returns the tabular type which corresponds to this instance
  120. * of {@link TabularData}.
  121. *
  122. * @return the tabular type for this instance.
  123. */
  124. TabularType getTabularType();
  125. /**
  126. * Returns the hash code of the composite data type. This is
  127. * computed as the sum of the hash codes of each value, together
  128. * with the hash code of the tabular type. These are the same
  129. * elements of the type that are compared as part of the {@link
  130. * #equals(java.lang.Object)} method, thus ensuring that the
  131. * hashcode is compatible with the equality test.
  132. *
  133. * @return the hash code of this instance.
  134. */
  135. int hashCode();
  136. /**
  137. * Returns true if this {@link TabularData} instance
  138. * contains no {@link CompositeData} values.
  139. *
  140. * @return true if the instance is devoid of rows.
  141. */
  142. boolean isEmpty();
  143. /**
  144. * Returns a {@link java.util.Set} view of the keys or
  145. * indices of this {@link TabularData} instance.
  146. *
  147. * @return a set containing the keys of this instance.
  148. */
  149. Set<?> keySet();
  150. /**
  151. * Adds the specified {@link CompositeData} value to the
  152. * table. The value must be non-null, of the same type
  153. * as the row type of this instance, and must not have
  154. * the same index as an existing value. The index is
  155. * calculated using the index names of the
  156. * {@link TabularType} for this instance.
  157. *
  158. * @param val the {@link CompositeData} value to add.
  159. * @throws NullPointerException if <code>val</code> is
  160. * <code>null</code>.
  161. * @throws InvalidOpenTypeException if the type of the
  162. * given value does not
  163. * match the row type.
  164. * @throws KeyAlreadyExistsException if the value has the
  165. * same calculated index
  166. * as an existing value.
  167. */
  168. void put(CompositeData val);
  169. /**
  170. * Adds each of the specified {@link CompositeData} values
  171. * to the table. Each element of the array must meet the
  172. * conditions given for the {@link #put(CompositeData)}
  173. * method. In addition, the index of each value in the
  174. * array must be distinct from the index of the other
  175. * values in the array, as well as from the existing values
  176. * in the table. The operation should be atomic; if one
  177. * value can not be added, then none of the values should
  178. * be. If the array is <code>null</code> or empty, the
  179. * method simply returns.
  180. *
  181. * @param vals the {@link CompositeData} values to add.
  182. * @throws NullPointerException if a value from the array is
  183. * <code>null</code>.
  184. * @throws InvalidOpenTypeException if the type of a
  185. * given value does not
  186. * match the row type.
  187. * @throws KeyAlreadyExistsException if a value has the
  188. * same calculated index
  189. * as an existing value or
  190. * of one of the other
  191. * specified values.
  192. */
  193. void putAll(CompositeData[] vals);
  194. /**
  195. * Removes the {@link CompositeData} value located at the
  196. * specified index. <code>null</code> is returned if the
  197. * value does not exist. Otherwise, the removed value is
  198. * returned.
  199. *
  200. * @param key the key of the value to remove.
  201. * @return the removed value, or <code>null</code> if
  202. * there is no value for the given key.
  203. * @throws NullPointerException if the key is <code>null</code>.
  204. * @throws InvalidOpenTypeException if the key does not match
  205. * the {@link TabularType} of this
  206. * instance.
  207. */
  208. CompositeData remove(Object[] key);
  209. /**
  210. * Returns the number of {@link CompositeData} values or rows
  211. * in the table.
  212. *
  213. * @return the number of rows in the table.
  214. */
  215. int size();
  216. /**
  217. * Returns a textual representation of this instance. The
  218. * exact format is left up to the implementation, but it
  219. * should contain the name of the implementing class and
  220. * the tabular type.
  221. *
  222. * @return a {@link java.lang.String} representation of the
  223. * object.
  224. */
  225. String toString();
  226. /**
  227. * Returns the values associated with this instance.
  228. *
  229. * @return the values of this instance.
  230. */
  231. Collection<?> values();
  232. }