AttributeSet.java 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /* AttributeSet.java --
  2. Copyright (C) 2002, 2005 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.print.attribute;
  32. /**
  33. * <code>AttributeSet</code> is the top-level interface for sets of printing
  34. * attributes in the Java Print Service API.
  35. * <p>
  36. * There are no duplicate values allowed in an attribute set and there is
  37. * at most one attribute object contained per category type. Based on the
  38. * {@link java.util.Map} interface the values of attribute sets are objects
  39. * of type {@link javax.print.attribute.Attribute} and the entries are the
  40. * categories as {@link java.lang.Class} instances.
  41. * </p>
  42. * <p>
  43. * The following specialized types of <code>AttributeSet</code> are available:
  44. * <ul>
  45. * <li>{@link javax.print.attribute.DocAttributeSet}</li>
  46. * <li>{@link javax.print.attribute.PrintRequestAttributeSet}</li>
  47. * <li>{@link javax.print.attribute.PrintJobAttributeSet}</li>
  48. * <li>{@link javax.print.attribute.PrintServiceAttributeSet}</li>
  49. * </ul>
  50. * </p>
  51. * <p>
  52. * Attribute sets may be unmodifiable depending on the context of usage. If
  53. * used as read-only attribute set modifying operations throw an
  54. * {@link javax.print.attribute.UnmodifiableSetException}.
  55. * </p>
  56. * <p>
  57. * The Java Print Service API provides implementation classes for the existing
  58. * attribute set interfaces but applications may use their own implementations.
  59. * </p>
  60. *
  61. * @author Michael Koch (konqueror@gmx.de)
  62. */
  63. public interface AttributeSet
  64. {
  65. /**
  66. * Adds the specified attribute value to this attribute set
  67. * if it is not already present.
  68. *
  69. * This operation removes any existing attribute of the same category
  70. * before adding the given attribute to the set.
  71. *
  72. * @param attribute the attribute to add.
  73. * @return <code>true</code> if the set is changed, false otherwise.
  74. * @throws NullPointerException if the attribute is <code>null</code>.
  75. * @throws UnmodifiableSetException if the set does not support modification.
  76. */
  77. boolean add (Attribute attribute);
  78. /**
  79. * Adds all of the elements in the specified set to this attribute set.
  80. *
  81. * @param attributes the set of attributes to add.
  82. * @return <code>true</code> if the set is changed, false otherwise.
  83. * @throws UnmodifiableSetException if the set does not support modification.
  84. *
  85. * @see #add(Attribute)
  86. */
  87. boolean addAll (AttributeSet attributes);
  88. /**
  89. * Removes all attributes from this attribute set.
  90. *
  91. * @throws UnmodifiableSetException if the set does not support modification.
  92. */
  93. void clear ();
  94. /**
  95. * Checks if this attributes set contains an attribute with the given
  96. * category.
  97. *
  98. * @param category the category to test for.
  99. * @return <code>true</code> if an attribute of the category is contained
  100. * in the set, <code>false</code> otherwise.
  101. */
  102. boolean containsKey (Class<?> category);
  103. /**
  104. * Checks if this attribute set contains the given attribute.
  105. *
  106. * @param attribute the attribute to test for.
  107. * @return <code>true</code> if the attribute is contained in the set,
  108. * <code>false</code> otherwise.
  109. */
  110. boolean containsValue (Attribute attribute);
  111. /**
  112. * Tests this set for equality with the given object. <code>true</code> is
  113. * returned, if the given object is also of type <code>AttributeSet</code>
  114. * and the contained attributes are the same as in this set.
  115. *
  116. * @param obj the Object to test.
  117. * @return <code>true</code> if equal, false otherwise.
  118. */
  119. boolean equals (Object obj);
  120. /**
  121. * Returns the attribute object contained in this set for the given attribute
  122. * category.
  123. *
  124. * @param category the category of the attribute. A <code>Class</code>
  125. * instance of a class implementing the <code>Attribute</code> interface.
  126. * @return The attribute for this category or <code>null</code> if no
  127. * attribute is contained for the given category.
  128. * @throws NullPointerException if category is null.
  129. * @throws ClassCastException if category is not implementing
  130. * <code>Attribute</code>.
  131. */
  132. Attribute get (Class<?> category);
  133. /**
  134. * Returns the hashcode value. The hashcode value is the sum of all hashcodes
  135. * of the attributes contained in this set.
  136. *
  137. * @return The hashcode for this attribute set.
  138. */
  139. int hashCode ();
  140. /**
  141. * Checks if the attribute set is empty.
  142. *
  143. * @return <code>true</code> if the attribute set is empty, false otherwise.
  144. */
  145. boolean isEmpty ();
  146. /**
  147. * Removes the given attribute from the set. If the given attribute is <code>null</code>
  148. * nothing is done and <code>false</code> is returned.
  149. *
  150. * @param attribute the attribute to remove.
  151. * @return <code>true</code> if removed, false in all other cases.
  152. * @throws UnmodifiableSetException if the set does not support modification.
  153. */
  154. boolean remove (Attribute attribute);
  155. /**
  156. * Removes the attribute entry of the given category from the set. If the given
  157. * category is <code>null</code> nothing is done and <code>false</code> is returned.
  158. *
  159. * @param category the category of the entry to be removed.
  160. * @return <code>true</code> if an attribute is removed, false in all other cases.
  161. * @throws UnmodifiableSetException if the set does not support modification.
  162. */
  163. boolean remove (Class<?> category);
  164. /**
  165. * Returns the number of elements in this attribute set.
  166. *
  167. * @return The number of elements.
  168. */
  169. int size ();
  170. /**
  171. * Returns the content of the attribute set as an array
  172. *
  173. * @return An array of attributes.
  174. */
  175. Attribute[] toArray ();
  176. }