1 /* 2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle in the LICENSE file that accompanied this code. 10 * 11 * This code is distributed in the hope that it will be useful, but WITHOUT 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14 * version 2 for more details (a copy is included in the LICENSE file that 15 * accompanied this code). 16 * 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 package javax.print.attribute.standard; 26 27 import java.util.Collection; 28 import java.util.HashSet; 29 30 import javax.print.attribute.Attribute; 31 import javax.print.attribute.PrintJobAttribute; 32 33 /** 34 * Class JobStateReasons is a printing attribute class, a set of enumeration 35 * values, that provides additional information about the job's current state, 36 * i.e., information that augments the value of the job's {@link JobState 37 * JobState} attribute. 38 * <P> 39 * Instances of {@link JobStateReason JobStateReason} do not appear in a Print 40 * Job's attribute set directly. Rather, a JobStateReasons attribute appears in 41 * the Print Job's attribute set. The JobStateReasons attribute contains zero, 42 * one, or more than one {@link JobStateReason JobStateReason} objects which 43 * pertain to the Print Job's status. The printer adds a {@link JobStateReason 44 * JobStateReason} object to the Print Job's JobStateReasons attribute when the 45 * corresponding condition becomes true of the Print Job, and the printer 46 * removes the {@link JobStateReason JobStateReason} object again when the 47 * corresponding condition becomes false, regardless of whether the Print Job's 48 * overall {@link JobState JobState} also changed. 49 * <P> 50 * Class JobStateReasons inherits its implementation from class {@link 51 * java.util.HashSet java.util.HashSet}. Unlike most printing attributes which 52 * are immutable once constructed, class JobStateReasons is designed to be 53 * mutable; you can add {@link JobStateReason JobStateReason} objects to an 54 * existing JobStateReasons object and remove them again. However, like class 55 * {@link java.util.HashSet java.util.HashSet}, class JobStateReasons is not 56 * multiple thread safe. If a JobStateReasons object will be used by multiple 57 * threads, be sure to synchronize its operations (e.g., using a synchronized 58 * set view obtained from class {@link java.util.Collections 59 * java.util.Collections}). 60 * <P> 61 * <B>IPP Compatibility:</B> The string value returned by each individual {@link 62 * JobStateReason JobStateReason} object's <CODE>toString()</CODE> method gives 63 * the IPP keyword value. The category name returned by <CODE>getName()</CODE> 64 * gives the IPP attribute name. 65 * 66 * @author Alan Kaminsky 67 */ 68 public final class JobStateReasons 69 extends HashSet<JobStateReason> implements PrintJobAttribute { 70 71 private static final long serialVersionUID = 8849088261264331812L; 72 73 /** 74 * Construct a new, empty job state reasons attribute; the underlying hash 75 * set has the default initial capacity and load factor. 76 */ 77 public JobStateReasons() { 78 super(); 79 } 80 81 /** 82 * Construct a new, empty job state reasons attribute; the underlying hash 83 * set has the given initial capacity and the default load factor. 84 * 85 * @param initialCapacity Initial capacity. 86 * @throws IllegalArgumentException if the initial capacity is less 87 * than zero. 88 */ 89 public JobStateReasons(int initialCapacity) { 90 super (initialCapacity); 91 } 92 93 /** 94 * Construct a new, empty job state reasons attribute; the underlying hash 95 * set has the given initial capacity and load factor. 96 * 97 * @param initialCapacity Initial capacity. 98 * @param loadFactor Load factor. 99 * @throws IllegalArgumentException if the initial capacity is less 100 * than zero. 101 */ 102 public JobStateReasons(int initialCapacity, float loadFactor) { 103 super (initialCapacity, loadFactor); 104 } 105 106 /** 107 * Construct a new job state reasons attribute that contains the same 108 * {@link JobStateReason JobStateReason} objects as the given collection. 109 * The underlying hash set's initial capacity and load factor are as 110 * specified in the superclass constructor {@link 111 * java.util.HashSet#HashSet(java.util.Collection) 112 * HashSet(Collection)}. 113 * 114 * @param collection Collection to copy. 115 * 116 * @exception NullPointerException 117 * (unchecked exception) Thrown if <CODE>collection</CODE> is null or 118 * if any element in <CODE>collection</CODE> is null. 119 * @throws ClassCastException 120 * (unchecked exception) Thrown if any element in 121 * <CODE>collection</CODE> is not an instance of class {@link 122 * JobStateReason JobStateReason}. 123 */ 124 public JobStateReasons(Collection<JobStateReason> collection) { 125 super (collection); 126 } 127 128 /** 129 * Adds the specified element to this job state reasons attribute if it is 130 * not already present. The element to be added must be an instance of class 131 * {@link JobStateReason JobStateReason}. If this job state reasons 132 * attribute already contains the specified element, the call leaves this 133 * job state reasons attribute unchanged and returns <tt>false</tt>. 134 * 135 * @param o Element to be added to this job state reasons attribute. 136 * 137 * @return <tt>true</tt> if this job state reasons attribute did not 138 * already contain the specified element. 139 * 140 * @throws NullPointerException 141 * (unchecked exception) Thrown if the specified element is null. 142 * @throws ClassCastException 143 * (unchecked exception) Thrown if the specified element is not an 144 * instance of class {@link JobStateReason JobStateReason}. 145 * @since 1.5 146 */ 147 public boolean add(JobStateReason o) { 148 if (o == null) { 149 throw new NullPointerException(); 150 } 151 return super.add(o); 152 } 153 154 /** 155 * Get the printing attribute class which is to be used as the "category" 156 * for this printing attribute value. 157 * <P> 158 * For class JobStateReasons, the category is class JobStateReasons itself. 159 * 160 * @return Printing attribute class (category), an instance of class 161 * {@link java.lang.Class java.lang.Class}. 162 */ 163 public final Class<? extends Attribute> getCategory() { 164 return JobStateReasons.class; 165 } 166 167 /** 168 * Get the name of the category of which this attribute value is an 169 * instance. 170 * <P> 171 * For class JobStateReasons, the category 172 * name is <CODE>"job-state-reasons"</CODE>. 173 * 174 * @return Attribute category name. 175 */ 176 public final String getName() { 177 return "job-state-reasons"; 178 } 179 180 }