1 /*
   2  * Copyright (c) 2000, 2017, 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 
  26 package javax.print.attribute.standard;
  27 
  28 import java.util.Collection;
  29 import java.util.HashSet;
  30 
  31 import javax.print.attribute.Attribute;
  32 import javax.print.attribute.PrintJobAttribute;
  33 
  34 /**
  35  * Class {@code JobStateReasons} is a printing attribute class, a set of
  36  * enumeration values, that provides additional information about the job's
  37  * current state, i.e., information that augments the value of the job's
  38  * {@link JobState JobState} attribute.
  39  * <p>
  40  * Instances of {@link JobStateReason JobStateReason} do not appear in a Print
  41  * Job's attribute set directly. Rather, a {@code JobStateReasons} attribute
  42  * appears in the Print Job's attribute set. The {@code JobStateReasons}
  43  * attribute contains zero, one, or more than one
  44  * {@link JobStateReason JobStateReason} objects which pertain to the Print
  45  * Job's status. The printer adds a {@link JobStateReason JobStateReason} object
  46  * to the Print Job's JobStateReasons attribute when the corresponding condition
  47  * becomes true of the Print Job, and the printer removes the
  48  * {@link JobStateReason JobStateReason} object again when the corresponding
  49  * condition becomes false, regardless of whether the Print Job's overall
  50  * {@link JobState JobState} also changed.
  51  * <p>
  52  * Class {@code JobStateReasons} inherits its implementation from class
  53  * {@link HashSet java.util.HashSet}. Unlike most printing attributes
  54  * which are immutable once constructed, class {@code JobStateReasons} is
  55  * 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}, class
  58  * {@code JobStateReasons} is not multiple thread safe. If a
  59  * {@code JobStateReasons} object will be used by multiple threads, be sure to
  60  * synchronize its operations (e.g., using a synchronized set view obtained
  61  * from class {@link java.util.Collections java.util.Collections}).
  62  * <p>
  63  * <b>IPP Compatibility:</b> The string value returned by each individual
  64  * {@link JobStateReason JobStateReason} object's {@code toString()} method
  65  * gives the IPP keyword value. The category name returned by {@code getName()}
  66  * gives the IPP attribute name.
  67  *
  68  * @author Alan Kaminsky
  69  */
  70 public final class JobStateReasons
  71     extends HashSet<JobStateReason> implements PrintJobAttribute {
  72 
  73     /**
  74      * Use serialVersionUID from JDK 1.4 for interoperability.
  75      */
  76     private static final long serialVersionUID = 8849088261264331812L;
  77 
  78     /**
  79      * Construct a new, empty job state reasons attribute; the underlying hash
  80      * set has the default initial capacity and load factor.
  81      */
  82     public JobStateReasons() {
  83         super();
  84     }
  85 
  86     /**
  87      * Construct a new, empty job state reasons attribute; the underlying hash
  88      * set has the given initial capacity and the default load factor.
  89      *
  90      * @param  initialCapacity initial capacity
  91      * @throws IllegalArgumentException if the initial capacity is negative
  92      */
  93     public JobStateReasons(int initialCapacity) {
  94         super (initialCapacity);
  95     }
  96 
  97     /**
  98      * Construct a new, empty job state reasons attribute; the underlying hash
  99      * set has the given initial capacity and load factor.
 100      *
 101      * @param  initialCapacity initial capacity
 102      * @param  loadFactor load factor
 103      * @throws IllegalArgumentException if the initial capacity is negative
 104      */
 105     public JobStateReasons(int initialCapacity, float loadFactor) {
 106         super (initialCapacity, loadFactor);
 107     }
 108 
 109     /**
 110      * Construct a new job state reasons attribute that contains the same
 111      * {@link JobStateReason JobStateReason} objects as the given collection.
 112      * The underlying hash set's initial capacity and load factor are as
 113      * specified in the superclass constructor
 114      * {@link HashSet#HashSet(Collection) HashSet(Collection)}.
 115      *
 116      * @param  collection collection to copy
 117      * @throws NullPointerException if {@code collection} is {@code null} or if
 118      *         any element in {@code collection} is {@code null}
 119      * @throws ClassCastException if any element in {@code collection} is not an
 120      *         instance of class {@link JobStateReason JobStateReason}
 121      */
 122     public JobStateReasons(Collection<JobStateReason> collection) {
 123         super (collection);
 124     }
 125 
 126     /**
 127      * Adds the specified element to this job state reasons attribute if it is
 128      * not already present. The element to be added must be an instance of class
 129      * {@link JobStateReason JobStateReason}. If this job state reasons
 130      * attribute already contains the specified element, the call leaves this
 131      * job state reasons attribute unchanged and returns {@code false}.
 132      *
 133      * @param  o element to be added to this job state reasons attribute
 134      * @return {@code true} if this job state reasons attribute did not already
 135      *         contain the specified element
 136      * @throws NullPointerException if the specified element is {@code null}
 137      * @throws ClassCastException if the specified element is not an instance of
 138      *         class {@link JobStateReason JobStateReason}
 139      * @since 1.5
 140      */
 141     public boolean add(JobStateReason o) {
 142         if (o == null) {
 143             throw new NullPointerException();
 144         }
 145         return super.add(o);
 146     }
 147 
 148     /**
 149      * Get the printing attribute class which is to be used as the "category"
 150      * for this printing attribute value.
 151      * <p>
 152      * For class {@code JobStateReasons}, the category is class
 153      * JobStateReasons itself.
 154      *
 155      * @return printing attribute class (category), an instance of class
 156      *         {@link Class java.lang.Class}
 157      */
 158     public final Class<? extends Attribute> getCategory() {
 159         return JobStateReasons.class;
 160     }
 161 
 162     /**
 163      * Get the name of the category of which this attribute value is an
 164      * instance.
 165      * <p>
 166      * For class JobStateReasons, the category name is
 167      * {@code "job-state-reasons"}.
 168      *
 169      * @return attribute category name
 170      */
 171     public final String getName() {
 172         return "job-state-reasons";
 173     }
 174 }