View Javadoc
1   /*
2    * Copyright (c) 2000, 2007, Oracle and/or its affiliates. All rights reserved.
3    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4    *
5    * This code is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU General Public License version 2 only, as
7    * published by the Free Software Foundation.  Oracle designates this
8    * particular file as subject to the "Classpath" exception as provided
9    * by Oracle in the LICENSE file that accompanied this code.
10   *
11   * This code is distributed in the hope that it will be useful, but WITHOUT
12   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13   * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14   * version 2 for more details (a copy is included in the LICENSE file that
15   * accompanied this code).
16   *
17   * You should have received a copy of the GNU General Public License version
18   * 2 along with this work; if not, write to the Free Software Foundation,
19   * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20   *
21   * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22   * or visit www.oracle.com if you need additional information or have any
23   * questions.
24   */
25  
26  
27  package javax.management.openmbean;
28  
29  
30  // java import
31  //
32  import java.util.Set;
33  import java.util.Collection;
34  
35  // jmx import
36  //
37  
38  
39  /**
40   * The <tt>TabularData</tt> interface specifies the behavior of a specific type of complex <i>open data</i> objects
41   * which represent <i>tabular data</i> structures.
42   *
43   * @since 1.5
44   */
45  public interface TabularData /*extends Map*/ {
46  
47  
48      /* *** TabularData specific information methods *** */
49  
50  
51      /**
52       * Returns the <i>tabular type</i> describing this
53       * <tt>TabularData</tt> instance.
54       *
55       * @return the tabular type.
56       */
57      public TabularType getTabularType();
58  
59  
60      /**
61       * Calculates the index that would be used in this <tt>TabularData</tt> instance to refer to the specified
62       * composite data <var>value</var> parameter if it were added to this instance.
63       * This method checks for the type validity of the specified <var>value</var>,
64       * but does not check if the calculated index is already used to refer to a value in this <tt>TabularData</tt> instance.
65       *
66       * @param  value                      the composite data value whose index in this
67       *                                    <tt>TabularData</tt> instance is to be calculated;
68       *                                    must be of the same composite type as this instance's row type;
69       *                                    must not be null.
70       *
71       * @return the index that the specified <var>value</var> would have in this <tt>TabularData</tt> instance.
72       *
73       * @throws NullPointerException       if <var>value</var> is <tt>null</tt>
74       *
75       * @throws InvalidOpenTypeException   if <var>value</var> does not conform to this <tt>TabularData</tt> instance's
76       *                                    row type definition.
77       */
78      public Object[] calculateIndex(CompositeData value) ;
79  
80  
81  
82  
83      /* *** Content information query methods *** */
84  
85      /**
86       * Returns the number of <tt>CompositeData</tt> values (ie the
87       * number of rows) contained in this <tt>TabularData</tt>
88       * instance.
89       *
90       * @return the number of values contained.
91       */
92      public int size() ;
93  
94      /**
95       * Returns <tt>true</tt> if the number of <tt>CompositeData</tt>
96       * values (ie the number of rows) contained in this
97       * <tt>TabularData</tt> instance is zero.
98       *
99       * @return true if this <tt>TabularData</tt> is empty.
100      */
101     public boolean isEmpty() ;
102 
103     /**
104      * Returns <tt>true</tt> if and only if this <tt>TabularData</tt> instance contains a <tt>CompositeData</tt> value
105      * (ie a row) whose index is the specified <var>key</var>. If <var>key</var> is <tt>null</tt> or does not conform to
106      * this <tt>TabularData</tt> instance's <tt>TabularType</tt> definition, this method simply returns <tt>false</tt>.
107      *
108      * @param  key  the index value whose presence in this <tt>TabularData</tt> instance is to be tested.
109      *
110      * @return  <tt>true</tt> if this <tt>TabularData</tt> indexes a row value with the specified key.
111      */
112     public boolean containsKey(Object[] key) ;
113 
114     /**
115      * Returns <tt>true</tt> if and only if this <tt>TabularData</tt> instance contains the specified
116      * <tt>CompositeData</tt> value. If <var>value</var> is <tt>null</tt> or does not conform to
117      * this <tt>TabularData</tt> instance's row type definition, this method simply returns <tt>false</tt>.
118      *
119      * @param  value  the row value whose presence in this <tt>TabularData</tt> instance is to be tested.
120      *
121      * @return  <tt>true</tt> if this <tt>TabularData</tt> instance contains the specified row value.
122      */
123     public boolean containsValue(CompositeData value) ;
124 
125     /**
126      * Returns the <tt>CompositeData</tt> value whose index is
127      * <var>key</var>, or <tt>null</tt> if there is no value mapping
128      * to <var>key</var>, in this <tt>TabularData</tt> instance.
129      *
130      * @param key the key of the row to return.
131      *
132      * @return the value corresponding to <var>key</var>.
133      *
134      * @throws NullPointerException if the <var>key</var> is
135      * <tt>null</tt>
136      * @throws InvalidKeyException if the <var>key</var> does not
137      * conform to this <tt>TabularData</tt> instance's *
138      * <tt>TabularType</tt> definition
139      */
140     public CompositeData get(Object[] key) ;
141 
142 
143 
144 
145     /* *** Content modification operations (one element at a time) *** */
146 
147 
148     /**
149      * Adds <var>value</var> to this <tt>TabularData</tt> instance.
150      * The composite type of <var>value</var> must be the same as this
151      * instance's row type (ie the composite type returned by
152      * <tt>this.getTabularType().{@link TabularType#getRowType
153      * getRowType()}</tt>), and there must not already be an existing
154      * value in this <tt>TabularData</tt> instance whose index is the
155      * same as the one calculated for the <var>value</var> to be
156      * added. The index for <var>value</var> is calculated according
157      * to this <tt>TabularData</tt> instance's <tt>TabularType</tt>
158      * definition (see <tt>TabularType.{@link
159      * TabularType#getIndexNames getIndexNames()}</tt>).
160      *
161      * @param  value                      the composite data value to be added as a new row to this <tt>TabularData</tt> instance;
162      *                                    must be of the same composite type as this instance's row type;
163      *                                    must not be null.
164      *
165      * @throws NullPointerException       if <var>value</var> is <tt>null</tt>
166      * @throws InvalidOpenTypeException   if <var>value</var> does not conform to this <tt>TabularData</tt> instance's
167      *                                    row type definition.
168      * @throws KeyAlreadyExistsException  if the index for <var>value</var>, calculated according to
169      *                                    this <tt>TabularData</tt> instance's <tt>TabularType</tt> definition
170      *                                    already maps to an existing value in the underlying HashMap.
171      */
172     public void put(CompositeData value) ;
173 
174     /**
175      * Removes the <tt>CompositeData</tt> value whose index is <var>key</var> from this <tt>TabularData</tt> instance,
176      * and returns the removed value, or returns <tt>null</tt> if there is no value whose index is <var>key</var>.
177      *
178      * @param  key  the index of the value to get in this <tt>TabularData</tt> instance;
179      *              must be valid with this <tt>TabularData</tt> instance's row type definition;
180      *              must not be null.
181      *
182      * @return previous value associated with specified key, or <tt>null</tt>
183      *         if there was no mapping for key.
184      *
185      * @throws NullPointerException  if the <var>key</var> is <tt>null</tt>
186      * @throws InvalidKeyException   if the <var>key</var> does not conform to this <tt>TabularData</tt> instance's
187      *                               <tt>TabularType</tt> definition
188      */
189     public CompositeData remove(Object[] key) ;
190 
191 
192 
193 
194     /* ***   Content modification bulk operations   *** */
195 
196 
197     /**
198      * Add all the elements in <var>values</var> to this <tt>TabularData</tt> instance.
199      * If any  element in <var>values</var> does not satisfy the constraints defined in {@link #put(CompositeData) <tt>put</tt>},
200      * or if any two elements in <var>values</var> have the same index calculated according to this <tt>TabularData</tt>
201      * instance's <tt>TabularType</tt> definition, then an exception describing the failure is thrown
202      * and no element of <var>values</var> is added,  thus leaving this <tt>TabularData</tt> instance unchanged.
203      *
204      * @param  values  the array of composite data values to be added as new rows to this <tt>TabularData</tt> instance;
205      *                 if <var>values</var> is <tt>null</tt> or empty, this method returns without doing anything.
206      *
207      * @throws NullPointerException       if an element of <var>values</var> is <tt>null</tt>
208      * @throws InvalidOpenTypeException   if an element of <var>values</var> does not conform to
209      *                                    this <tt>TabularData</tt> instance's row type definition
210      * @throws KeyAlreadyExistsException  if the index for an element of <var>values</var>, calculated according to
211      *                                    this <tt>TabularData</tt> instance's <tt>TabularType</tt> definition
212      *                                    already maps to an existing value in this instance,
213      *                                    or two elements of <var>values</var> have the same index.
214      */
215     public void putAll(CompositeData[] values) ;
216 
217     /**
218      * Removes all <tt>CompositeData</tt> values (ie rows) from this <tt>TabularData</tt> instance.
219      */
220     public void clear();
221 
222 
223 
224 
225     /* ***   Collection views of the keys and values   *** */
226 
227 
228     /**
229      * Returns a set view of the keys (ie the index values) of the
230      * {@code CompositeData} values (ie the rows) contained in this
231      * {@code TabularData} instance. The returned {@code Set} is a
232      * {@code Set<List<?>>} but is declared as a {@code Set<?>} for
233      * compatibility reasons. The returned set can be used to iterate
234      * over the keys.
235      *
236      * @return a set view ({@code Set<List<?>>}) of the index values
237      * used in this {@code TabularData} instance.
238      */
239     public Set<?> keySet();
240 
241     /**
242      * Returns a collection view of the {@code CompositeData} values
243      * (ie the rows) contained in this {@code TabularData} instance.
244      * The returned {@code Collection} is a {@code Collection<CompositeData>}
245      * but is declared as a {@code Collection<?>} for compatibility reasons.
246      * The returned collection can be used to iterate over the values.
247      *
248      * @return a collection view ({@code Collection<CompositeData>})
249      * of the rows contained in this {@code TabularData} instance.
250      */
251     public Collection<?> values();
252 
253 
254 
255 
256     /* ***  Commodity methods from java.lang.Object  *** */
257 
258 
259     /**
260      * Compares the specified <var>obj</var> parameter with this <code>TabularData</code> instance for equality.
261      * <p>
262      * Returns <tt>true</tt> if and only if all of the following statements are true:
263      * <ul>
264      * <li><var>obj</var> is non null,</li>
265      * <li><var>obj</var> also implements the <code>TabularData</code> interface,</li>
266      * <li>their row types are equal</li>
267      * <li>their contents (ie index to value mappings) are equal</li>
268      * </ul>
269      * This ensures that this <tt>equals</tt> method works properly for <var>obj</var> parameters which are
270      * different implementations of the <code>TabularData</code> interface.
271      * <br>&nbsp;
272      * @param  obj  the object to be compared for equality with this <code>TabularData</code> instance;
273      *
274      * @return  <code>true</code> if the specified object is equal to this <code>TabularData</code> instance.
275      */
276     public boolean equals(Object obj);
277 
278     /**
279      * Returns the hash code value for this <code>TabularData</code> instance.
280      * <p>
281      * The hash code of a <code>TabularData</code> instance is the sum of the hash codes
282      * of all elements of information used in <code>equals</code> comparisons
283      * (ie: its <i>tabular type</i> and its content, where the content is defined as all the index to value mappings).
284      * <p>
285      * This ensures that <code> t1.equals(t2) </code> implies that <code> t1.hashCode()==t2.hashCode() </code>
286      * for any two <code>TabularDataSupport</code> instances <code>t1</code> and <code>t2</code>,
287      * as required by the general contract of the method
288      * {@link Object#hashCode() Object.hashCode()}.
289      *
290      * @return  the hash code value for this <code>TabularDataSupport</code> instance
291      */
292     public int hashCode();
293 
294     /**
295      * Returns a string representation of this <code>TabularData</code> instance.
296      * <p>
297      * The string representation consists of the name of the implementing class,
298      * and the tabular type of this instance.
299      *
300      * @return  a string representation of this <code>TabularData</code> instance
301      */
302     public String toString();
303 
304 }