001 /*
002 * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved.
003 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004 *
005 * This code is free software; you can redistribute it and/or modify it
006 * under the terms of the GNU General Public License version 2 only, as
007 * published by the Free Software Foundation. Sun designates this
008 * particular file as subject to the "Classpath" exception as provided
009 * by Sun in the LICENSE file that accompanied this code.
010 *
011 * This code is distributed in the hope that it will be useful, but WITHOUT
012 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014 * version 2 for more details (a copy is included in the LICENSE file that
015 * accompanied this code).
016 *
017 * You should have received a copy of the GNU General Public License version
018 * 2 along with this work; if not, write to the Free Software Foundation,
019 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020 *
021 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022 * CA 95054 USA or visit www.sun.com if you need additional information or
023 * have any questions.
024 */
025 package javax.print.attribute.standard;
026
027 import java.util.Collection;
028 import java.util.HashSet;
029
030 import javax.print.attribute.Attribute;
031 import javax.print.attribute.PrintJobAttribute;
032
033 /**
034 * Class JobStateReasons is a printing attribute class, a set of enumeration
035 * values, that provides additional information about the job's current state,
036 * i.e., information that augments the value of the job's {@link JobState
037 * JobState} attribute.
038 * <P>
039 * Instances of {@link JobStateReason JobStateReason} do not appear in a Print
040 * Job's attribute set directly. Rather, a JobStateReasons attribute appears in
041 * the Print Job's attribute set. The JobStateReasons attribute contains zero,
042 * one, or more than one {@link JobStateReason JobStateReason} objects which
043 * pertain to the Print Job's status. The printer adds a {@link JobStateReason
044 * JobStateReason} object to the Print Job's JobStateReasons attribute when the
045 * corresponding condition becomes true of the Print Job, and the printer
046 * removes the {@link JobStateReason JobStateReason} object again when the
047 * corresponding condition becomes false, regardless of whether the Print Job's
048 * overall {@link JobState JobState} also changed.
049 * <P>
050 * Class JobStateReasons inherits its implementation from class {@link
051 * java.util.HashSet java.util.HashSet}. Unlike most printing attributes which
052 * are immutable once constructed, class JobStateReasons is designed to be
053 * mutable; you can add {@link JobStateReason JobStateReason} objects to an
054 * existing JobStateReasons object and remove them again. However, like class
055 * {@link java.util.HashSet java.util.HashSet}, class JobStateReasons is not
056 * multiple thread safe. If a JobStateReasons object will be used by multiple
057 * threads, be sure to synchronize its operations (e.g., using a synchronized
058 * set view obtained from class {@link java.util.Collections
059 * java.util.Collections}).
060 * <P>
061 * <B>IPP Compatibility:</B> The string value returned by each individual {@link
062 * JobStateReason JobStateReason} object's <CODE>toString()</CODE> method gives
063 * the IPP keyword value. The category name returned by <CODE>getName()</CODE>
064 * gives the IPP attribute name.
065 * <P>
066 *
067 * @author Alan Kaminsky
068 */
069 public final class JobStateReasons extends HashSet<JobStateReason>
070 implements PrintJobAttribute {
071
072 private static final long serialVersionUID = 8849088261264331812L;
073
074 /**
075 * Construct a new, empty job state reasons attribute; the underlying hash
076 * set has the default initial capacity and load factor.
077 */
078 public JobStateReasons() {
079 super ();
080 }
081
082 /**
083 * Construct a new, empty job state reasons attribute; the underlying hash
084 * set has the given initial capacity and the default load factor.
085 *
086 * @param initialCapacity Initial capacity.
087 * @throws IllegalArgumentException if the initial capacity is less
088 * than zero.
089 */
090 public JobStateReasons(int initialCapacity) {
091 super (initialCapacity);
092 }
093
094 /**
095 * Construct a new, empty job state reasons attribute; the underlying hash
096 * set has the given initial capacity and load factor.
097 *
098 * @param initialCapacity Initial capacity.
099 * @param loadFactor Load factor.
100 * @throws IllegalArgumentException if the initial capacity is less
101 * than zero.
102 */
103 public JobStateReasons(int initialCapacity, float loadFactor) {
104 super (initialCapacity, loadFactor);
105 }
106
107 /**
108 * Construct a new job state reasons attribute that contains the same
109 * {@link JobStateReason JobStateReason} objects as the given collection.
110 * The underlying hash set's initial capacity and load factor are as
111 * specified in the superclass constructor {@link
112 * java.util.HashSet#HashSet(java.util.Collection)
113 * <CODE>HashSet(Collection)</CODE>}.
114 *
115 * @param collection Collection to copy.
116 *
117 * @exception NullPointerException
118 * (unchecked exception) Thrown if <CODE>collection</CODE> is null or
119 * if any element in <CODE>collection</CODE> is null.
120 * @throws ClassCastException
121 * (unchecked exception) Thrown if any element in
122 * <CODE>collection</CODE> is not an instance of class {@link
123 * JobStateReason JobStateReason}.
124 */
125 public JobStateReasons(Collection<JobStateReason> collection) {
126 super (collection);
127 }
128
129 /**
130 * Adds the specified element to this job state reasons attribute if it is
131 * not already present. The element to be added must be an instance of class
132 * {@link JobStateReason JobStateReason}. If this job state reasons
133 * attribute already contains the specified element, the call leaves this
134 * job state reasons attribute unchanged and returns <tt>false</tt>.
135 *
136 * @param o Element to be added to this job state reasons attribute.
137 *
138 * @return <tt>true</tt> if this job state reasons attribute did not
139 * already contain the specified element.
140 *
141 * @throws NullPointerException
142 * (unchecked exception) Thrown if the specified element is null.
143 * @throws ClassCastException
144 * (unchecked exception) Thrown if the specified element is not an
145 * instance of class {@link JobStateReason JobStateReason}.
146 * @since 1.5
147 */
148 public boolean add(JobStateReason o) {
149 if (o == null) {
150 throw new NullPointerException();
151 }
152 return super .add((JobStateReason) o);
153 }
154
155 /**
156 * Get the printing attribute class which is to be used as the "category"
157 * for this printing attribute value.
158 * <P>
159 * For class JobStateReasons, the category is class JobStateReasons itself.
160 *
161 * @return Printing attribute class (category), an instance of class
162 * {@link java.lang.Class java.lang.Class}.
163 */
164 public final Class<? extends Attribute> getCategory() {
165 return JobStateReasons.class;
166 }
167
168 /**
169 * Get the name of the category of which this attribute value is an
170 * instance.
171 * <P>
172 * For class JobStateReasons, the category
173 * name is <CODE>"job-state-reasons"</CODE>.
174 *
175 * @return Attribute category name.
176 */
177 public final String getName() {
178 return "job-state-reasons";
179 }
180
181 }
|