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 {@code TabularData} 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 * {@code TabularData} 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 {@code TabularData} 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 {@code TabularData} instance. 65 * 66 * @param value the composite data value whose index in this 67 * {@code TabularData} 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 {@code TabularData} instance. 72 * 73 * @throws NullPointerException if <var>value</var> is {@code null} 74 * 75 * @throws InvalidOpenTypeException if <var>value</var> does not conform to this {@code TabularData} 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 {@code CompositeData} values (ie the 87 * number of rows) contained in this {@code TabularData} 88 * instance. 89 * 90 * @return the number of values contained. 91 */ 92 public int size() ; 93 94 /** 95 * Returns {@code true} if the number of {@code CompositeData} 96 * values (ie the number of rows) contained in this 97 * {@code TabularData} instance is zero. 98 * 99 * @return true if this {@code TabularData} is empty. 100 */ 101 public boolean isEmpty() ; 102 103 /** 104 * Returns {@code true} if and only if this {@code TabularData} instance contains a {@code CompositeData} value 105 * (ie a row) whose index is the specified <var>key</var>. If <var>key</var> is {@code null} or does not conform to 106 * this {@code TabularData} instance's {@code TabularType} definition, this method simply returns {@code false}. 107 * 108 * @param key the index value whose presence in this {@code TabularData} instance is to be tested. 109 * 110 * @return {@code true} if this {@code TabularData} indexes a row value with the specified key. 111 */ 112 public boolean containsKey(Object[] key) ; 113 114 /** 115 * Returns {@code true} if and only if this {@code TabularData} instance contains the specified 116 * {@code CompositeData} value. If <var>value</var> is {@code null} or does not conform to 117 * this {@code TabularData} instance's row type definition, this method simply returns {@code false}. 118 * 119 * @param value the row value whose presence in this {@code TabularData} instance is to be tested. 120 * 121 * @return {@code true} if this {@code TabularData} instance contains the specified row value. 122 */ 123 public boolean containsValue(CompositeData value) ; 124 125 /** 126 * Returns the {@code CompositeData} value whose index is 127 * <var>key</var>, or {@code null} if there is no value mapping 128 * to <var>key</var>, in this {@code TabularData} 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 * {@code null} 136 * @throws InvalidKeyException if the <var>key</var> does not 137 * conform to this {@code TabularData} instance's * 138 * {@code TabularType} 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 {@code TabularData} 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 * <code>this.getTabularType().{@link TabularType#getRowType 153 * getRowType()}</code>), and there must not already be an existing 154 * value in this {@code TabularData} 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 {@code TabularData} instance's {@code TabularType} 158 * definition (see <code>TabularType.{@link 159 * TabularType#getIndexNames getIndexNames()}</code>). 160 * 161 * @param value the composite data value to be added as a new row to this {@code TabularData} 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 {@code null} 166 * @throws InvalidOpenTypeException if <var>value</var> does not conform to this {@code TabularData} instance's 167 * row type definition. 168 * @throws KeyAlreadyExistsException if the index for <var>value</var>, calculated according to 169 * this {@code TabularData} instance's {@code TabularType} definition 170 * already maps to an existing value in the underlying HashMap. 171 */ 172 public void put(CompositeData value) ; 173 174 /** 175 * Removes the {@code CompositeData} value whose index is <var>key</var> from this {@code TabularData} instance, 176 * and returns the removed value, or returns {@code null} if there is no value whose index is <var>key</var>. 177 * 178 * @param key the index of the value to get in this {@code TabularData} instance; 179 * must be valid with this {@code TabularData} instance's row type definition; 180 * must not be null. 181 * 182 * @return previous value associated with specified key, or {@code null} 183 * if there was no mapping for key. 184 * 185 * @throws NullPointerException if the <var>key</var> is {@code null} 186 * @throws InvalidKeyException if the <var>key</var> does not conform to this {@code TabularData} instance's 187 * {@code TabularType} 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 {@code TabularData} instance. 199 * If any element in <var>values</var> does not satisfy the constraints defined in {@link #put(CompositeData) put}, 200 * or if any two elements in <var>values</var> have the same index calculated according to this {@code TabularData} 201 * instance's {@code TabularType} definition, then an exception describing the failure is thrown 202 * and no element of <var>values</var> is added, thus leaving this {@code TabularData} instance unchanged. 203 * 204 * @param values the array of composite data values to be added as new rows to this {@code TabularData} instance; 205 * if <var>values</var> is {@code null} or empty, this method returns without doing anything. 206 * 207 * @throws NullPointerException if an element of <var>values</var> is {@code null} 208 * @throws InvalidOpenTypeException if an element of <var>values</var> does not conform to 209 * this {@code TabularData} instance's row type definition 210 * @throws KeyAlreadyExistsException if the index for an element of <var>values</var>, calculated according to 211 * this {@code TabularData} instance's {@code TabularType} 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 {@code CompositeData} values (ie rows) from this {@code TabularData} 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} instance for equality. 261 * <p> 262 * Returns {@code true} 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} 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 {@code equals} method works properly for <var>obj</var> parameters which are 270 * different implementations of the {@code TabularData} interface. 271 * <br> 272 * @param obj the object to be compared for equality with this {@code TabularData} instance; 273 * 274 * @return {@code true} if the specified object is equal to this {@code TabularData} instance. 275 */ 276 public boolean equals(Object obj); 277 278 /** 279 * Returns the hash code value for this {@code TabularData} instance. 280 * <p> 281 * The hash code of a {@code TabularData} instance is the sum of the hash codes 282 * of all elements of information used in {@code equals} 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)} implies that {@code t1.hashCode()==t2.hashCode()} 286 * for any two {@code TabularDataSupport} instances {@code t1} and {@code t2}, 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} instance 291 */ 292 public int hashCode(); 293 294 /** 295 * Returns a string representation of this {@code TabularData} 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} instance 301 */ 302 public String toString(); 303 304 }