Path: blob/master/src/java.desktop/share/classes/javax/print/attribute/AttributeSet.java
41159 views
/*1* Copyright (c) 2000, 2017, 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 {@code 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> where duplicate33* values are not allowed in the set. Furthermore, each value in an attribute34* set is a member of some <i>category,</i> and at most one value in any35* particular category is allowed in the set. For an attribute set, the values36* are {@link Attribute Attribute} objects, and the categories are37* {@link Class Class} objects. An attribute's category is the class (or38* interface) at the root of the class hierarchy for that kind of attribute.39* Note that an attribute object's category may be a superclass of the attribute40* object's class rather than the attribute object's class itself. An attribute41* object's category is determined by calling the42* {@link Attribute#getCategory() getCategory()} method defined in interface43* {@link Attribute Attribute}.44* <p>45* The interfaces of an {@code AttributeSet} resemble those of the Java46* Collections API's {@code java.util.Map} interface, but is more restrictive in47* the types it will accept, and combines keys and values into an48* {@code Attribute}.49* <p>50* Attribute sets are used in several places in the Print Service API. In each51* context, only certain kinds of attributes are allowed to appear in the52* attribute set, as determined by the tagging interfaces which the attribute53* class implements -- {@link DocAttribute DocAttribute},54* {@link PrintRequestAttribute PrintRequestAttribute},55* {@link PrintJobAttribute PrintJobAttribute}, and56* {@link PrintServiceAttribute PrintServiceAttribute}.57* There are four specializations of an attribute set that are restricted to58* contain just one of the four kinds of attribute --59* {@link DocAttributeSet DocAttributeSet},60* {@link PrintRequestAttributeSet PrintRequestAttributeSet},61* {@link PrintJobAttributeSet PrintJobAttributeSet}, and62* {@link PrintServiceAttributeSet PrintServiceAttributeSet}, respectively. Note63* that many attribute classes implement more than one tagging interface and so64* may appear in more than one context.65* <ul>66* <li>A {@link DocAttributeSet DocAttributeSet}, containing67* {@link DocAttribute DocAttribute}s, specifies the characteristics of an68* individual doc and the print job settings to be applied to an individual69* doc.70* <li>A {@link PrintRequestAttributeSet PrintRequestAttributeSet}, containing71* {@link PrintRequestAttribute PrintRequestAttribute}s, specifies the72* settings to be applied to a whole print job and to all the docs in the73* print job.74* <li>A {@link PrintJobAttributeSet PrintJobAttributeSet}, containing75* {@link PrintJobAttribute PrintJobAttribute}s, reports the status of a print76* job.77* <li>A {@link PrintServiceAttributeSet PrintServiceAttributeSet}, containing78* {@link PrintServiceAttribute PrintServiceAttribute}s, reports the status of79* a Print Service instance.80* </ul>81* In some contexts, the client is only allowed to examine an attribute set's82* contents but not change them (the set is read-only). In other places, the83* client is allowed both to examine and to change an attribute set's contents84* (the set is read-write). For a read-only attribute set, calling a mutating85* operation throws an {@code UnmodifiableSetException}.86* <p>87* The Print Service API provides one implementation of interface88* {@code AttributeSet}, class {@link HashAttributeSet HashAttributeSet}. A89* client can use class {@link HashAttributeSet HashAttributeSet} or provide its90* own implementation of interface {@code AttributeSet}. The Print Service API91* also provides implementations of interface {@code AttributeSet}'s92* subinterfaces -- classes93* {@link HashDocAttributeSet HashDocAttributeSet},94* {@link HashPrintRequestAttributeSet HashPrintRequestAttributeSet},95* {@link HashPrintJobAttributeSet HashPrintJobAttributeSet}, and96* {@link HashPrintServiceAttributeSet HashPrintServiceAttributeSet}.97*98* @author Alan Kaminsky99*/100public interface AttributeSet {101102/**103* Returns the attribute value which this attribute set contains in the104* given attribute category. Returns {@code null} if this attribute set does105* not contain any attribute value in the given attribute category.106*107* @param category attribute category whose associated attribute value is108* to be returned. It must be a {@link Class Class} that implements109* interface {@link Attribute Attribute}.110* @return the attribute value in the given attribute category contained in111* this attribute set, or {@code null} if this attribute set does112* not contain any attribute value in the given attribute category113* @throws NullPointerException if the {@code category} is {@code null}114* @throws ClassCastException if the {@code category} is not a115* {@link Class Class} that implements interface116* {@link Attribute Attribute}117*/118public Attribute get(Class<?> category);119120/**121* Adds the specified attribute to this attribute set if it is not already122* present, first removing any existing value in the same attribute category123* as the specified attribute value.124*125* @param attribute attribute value to be added to this attribute set126* @return {@code true} if this attribute set changed as a result of the127* call, i.e., the given attribute value was not already a member of128* this attribute set129* @throws NullPointerException if the {@code attribute} is {@code null}130* @throws UnmodifiableSetException if this attribute set does not support131* the {@code add()} operation132*/133public boolean add(Attribute attribute);134135/**136* Removes any attribute for this category from this attribute set if137* present. If {@code category} is {@code null}, then {@code remove()} does138* nothing and returns {@code false}.139*140* @param category attribute category to be removed from this attribute set141* @return {@code true} if this attribute set changed as a result of the142* call, i.e., the given attribute value had been a member of this143* attribute set144* @throws UnmodifiableSetException if this attribute set does not support145* the {@code remove()} operation146*/147public boolean remove(Class<?> category);148149/**150* Removes the specified attribute from this attribute set if present. If151* {@code attribute} is {@code null}, then {@code remove()} does nothing and152* returns {@code false}.153*154* @param attribute attribute value to be removed from this attribute set155* @return {@code true} if this attribute set changed as a result of the156* call, i.e., the given attribute value had been a member of this157* attribute set158* @throws UnmodifiableSetException if this attribute set does not support159* the {@code remove()} operation160*/161public boolean remove(Attribute attribute);162163/**164* Returns {@code true} if this attribute set contains an attribute for the165* specified category.166*167* @param category whose presence in this attribute set is to be tested168* @return {@code true} if this attribute set contains an attribute value169* for the specified category170*/171public boolean containsKey(Class<?> category);172173/**174* Returns {@code true} if this attribute set contains the given attribute175* value.176*177* @param attribute attribute value whose presence in this attribute set is178* to be tested179* @return {@code true} if this attribute set contains the given attribute180* value181*/182public boolean containsValue(Attribute attribute);183184/**185* Adds all of the elements in the specified set to this attribute. The186* outcome is the same as if the = {@link #add(Attribute) add(Attribute)}187* operation had been applied to this attribute set successively with each188* element from the specified set. The behavior of the189* {@code addAll(AttributeSet)} operation is unspecified if the specified190* set is modified while the operation is in progress.191* <p>192* If the {@code addAll(AttributeSet)} operation throws an exception, the193* effect on this attribute set's state is implementation dependent;194* elements from the specified set before the point of the exception may or195* may not have been added to this attribute set.196*197* @param attributes whose elements are to be added to this attribute set198* @return {@code true} if this attribute set changed as a result of the199* call200* @throws UnmodifiableSetException if this attribute set does not support201* the {@code addAll(AttributeSet)} method202* @throws NullPointerException if some element in the specified set is203* {@code null}204* @see #add(Attribute)205*/206public boolean addAll(AttributeSet attributes);207208/**209* Returns the number of attributes in this attribute set. If this attribute210* set contains more than {@code Integer.MAX_VALUE} elements, returns211* {@code Integer.MAX_VALUE}.212*213* @return the number of attributes in this attribute set214*/215public int size();216217/**218* Returns an array of the attributes contained in this set.219*220* @return the {@code Attributes} contained in this set as an array, zero221* length if the {@code AttributeSet} is empty222*/223public Attribute[] toArray();224225/**226* Removes all attributes from this attribute set.227*228* @throws UnmodifiableSetException if this attribute set does not support229* the {@code clear()} operation230*/231public void clear();232233/**234* Returns {@code true} if this attribute set contains no attributes.235*236* @return {@code true} if this attribute set contains no attributes237*/238public boolean isEmpty();239240/**241* Compares the specified object with this attribute set for equality.242* Returns {@code true} if the given object is also an attribute set and the243* two attribute sets contain the same attribute category-attribute value244* mappings. This ensures that the {@code equals()} method works properly245* across different implementations of the {@code AttributeSet} interface.246*247* @param object to be compared for equality with this attribute set248* @return {@code true} if the specified object is equal to this attribute249* set250*/251public boolean equals(Object object);252253/**254* Returns the hash code value for this attribute set. The hash code of an255* attribute set is defined to be the sum of the hash codes of each entry in256* the {@code AttributeSet}. This ensures that {@code t1.equals(t2)} implies257* that {@code t1.hashCode()==t2.hashCode()} for any two attribute sets258* {@code t1} and {@code t2}, as required by the general contract of259* {@link Object#hashCode() Object.hashCode()}.260*261* @return the hash code value for this attribute set262*/263public int hashCode();264}265266267