001 /* CompositeData.java -- A composite data structure. 002 Copyright (C) 2006, 2007 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package javax.management.openmbean; 039 040 import java.util.Collection; 041 042 /** 043 * Provides an interface to a composite data structure, 044 * in order to aid interoperability. The composite data 045 * structure is represented by mapping field names to 046 * values. 047 * 048 * @author Andrew John Hughes (gnu_andrew@member.fsf.org) 049 * @since 1.5 050 */ 051 public interface CompositeData 052 { 053 054 /** 055 * Returns true if this {@link CompositeData} instance contains 056 * the specified key. This method always returns false for 057 * an input key equal to <code>null</code> or the empty string. 058 * 059 * @param key the key to find in the structure. 060 * @return true if the key exists. 061 */ 062 boolean containsKey(String key); 063 064 /** 065 * Returns true if this {@link CompositeData} instance has 066 * a value equal to that supplied. 067 * 068 * @param value the value to look for. 069 * @return true if the value exists. 070 */ 071 boolean containsValue(Object value); 072 073 /** 074 * Compares the specified object with this object for equality. 075 * The object is judged equivalent if it is non-null, and also 076 * an instance of {@link CompositeData} with the same name-value 077 * mappings and types. The two compared instances may be 078 * equivalent even if they represent different implementations of 079 * {@link CompositeData}. 080 * 081 * @param obj the object to compare for equality. 082 * @return true if <code>obj</code> is equal to <code>this</code>. 083 */ 084 boolean equals(Object obj); 085 086 /** 087 * Retrieves the value for the specified key. 088 * 089 * @param key the key whose value should be returned. 090 * @return the matching value. 091 * @throws IllegalArgumentException if the key is <code>null</code> 092 * or the empty string. 093 * @throws InvalidKeyException if the key does not exist. 094 */ 095 Object get(String key); 096 097 /** 098 * Returns the appropriate value for each key in the given array, 099 * using the same ordering. 100 * 101 * @param keys the keys whose values should be returned. 102 * @return the matching values. 103 * @throws IllegalArgumentException if one of the keys is 104 * <code>null</code> or the 105 * empty string. 106 * @throws InvalidKeyException if one of the keys does not exist. 107 */ 108 Object[] getAll(String[] keys); 109 110 /** 111 * Returns the composite type which corresponds to this instance 112 * of {@link CompositeData}. 113 * 114 * @return the composite type for this instance. 115 */ 116 CompositeType getCompositeType(); 117 118 /** 119 * Returns the hash code of this instance. The hash code is 120 * computed as the sum of the hash codes of all the values plus 121 * the hash code of the composite type. As equality comparisons 122 * take place using this same information, this ensures that 123 * the property, <code>e1.equals(e2)</code> implies 124 * <code>e1.hashCode() == e2.hashCode(), holds for any pair 125 * of instances, <code>e1</code> and <code>e2</code>. 126 * 127 * @return the hash code of this {@link CompositeData}. 128 * @see Object#equals(Object) 129 */ 130 int hashCode(); 131 132 /** 133 * Returns a textual representation of this instance. The 134 * exact format is left up to the implementation, but it 135 * should contain the name of the implementing class, 136 * the name of the type and a mapping of the form 137 * <code>key=value</code> for each pair of key and value. 138 * 139 * @return a {@link java.lang.String} representation of the 140 * object. 141 */ 142 String toString(); 143 144 /** 145 * Returns a read-only collection of the values associated with 146 * this instance. The values are sorted using the lexicographic 147 * ordering of the corresponding keys. 148 * 149 * @return the values of this instance. 150 */ 151 Collection<?> values(); 152 153 }