1. /*
  2. * @(#)TabularData.java 3.19 04/02/10
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.management.openmbean;
  8. // java import
  9. //
  10. import java.io.Serializable;
  11. import java.util.Map;
  12. import java.util.Set;
  13. import java.util.Collection;
  14. // jmx import
  15. //
  16. /**
  17. * The <tt>TabularData</tt> interface specifies the behavior of a specific type of complex <i>open data</i> objects
  18. * which represent <i>tabular data</i> structures.
  19. *
  20. * @version 3.19 04/02/10
  21. * @author Sun Microsystems, Inc.
  22. *
  23. * @since 1.5
  24. * @since.unbundled JMX 1.1
  25. */
  26. public interface TabularData /*extends Map*/ {
  27. /* *** TabularData specific information methods *** */
  28. /**
  29. * Returns the <i>tabular type</i> describing this
  30. * <tt>TabularData</tt> instance.
  31. *
  32. * @return the tabular type.
  33. */
  34. public TabularType getTabularType();
  35. /**
  36. * Calculates the index that would be used in this <tt>TabularData</tt> instance to refer to the specified
  37. * composite data <var>value</var> parameter if it were added to this instance.
  38. * This method checks for the type validity of the specified <var>value</var>,
  39. * but does not check if the calculated index is already used to refer to a value in this <tt>TabularData</tt> instance.
  40. *
  41. * @param value the composite data value whose index in this
  42. * <tt>TabularData</tt> instance is to be calculated;
  43. * must be of the same composite type as this instance's row type;
  44. * must not be null.
  45. *
  46. * @return the index that the specified <var>value</var> would have in this <tt>TabularData</tt> instance.
  47. *
  48. * @throws NullPointerException if <var>value</var> is <tt>null</tt>
  49. *
  50. * @throws InvalidOpenTypeException if <var>value</var> does not conform to this <tt>TabularData</tt> instance's
  51. * row type definition.
  52. */
  53. public Object[] calculateIndex(CompositeData value) ;
  54. /* *** Content information query methods *** */
  55. /**
  56. * Returns the number of <tt>CompositeData</tt> values (ie the
  57. * number of rows) contained in this <tt>TabularData</tt>
  58. * instance.
  59. *
  60. * @return the number of values contained.
  61. */
  62. public int size() ;
  63. /**
  64. * Returns <tt>true</tt> if the number of <tt>CompositeData</tt>
  65. * values (ie the number of rows) contained in this
  66. * <tt>TabularData</tt> instance is zero.
  67. *
  68. * @return true if this <tt>TabularData</tt> is empty.
  69. */
  70. public boolean isEmpty() ;
  71. /**
  72. * Returns <tt>true</tt> if and only if this <tt>TabularData</tt> instance contains a <tt>CompositeData</tt> value
  73. * (ie a row) whose index is the specified <var>key</var>. If <var>key</var> is <tt>null</tt> or does not conform to
  74. * this <tt>TabularData</tt> instance's <tt>TabularType</tt> definition, this method simply returns <tt>false</tt>.
  75. *
  76. * @param key the index value whose presence in this <tt>TabularData</tt> instance is to be tested.
  77. *
  78. * @return <tt>true</tt> if this <tt>TabularData</tt> indexes a row value with the specified key.
  79. */
  80. public boolean containsKey(Object[] key) ;
  81. /**
  82. * Returns <tt>true</tt> if and only if this <tt>TabularData</tt> instance contains the specified
  83. * <tt>CompositeData</tt> value. If <var>value</var> is <tt>null</tt> or does not conform to
  84. * this <tt>TabularData</tt> instance's row type definition, this method simply returns <tt>false</tt>.
  85. *
  86. * @param value the row value whose presence in this <tt>TabularData</tt> instance is to be tested.
  87. *
  88. * @return <tt>true</tt> if this <tt>TabularData</tt> instance contains the specified row value.
  89. */
  90. public boolean containsValue(CompositeData value) ;
  91. /**
  92. * Returns the <tt>CompositeData</tt> value whose index is
  93. * <var>key</var>, or <tt>null</tt> if there is no value mapping
  94. * to <var>key</var>, in this <tt>TabularData</tt> instance.
  95. *
  96. * @param key the key of the row to return.
  97. *
  98. * @return the value corresponding to <var>key</var>.
  99. *
  100. * @throws NullPointerException if the <var>key</var> is
  101. * <tt>null</tt>
  102. * @throws InvalidKeyException if the <var>key</var> does not
  103. * conform to this <tt>TabularData</tt> instance's *
  104. * <tt>TabularType</tt> definition
  105. */
  106. public CompositeData get(Object[] key) ;
  107. /* *** Content modification operations (one element at a time) *** */
  108. /**
  109. * Adds <var>value</var> to this <tt>TabularData</tt> instance.
  110. * The composite type of <var>value</var> must be the same as this
  111. * instance's row type (ie the composite type returned by
  112. * <tt>this.getTabularType().{@link TabularType#getRowType
  113. * getRowType()}</tt>), and there must not already be an existing
  114. * value in this <tt>TabularData</tt> instance whose index is the
  115. * same as the one calculated for the <var>value</var> to be
  116. * added. The index for <var>value</var> is calculated according
  117. * to this <tt>TabularData</tt> instance's <tt>TabularType</tt>
  118. * definition (see <tt>TabularType.{@link
  119. * TabularType#getIndexNames getIndexNames()}</tt>).
  120. *
  121. * @param value the composite data value to be added as a new row to this <tt>TabularData</tt> instance;
  122. * must be of the same composite type as this instance's row type;
  123. * must not be null.
  124. *
  125. * @throws NullPointerException if <var>value</var> is <tt>null</tt>
  126. * @throws InvalidOpenTypeException if <var>value</var> does not conform to this <tt>TabularData</tt> instance's
  127. * row type definition.
  128. * @throws KeyAlreadyExistsException if the index for <var>value</var>, calculated according to
  129. * this <tt>TabularData</tt> instance's <tt>TabularType</tt> definition
  130. * already maps to an existing value in the underlying HashMap.
  131. */
  132. public void put(CompositeData value) ;
  133. /**
  134. * Removes the <tt>CompositeData</tt> value whose index is <var>key</var> from this <tt>TabularData</tt> instance,
  135. * and returns the removed value, or returns <tt>null</tt> if there is no value whose index is <var>key</var>.
  136. *
  137. * @param key the index of the value to get in this <tt>TabularData</tt> instance;
  138. * must be valid with this <tt>TabularData</tt> instance's row type definition;
  139. * must not be null.
  140. *
  141. * @return previous value associated with specified key, or <tt>null</tt>
  142. * if there was no mapping for key.
  143. *
  144. * @throws NullPointerException if the <var>key</var> is <tt>null</tt>
  145. * @throws InvalidKeyException if the <var>key</var> does not conform to this <tt>TabularData</tt> instance's
  146. * <tt>TabularType</tt> definition
  147. */
  148. public CompositeData remove(Object[] key) ;
  149. /* *** Content modification bulk operations *** */
  150. /**
  151. * Add all the elements in <var>values</var> to this <tt>TabularData</tt> instance.
  152. * If any element in <var>values</var> does not satisfy the constraints defined in {@link #put(CompositeData) <tt>put</tt>},
  153. * or if any two elements in <var>values</var> have the same index calculated according to this <tt>TabularData</tt>
  154. * instance's <tt>TabularType</tt> definition, then an exception describing the failure is thrown
  155. * and no element of <var>values</var> is added, thus leaving this <tt>TabularData</tt> instance unchanged.
  156. *
  157. * @param values the array of composite data values to be added as new rows to this <tt>TabularData</tt> instance;
  158. * if <var>values</var> is <tt>null</tt> or empty, this method returns without doing anything.
  159. *
  160. * @throws NullPointerException if an element of <var>values</var> is <tt>null</tt>
  161. * @throws InvalidOpenTypeException if an element of <var>values</var> does not conform to
  162. * this <tt>TabularData</tt> instance's row type definition
  163. * @throws KeyAlreadyExistsException if the index for an element of <var>values</var>, calculated according to
  164. * this <tt>TabularData</tt> instance's <tt>TabularType</tt> definition
  165. * already maps to an existing value in this instance,
  166. * or two elements of <var>values</var> have the same index.
  167. */
  168. public void putAll(CompositeData[] values) ;
  169. /**
  170. * Removes all <tt>CompositeData</tt> values (ie rows) from this <tt>TabularData</tt> instance.
  171. */
  172. public void clear();
  173. /* *** Collection views of the keys and values *** */
  174. /**
  175. * Returns a set view of the keys (ie the index values) of the <tt>CompositeData</tt> values (ie the rows)
  176. * contained in this <tt>TabularData</tt> instance. The returned Set can then be used to iterate over the keys.
  177. *
  178. * @return a set view of the index values used in this <tt>TabularData</tt> instance.
  179. */
  180. public Set keySet();
  181. /**
  182. * Returns a collection view of the <tt>CompositeData</tt> values (ie the rows)
  183. * contained in this <tt>TabularData</tt> instance.
  184. * The returned collection can then be used to iterate over the values.
  185. *
  186. * @return a collection view of the rows contained in this <tt>TabularData</tt> instance.
  187. */
  188. public Collection values();
  189. /* *** Commodity methods from java.lang.Object *** */
  190. /**
  191. * Compares the specified <var>obj</var> parameter with this <code>TabularData</code> instance for equality.
  192. * <p>
  193. * Returns <tt>true</tt> if and only if all of the following statements are true:
  194. * <ul>
  195. * <li><var>obj</var> is non null,</li>
  196. * <li><var>obj</var> also implements the <code>TabularData</code> interface,</li>
  197. * <li>their row types are equal</li>
  198. * <li>their contents (ie index to value mappings) are equal</li>
  199. * </ul>
  200. * This ensures that this <tt>equals</tt> method works properly for <var>obj</var> parameters which are
  201. * different implementations of the <code>TabularData</code> interface.
  202. * <br> 
  203. * @param obj the object to be compared for equality with this <code>TabularData</code> instance;
  204. *
  205. * @return <code>true</code> if the specified object is equal to this <code>TabularData</code> instance.
  206. */
  207. public boolean equals(Object obj);
  208. /**
  209. * Returns the hash code value for this <code>TabularData</code> instance.
  210. * <p>
  211. * The hash code of a <code>TabularData</code> instance is the sum of the hash codes
  212. * of all elements of information used in <code>equals</code> comparisons
  213. * (ie: its <i>tabular type</i> and its content, where the content is defined as all the index to value mappings).
  214. * <p>
  215. * This ensures that <code> t1.equals(t2) </code> implies that <code> t1.hashCode()==t2.hashCode() </code>
  216. * for any two <code>TabularDataSupport</code> instances <code>t1</code> and <code>t2</code>,
  217. * as required by the general contract of the method
  218. * {@link Object#hashCode() Object.hashCode()}.
  219. *
  220. * @return the hash code value for this <code>TabularDataSupport</code> instance
  221. */
  222. public int hashCode();
  223. /**
  224. * Returns a string representation of this <code>TabularData</code> instance.
  225. * <p>
  226. * The string representation consists of the name of the implementing class,
  227. * and the tabular type of this instance.
  228. *
  229. * @return a string representation of this <code>TabularData</code> instance
  230. */
  231. public String toString();
  232. }