CompositeData.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /* CompositeData.java -- A composite data structure.
  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. /**
  34. * Provides an interface to a composite data structure,
  35. * in order to aid interoperability. The composite data
  36. * structure is represented by mapping field names to
  37. * values.
  38. *
  39. * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
  40. * @since 1.5
  41. */
  42. public interface CompositeData
  43. {
  44. /**
  45. * Returns true if this {@link CompositeData} instance contains
  46. * the specified key. This method always returns false for
  47. * an input key equal to <code>null</code> or the empty string.
  48. *
  49. * @param key the key to find in the structure.
  50. * @return true if the key exists.
  51. */
  52. boolean containsKey(String key);
  53. /**
  54. * Returns true if this {@link CompositeData} instance has
  55. * a value equal to that supplied.
  56. *
  57. * @param value the value to look for.
  58. * @return true if the value exists.
  59. */
  60. boolean containsValue(Object value);
  61. /**
  62. * Compares the specified object with this object for equality.
  63. * The object is judged equivalent if it is non-null, and also
  64. * an instance of {@link CompositeData} with the same name-value
  65. * mappings and types. The two compared instances may be
  66. * equivalent even if they represent different implementations of
  67. * {@link CompositeData}.
  68. *
  69. * @param obj the object to compare for equality.
  70. * @return true if <code>obj</code> is equal to <code>this</code>.
  71. */
  72. boolean equals(Object obj);
  73. /**
  74. * Retrieves the value for the specified key.
  75. *
  76. * @param key the key whose value should be returned.
  77. * @return the matching value.
  78. * @throws IllegalArgumentException if the key is <code>null</code>
  79. * or the empty string.
  80. * @throws InvalidKeyException if the key does not exist.
  81. */
  82. Object get(String key);
  83. /**
  84. * Returns the appropriate value for each key in the given array,
  85. * using the same ordering.
  86. *
  87. * @param keys the keys whose values should be returned.
  88. * @return the matching values.
  89. * @throws IllegalArgumentException if one of the keys is
  90. * <code>null</code> or the
  91. * empty string.
  92. * @throws InvalidKeyException if one of the keys does not exist.
  93. */
  94. Object[] getAll(String[] keys);
  95. /**
  96. * Returns the composite type which corresponds to this instance
  97. * of {@link CompositeData}.
  98. *
  99. * @return the composite type for this instance.
  100. */
  101. CompositeType getCompositeType();
  102. /**
  103. * Returns the hash code of this instance. The hash code is
  104. * computed as the sum of the hash codes of all the values plus
  105. * the hash code of the composite type. As equality comparisons
  106. * take place using this same information, this ensures that
  107. * the property, <code>e1.equals(e2)</code> implies
  108. * <code>e1.hashCode() == e2.hashCode(), holds for any pair
  109. * of instances, <code>e1</code> and <code>e2</code>.
  110. *
  111. * @return the hash code of this {@link CompositeData}.
  112. * @see Object#equals(Object)
  113. */
  114. int hashCode();
  115. /**
  116. * Returns a textual representation of this instance. The
  117. * exact format is left up to the implementation, but it
  118. * should contain the name of the implementing class,
  119. * the name of the type and a mapping of the form
  120. * <code>key=value</code> for each pair of key and value.
  121. *
  122. * @return a {@link java.lang.String} representation of the
  123. * object.
  124. */
  125. String toString();
  126. /**
  127. * Returns a read-only collection of the values associated with
  128. * this instance. The values are sorted using the lexicographic
  129. * ordering of the corresponding keys.
  130. *
  131. * @return the values of this instance.
  132. */
  133. Collection<?> values();
  134. }