1. /*
  2. * @(#)JobStateReasons.java 1.8 04/05/05
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.print.attribute.standard;
  8. import java.util.Collection;
  9. import java.util.HashSet;
  10. import javax.print.attribute.Attribute;
  11. import javax.print.attribute.PrintJobAttribute;
  12. /**
  13. * Class JobStateReasons is a printing attribute class, a set of enumeration
  14. * values, that provides additional information about the job's current state,
  15. * i.e., information that augments the value of the job's {@link JobState
  16. * JobState} attribute.
  17. * <P>
  18. * Instances of {@link JobStateReason JobStateReason} do not appear in a Print
  19. * Job's attribute set directly. Rather, a JobStateReasons attribute appears in
  20. * the Print Job's attribute set. The JobStateReasons attribute contains zero,
  21. * one, or more than one {@link JobStateReason JobStateReason} objects which
  22. * pertain to the Print Job's status. The printer adds a {@link JobStateReason
  23. * JobStateReason} object to the Print Job's JobStateReasons attribute when the
  24. * corresponding condition becomes true of the Print Job, and the printer
  25. * removes the {@link JobStateReason JobStateReason} object again when the
  26. * corresponding condition becomes false, regardless of whether the Print Job's
  27. * overall {@link JobState JobState} also changed.
  28. * <P>
  29. * Class JobStateReasons inherits its implementation from class {@link
  30. * java.util.HashSet java.util.HashSet}. Unlike most printing attributes which
  31. * are immutable once constructed, class JobStateReasons is designed to be
  32. * mutable; you can add {@link JobStateReason JobStateReason} objects to an
  33. * existing JobStateReasons object and remove them again. However, like class
  34. * {@link java.util.HashSet java.util.HashSet}, class JobStateReasons is not
  35. * multiple thread safe. If a JobStateReasons object will be used by multiple
  36. * threads, be sure to synchronize its operations (e.g., using a synchronized
  37. * set view obtained from class {@link java.util.Collections
  38. * java.util.Collections}).
  39. * <P>
  40. * <B>IPP Compatibility:</B> The string value returned by each individual {@link
  41. * JobStateReason JobStateReason} object's <CODE>toString()</CODE> method gives
  42. * the IPP keyword value. The category name returned by <CODE>getName()</CODE>
  43. * gives the IPP attribute name.
  44. * <P>
  45. *
  46. * @author Alan Kaminsky
  47. */
  48. public final class JobStateReasons
  49. extends HashSet<JobStateReason> implements PrintJobAttribute {
  50. private static final long serialVersionUID = 8849088261264331812L;
  51. /**
  52. * Construct a new, empty job state reasons attribute; the underlying hash
  53. * set has the default initial capacity and load factor.
  54. */
  55. public JobStateReasons() {
  56. super();
  57. }
  58. /**
  59. * Construct a new, empty job state reasons attribute; the underlying hash
  60. * set has the given initial capacity and the default load factor.
  61. *
  62. * @param initialCapacity Initial capacity.
  63. * @throws IllegalArgumentException if the initial capacity is less
  64. * than zero.
  65. */
  66. public JobStateReasons(int initialCapacity) {
  67. super (initialCapacity);
  68. }
  69. /**
  70. * Construct a new, empty job state reasons attribute; the underlying hash
  71. * set has the given initial capacity and load factor.
  72. *
  73. * @param initialCapacity Initial capacity.
  74. * @param loadFactor Load factor.
  75. * @throws IllegalArgumentException if the initial capacity is less
  76. * than zero.
  77. */
  78. public JobStateReasons(int initialCapacity, float loadFactor) {
  79. super (initialCapacity, loadFactor);
  80. }
  81. /**
  82. * Construct a new job state reasons attribute that contains the same
  83. * {@link JobStateReason JobStateReason} objects as the given collection.
  84. * The underlying hash set's initial capacity and load factor are as
  85. * specified in the superclass constructor {@link
  86. * java.util.HashSet#HashSet(java.util.Collection)
  87. * <CODE>HashSet(Collection)</CODE>}.
  88. *
  89. * @param collection Collection to copy.
  90. *
  91. * @exception NullPointerException
  92. * (unchecked exception) Thrown if <CODE>collection</CODE> is null or
  93. * if any element in <CODE>collection</CODE> is null.
  94. * @throws ClassCastException
  95. * (unchecked exception) Thrown if any element in
  96. * <CODE>collection</CODE> is not an instance of class {@link
  97. * JobStateReason JobStateReason}.
  98. */
  99. public JobStateReasons(Collection<JobStateReason> collection) {
  100. super (collection);
  101. }
  102. /**
  103. * Adds the specified element to this job state reasons attribute if it is
  104. * not already present. The element to be added must be an instance of class
  105. * {@link JobStateReason JobStateReason}. If this job state reasons
  106. * attribute already contains the specified element, the call leaves this
  107. * job state reasons attribute unchanged and returns <tt>false</tt>.
  108. *
  109. * @param o Element to be added to this job state reasons attribute.
  110. *
  111. * @return <tt>true</tt> if this job state reasons attribute did not
  112. * already contain the specified element.
  113. *
  114. * @throws NullPointerException
  115. * (unchecked exception) Thrown if the specified element is null.
  116. * @throws ClassCastException
  117. * (unchecked exception) Thrown if the specified element is not an
  118. * instance of class {@link JobStateReason JobStateReason}.
  119. */
  120. public boolean add(JobStateReason o) {
  121. if (o == null) {
  122. throw new NullPointerException();
  123. }
  124. return super.add ((JobStateReason) o);
  125. }
  126. /**
  127. * Get the printing attribute class which is to be used as the "category"
  128. * for this printing attribute value.
  129. * <P>
  130. * For class JobStateReasons, the category is class JobStateReasons itself.
  131. *
  132. * @return Printing attribute class (category), an instance of class
  133. * {@link java.lang.Class java.lang.Class}.
  134. */
  135. public final Class<? extends Attribute> getCategory() {
  136. return JobStateReasons.class;
  137. }
  138. /**
  139. * Get the name of the category of which this attribute value is an
  140. * instance.
  141. * <P>
  142. * For class JobStateReasons, the category
  143. * name is <CODE>"job-state-reasons"</CODE>.
  144. *
  145. * @return Attribute category name.
  146. */
  147. public final String getName() {
  148. return "job-state-reasons";
  149. }
  150. }