Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/javax/print/attribute/AttributeSet.java
38918 views
/*1* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print.attribute;2627/**28* Interface AttributeSet specifies the interface for a set of printing29* attributes. A printing attribute is an object whose class implements30* interface {@link Attribute Attribute}.31* <P>32* An attribute set contains a group of <I>attribute values,</I>33* where duplicate values are not allowed in the set.34* Furthermore, each value in an attribute set is35* a member of some <I>category,</I> and at most one value in any particular36* category is allowed in the set. For an attribute set, the values are {@link37* Attribute Attribute} objects, and the categories are {@link java.lang.Class38* Class} objects. An attribute's category is the class (or interface) at the39* root of the class hierarchy for that kind of attribute. Note that an40* attribute object's category may be a superclass of the attribute object's41* class rather than the attribute object's class itself. An attribute42* object's43* category is determined by calling the {@link Attribute#getCategory()44* getCategory()} method defined in interface {@link Attribute45* Attribute}.46* <P>47* The interfaces of an AttributeSet resemble those of the Java Collections48* API's java.util.Map interface, but is more restrictive in the types49* it will accept, and combines keys and values into an Attribute.50* <P>51* Attribute sets are used in several places in the Print Service API. In52* each context, only certain kinds of attributes are allowed to appear in the53* attribute set, as determined by the tagging interfaces which the attribute54* class implements -- {@link DocAttribute DocAttribute}, {@link55* PrintRequestAttribute PrintRequestAttribute}, {@link PrintJobAttribute56* PrintJobAttribute}, and {@link PrintServiceAttribute57* PrintServiceAttribute}.58* There are four specializations of an attribute set that are restricted to59* contain just one of the four kinds of attribute -- {@link DocAttributeSet60* DocAttributeSet}, {@link PrintRequestAttributeSet61* PrintRequestAttributeSet},62* {@link PrintJobAttributeSet PrintJobAttributeSet}, and {@link63* PrintServiceAttributeSet PrintServiceAttributeSet}, respectively. Note that64* many attribute classes implement more than one tagging interface and so may65* appear in more than one context.66* <UL>67* <LI>68* A {@link DocAttributeSet DocAttributeSet}, containing {@link DocAttribute69* DocAttribute}s, specifies the characteristics of an individual doc and the70* print job settings to be applied to an individual doc.71* <P>72* <LI>73* A {@link PrintRequestAttributeSet PrintRequestAttributeSet}, containing74* {@link PrintRequestAttribute PrintRequestAttribute}s, specifies the75* settings76* to be applied to a whole print job and to all the docs in the print job.77* <P>78* <LI>79* A {@link PrintJobAttributeSet PrintJobAttributeSet}, containing {@link80* PrintJobAttribute PrintJobAttribute}s, reports the status of a print job.81* <P>82* <LI>83* A {@link PrintServiceAttributeSet PrintServiceAttributeSet}, containing84* {@link PrintServiceAttribute PrintServiceAttribute}s, reports the status of85* a Print Service instance.86* </UL>87* <P>88* In some contexts, the client is only allowed to examine an attribute set's89* contents but not change them (the set is read-only). In other places, the90* client is allowed both to examine and to change an attribute set's contents91* (the set is read-write). For a read-only attribute set, calling a mutating92* operation throws an UnmodifiableSetException.93* <P>94* The Print Service API provides one implementation of interface95* AttributeSet, class {@link HashAttributeSet HashAttributeSet}.96* A client can use class {@link97* HashAttributeSet HashAttributeSet} or provide its own implementation of98* interface AttributeSet. The Print Service API also provides99* implementations of interface AttributeSet's subinterfaces -- classes {@link100* HashDocAttributeSet HashDocAttributeSet},101* {@link HashPrintRequestAttributeSet102* HashPrintRequestAttributeSet}, {@link HashPrintJobAttributeSet103* HashPrintJobAttributeSet}, and {@link HashPrintServiceAttributeSet104* HashPrintServiceAttributeSet}.105* <P>106*107* @author Alan Kaminsky108*/109public interface AttributeSet {110111112/**113* Returns the attribute value which this attribute set contains in the114* given attribute category. Returns <tt>null</tt> if this attribute set115* does not contain any attribute value in the given attribute category.116*117* @param category Attribute category whose associated attribute value118* is to be returned. It must be a119* {@link java.lang.Class Class}120* that implements interface {@link Attribute121* Attribute}.122*123* @return The attribute value in the given attribute category contained124* in this attribute set, or <tt>null</tt> if this attribute set125* does not contain any attribute value in the given attribute126* category.127*128* @throws NullPointerException129* (unchecked exception) Thrown if the <CODE>category</CODE> is null.130* @throws ClassCastException131* (unchecked exception) Thrown if the <CODE>category</CODE> is not a132* {@link java.lang.Class Class} that implements interface {@link133* Attribute Attribute}.134*/135public Attribute get(Class<?> category);136137/**138* Adds the specified attribute to this attribute set if it is not139* already present, first removing any existing value in the same140* attribute category as the specified attribute value.141*142* @param attribute Attribute value to be added to this attribute set.143*144* @return <tt>true</tt> if this attribute set changed as a result of the145* call, i.e., the given attribute value was not already a member146* of this attribute set.147*148* @throws NullPointerException149* (unchecked exception) Thrown if the <CODE>attribute</CODE> is null.150* @throws UnmodifiableSetException151* (unchecked exception) Thrown if this attribute set does not support152* the <CODE>add()</CODE> operation.153*/154public boolean add(Attribute attribute);155156157/**158* Removes any attribute for this category from this attribute set if159* present. If <CODE>category</CODE> is null, then160* <CODE>remove()</CODE> does nothing and returns <tt>false</tt>.161*162* @param category Attribute category to be removed from this163* attribute set.164*165* @return <tt>true</tt> if this attribute set changed as a result of the166* call, i.e., the given attribute value had been a member of this167* attribute set.168*169* @throws UnmodifiableSetException170* (unchecked exception) Thrown if this attribute set does not support171* the <CODE>remove()</CODE> operation.172*/173public boolean remove(Class<?> category);174175/**176* Removes the specified attribute from this attribute set if177* present. If <CODE>attribute</CODE> is null, then178* <CODE>remove()</CODE> does nothing and returns <tt>false</tt>.179*180* @param attribute Attribute value to be removed from this attribute set.181*182* @return <tt>true</tt> if this attribute set changed as a result of the183* call, i.e., the given attribute value had been a member of this184* attribute set.185*186* @throws UnmodifiableSetException187* (unchecked exception) Thrown if this attribute set does not support188* the <CODE>remove()</CODE> operation.189*/190public boolean remove(Attribute attribute);191192/**193* Returns <tt>true</tt> if this attribute set contains an194* attribute for the specified category.195*196* @param category whose presence in this attribute set is197* to be tested.198*199* @return <tt>true</tt> if this attribute set contains an attribute200* value for the specified category.201*/202public boolean containsKey(Class<?> category);203204/**205* Returns <tt>true</tt> if this attribute set contains the given206* attribute value.207*208* @param attribute Attribute value whose presence in this209* attribute set is to be tested.210*211* @return <tt>true</tt> if this attribute set contains the given212* attribute value.213*/214public boolean containsValue(Attribute attribute);215216/**217* Adds all of the elements in the specified set to this attribute.218* The outcome is the same as if the =219* {@link #add(Attribute) add(Attribute)}220* operation had been applied to this attribute set successively with each221* element from the specified set.222* The behavior of the <CODE>addAll(AttributeSet)</CODE>223* operation is unspecified if the specified set is modified while224* the operation is in progress.225* <P>226* If the <CODE>addAll(AttributeSet)</CODE> operation throws an exception,227* the effect on this attribute set's state is implementation dependent;228* elements from the specified set before the point of the exception may229* or may not have been added to this attribute set.230*231* @param attributes whose elements are to be added to this attribute232* set.233*234* @return <tt>true</tt> if this attribute set changed as a result of the235* call.236*237* @throws UnmodifiableSetException238* (Unchecked exception) Thrown if this attribute set does not support239* the <tt>addAll(AttributeSet)</tt> method.240* @throws NullPointerException241* (Unchecked exception) Thrown if some element in the specified242* set is null.243*244* @see #add(Attribute)245*/246public boolean addAll(AttributeSet attributes);247248/**249* Returns the number of attributes in this attribute set. If this250* attribute set contains more than <tt>Integer.MAX_VALUE</tt> elements,251* returns <tt>Integer.MAX_VALUE</tt>.252*253* @return The number of attributes in this attribute set.254*/255public int size();256257/**258* Returns an array of the attributes contained in this set.259* @return the Attributes contained in this set as an array, zero length260* if the AttributeSet is empty.261*/262public Attribute[] toArray();263264265/**266* Removes all attributes from this attribute set.267*268* @throws UnmodifiableSetException269* (unchecked exception) Thrown if this attribute set does not support270* the <CODE>clear()</CODE> operation.271*/272public void clear();273274/**275* Returns true if this attribute set contains no attributes.276*277* @return true if this attribute set contains no attributes.278*/279public boolean isEmpty();280281/**282* Compares the specified object with this attribute set for equality.283* Returns <tt>true</tt> if the given object is also an attribute set and284* the two attribute sets contain the same attribute category-attribute285* value mappings. This ensures that the286* <tt>equals()</tt> method works properly across different287* implementations of the AttributeSet interface.288*289* @param object to be compared for equality with this attribute set.290*291* @return <tt>true</tt> if the specified object is equal to this292* attribute set.293*/294public boolean equals(Object object);295296/**297* Returns the hash code value for this attribute set. The hash code of an298* attribute set is defined to be the sum of the hash codes of each entry299* in the AttributeSet.300* This ensures that <tt>t1.equals(t2)</tt> implies that301* <tt>t1.hashCode()==t2.hashCode()</tt> for any two attribute sets302* <tt>t1</tt> and <tt>t2</tt>, as required by the general contract of303* {@link java.lang.Object#hashCode() Object.hashCode()}.304*305* @return The hash code value for this attribute set.306*/307public int hashCode();308309}310311312