001/* AttributeSet.java -- 
002   Copyright (C) 2002, 2005 Free Software Foundation, Inc.
003
004This file is part of GNU Classpath.
005
006GNU Classpath is free software; you can redistribute it and/or modify
007it under the terms of the GNU General Public License as published by
008the Free Software Foundation; either version 2, or (at your option)
009any later version.
010
011GNU Classpath is distributed in the hope that it will be useful, but
012WITHOUT ANY WARRANTY; without even the implied warranty of
013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014General Public License for more details.
015
016You should have received a copy of the GNU General Public License
017along with GNU Classpath; see the file COPYING.  If not, write to the
018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
01902110-1301 USA.
020
021Linking this library statically or dynamically with other modules is
022making a combined work based on this library.  Thus, the terms and
023conditions of the GNU General Public License cover the whole
024combination.
025
026As a special exception, the copyright holders of this library give you
027permission to link this library with independent modules to produce an
028executable, regardless of the license terms of these independent
029modules, and to copy and distribute the resulting executable under
030terms of your choice, provided that you also meet, for each linked
031independent module, the terms and conditions of the license of that
032module.  An independent module is a module which is not derived from
033or based on this library.  If you modify this library, you may extend
034this exception to your version of the library, but you are not
035obligated to do so.  If you do not wish to do so, delete this
036exception statement from your version. */
037
038package javax.print.attribute;
039
040/**
041 * <code>AttributeSet</code> is the top-level interface for sets of printing
042 * attributes in the Java Print Service API.
043 * <p>
044 * There are no duplicate values allowed in an attribute set and there is
045 * at most one attribute object contained per category type. Based on the
046 * {@link java.util.Map} interface the values of attribute sets are objects
047 * of type {@link javax.print.attribute.Attribute} and the entries are the
048 * categories as {@link java.lang.Class} instances.
049 * </p>
050 * <p>
051 * The following specialized types of <code>AttributeSet</code> are available:
052 * <ul>
053 *  <li>{@link javax.print.attribute.DocAttributeSet}</li>
054 *  <li>{@link javax.print.attribute.PrintRequestAttributeSet}</li>
055 *  <li>{@link javax.print.attribute.PrintJobAttributeSet}</li>
056 *  <li>{@link javax.print.attribute.PrintServiceAttributeSet}</li>
057 * </ul>
058 * </p>
059 * <p>
060 * Attribute sets may be unmodifiable depending on the context of usage. If 
061 * used as read-only attribute set modifying operations throw an 
062 * {@link javax.print.attribute.UnmodifiableSetException}.
063 * </p>
064 * <p>
065 * The Java Print Service API provides implementation classes for the existing
066 * attribute set interfaces but applications may use their own implementations.
067 * </p>
068 * 
069 * @author Michael Koch (konqueror@gmx.de)
070 */
071public interface AttributeSet
072{
073  /**
074   * Adds the specified attribute value to this attribute set 
075   * if it is not already present.
076   * 
077   * This operation removes any existing attribute of the same category 
078   * before adding the given attribute to the set. 
079   * 
080   * @param attribute the attribute to add.
081   * @return <code>true</code> if the set is changed, false otherwise.
082   * @throws NullPointerException if the attribute is <code>null</code>.
083   * @throws UnmodifiableSetException if the set does not support modification.
084   */
085  boolean add (Attribute attribute);
086
087  /**
088   * Adds all of the elements in the specified set to this attribute set.
089   * 
090   * @param attributes the set of attributes to add.
091   * @return <code>true</code> if the set is changed, false otherwise.
092   * @throws UnmodifiableSetException if the set does not support modification.
093   * 
094   * @see #add(Attribute)
095   */
096  boolean addAll (AttributeSet attributes);
097  
098  /**
099   * Removes all attributes from this attribute set.
100   * 
101   * @throws UnmodifiableSetException if the set does not support modification.
102   */
103  void clear ();
104  
105  /**
106   * Checks if this attributes set contains an attribute with the given 
107   * category.
108   * 
109   * @param category the category to test for.
110   * @return <code>true</code> if an attribute of the category is contained
111   * in the set, <code>false</code> otherwise.
112   */
113  boolean containsKey (Class<?> category);
114  
115  /**
116   * Checks if this attribute set contains the given attribute.
117   * 
118   * @param attribute the attribute to test for.
119   * @return <code>true</code> if the attribute is contained in the set,
120   * <code>false</code> otherwise.
121   */
122  boolean containsValue (Attribute attribute);
123  
124  /**
125   * Tests this set for equality with the given object. <code>true</code> is
126   * returned, if the given object is also of type <code>AttributeSet</code>
127   * and the contained attributes are the same as in this set.
128   * 
129   * @param obj the Object to test.
130   * @return <code>true</code> if equal, false otherwise.
131   */
132  boolean equals (Object obj);
133  
134  /**
135   * Returns the attribute object contained in this set for the given attribute
136   * category. 
137   * 
138   * @param category the category of the attribute. A <code>Class</code> 
139   * instance of a class implementing the <code>Attribute</code> interface. 
140   * @return The attribute for this category or <code>null</code> if no 
141   * attribute is contained for the given category. 
142   * @throws NullPointerException if category is null.
143   * @throws ClassCastException if category is not implementing 
144   * <code>Attribute</code>.
145   */
146  Attribute get (Class<?> category);
147  
148  /**
149   * Returns the hashcode value. The hashcode value is the sum of all hashcodes
150   * of the attributes contained in this set.
151   * 
152   * @return The hashcode for this attribute set.
153   */
154  int hashCode ();
155  
156  /**
157   * Checks if the attribute set is empty.
158   *
159   * @return <code>true</code> if the attribute set is empty, false otherwise.
160   */
161  boolean isEmpty ();
162
163  /**
164   * Removes the given attribute from the set. If the given attribute is <code>null</code>
165   * nothing is done and <code>false</code> is returned.
166   * 
167   * @param attribute the attribute to remove.  
168   * @return <code>true</code> if removed, false in all other cases. 
169   * @throws UnmodifiableSetException if the set does not support modification.
170   */
171  boolean remove (Attribute attribute);
172  
173  /**
174   * Removes the attribute entry of the given category from the set. If the given
175   * category is <code>null</code> nothing is done and <code>false</code> is returned.
176   * 
177   * @param category the category of the entry to be removed.
178   * @return <code>true</code> if an attribute is removed, false in all other cases. 
179   * @throws UnmodifiableSetException if the set does not support modification.
180   */
181  boolean remove (Class<?> category);
182  
183  /**
184   * Returns the number of elements in this attribute set.
185   *
186   * @return The number of elements.
187   */
188  int size ();
189  
190  /**
191   * Returns the content of the attribute set as an array
192   *
193   * @return An array of attributes.
194   */
195  Attribute[] toArray ();
196}