Path: blob/master/src/java.desktop/share/classes/javax/print/attribute/standard/JobStateReasons.java
41171 views
/*1* Copyright (c) 2000, 2021, 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.standard;2627import java.io.Serial;28import java.util.Collection;29import java.util.HashSet;3031import javax.print.attribute.Attribute;32import javax.print.attribute.PrintJobAttribute;3334/**35* Class {@code JobStateReasons} is a printing attribute class, a set of36* enumeration values, that provides additional information about the job's37* current state, i.e., information that augments the value of the job's38* {@link JobState JobState} attribute.39* <p>40* Instances of {@link JobStateReason JobStateReason} do not appear in a Print41* Job's attribute set directly. Rather, a {@code JobStateReasons} attribute42* appears in the Print Job's attribute set. The {@code JobStateReasons}43* attribute contains zero, one, or more than one44* {@link JobStateReason JobStateReason} objects which pertain to the Print45* Job's status. The printer adds a {@link JobStateReason JobStateReason} object46* to the Print Job's JobStateReasons attribute when the corresponding condition47* becomes true of the Print Job, and the printer removes the48* {@link JobStateReason JobStateReason} object again when the corresponding49* condition becomes false, regardless of whether the Print Job's overall50* {@link JobState JobState} also changed.51* <p>52* Class {@code JobStateReasons} inherits its implementation from class53* {@link HashSet java.util.HashSet}. Unlike most printing attributes54* which are immutable once constructed, class {@code JobStateReasons} is55* designed to be mutable; you can add {@link JobStateReason JobStateReason}56* objects to an existing {@code JobStateReasons} object and remove them again.57* However, like class {@link HashSet java.util.HashSet}, class58* {@code JobStateReasons} is not multiple thread safe. If a59* {@code JobStateReasons} object will be used by multiple threads, be sure to60* synchronize its operations (e.g., using a synchronized set view obtained61* from class {@link java.util.Collections java.util.Collections}).62* <p>63* <b>IPP Compatibility:</b> The string value returned by each individual64* {@link JobStateReason JobStateReason} object's {@code toString()} method65* gives the IPP keyword value. The category name returned by {@code getName()}66* gives the IPP attribute name.67*68* @author Alan Kaminsky69*/70public final class JobStateReasons71extends HashSet<JobStateReason> implements PrintJobAttribute {7273/**74* Use serialVersionUID from JDK 1.4 for interoperability.75*/76@Serial77private static final long serialVersionUID = 8849088261264331812L;7879/**80* Construct a new, empty job state reasons attribute; the underlying hash81* set has the default initial capacity and load factor.82*/83public JobStateReasons() {84super();85}8687/**88* Construct a new, empty job state reasons attribute; the underlying hash89* set has the given initial capacity and the default load factor.90*91* @param initialCapacity initial capacity92* @throws IllegalArgumentException if the initial capacity is negative93*/94public JobStateReasons(int initialCapacity) {95super (initialCapacity);96}9798/**99* Construct a new, empty job state reasons attribute; the underlying hash100* set has the given initial capacity and load factor.101*102* @param initialCapacity initial capacity103* @param loadFactor load factor104* @throws IllegalArgumentException if the initial capacity is negative105*/106public JobStateReasons(int initialCapacity, float loadFactor) {107super (initialCapacity, loadFactor);108}109110/**111* Construct a new job state reasons attribute that contains the same112* {@link JobStateReason JobStateReason} objects as the given collection.113* The underlying hash set's initial capacity and load factor are as114* specified in the superclass constructor115* {@link HashSet#HashSet(Collection) HashSet(Collection)}.116*117* @param collection collection to copy118* @throws NullPointerException if {@code collection} is {@code null} or if119* any element in {@code collection} is {@code null}120* @throws ClassCastException if any element in {@code collection} is not an121* instance of class {@link JobStateReason JobStateReason}122*/123public JobStateReasons(Collection<JobStateReason> collection) {124super (collection);125}126127/**128* Adds the specified element to this job state reasons attribute if it is129* not already present. The element to be added must be an instance of class130* {@link JobStateReason JobStateReason}. If this job state reasons131* attribute already contains the specified element, the call leaves this132* job state reasons attribute unchanged and returns {@code false}.133*134* @param o element to be added to this job state reasons attribute135* @return {@code true} if this job state reasons attribute did not already136* contain the specified element137* @throws NullPointerException if the specified element is {@code null}138* @throws ClassCastException if the specified element is not an instance of139* class {@link JobStateReason JobStateReason}140* @since 1.5141*/142public boolean add(JobStateReason o) {143if (o == null) {144throw new NullPointerException();145}146return super.add(o);147}148149/**150* Get the printing attribute class which is to be used as the "category"151* for this printing attribute value.152* <p>153* For class {@code JobStateReasons}, the category is class154* JobStateReasons itself.155*156* @return printing attribute class (category), an instance of class157* {@link Class java.lang.Class}158*/159public final Class<? extends Attribute> getCategory() {160return JobStateReasons.class;161}162163/**164* Get the name of the category of which this attribute value is an165* instance.166* <p>167* For class JobStateReasons, the category name is168* {@code "job-state-reasons"}.169*170* @return attribute category name171*/172public final String getName() {173return "job-state-reasons";174}175}176177178