jdk/src/share/classes/javax/print/attribute/standard/PrinterStateReasons.java
author chegar
Fri, 10 Feb 2012 11:03:20 +0000
changeset 11813 643f5bef6ab4
parent 5506 202f599c92aa
child 14342 8435a30053c1
permissions -rw-r--r--
7144475: fix some warnings in java.awt, javax.print.attribute.standard, and sun.beans.infos Reviewed-by: chegar, prr, alanb, anthony Contributed-by: Prasannaa <prasannaa_ss@yahoo.com>, Martijn Verburg <martijnverburg@gmail.com>, Goerge Albrecht <goerge.albrecht@gmx.net>, Graham Allan <grundlefleck@googlemail.com>, Iordanis Giannakakis <i.giannakakis@ymail.com>, Jose Llarena <jose.llarena@gmail.com>, Abrahamn Marin Perez <abraham.marin.perez@gmail.com>
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4245
diff changeset
     2
 * Copyright (c) 2000, 2006, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4245
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4245
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4245
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4245
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4245
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
package javax.print.attribute.standard;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
import java.util.AbstractSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.NoSuchElementException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import javax.print.attribute.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.print.attribute.PrintServiceAttribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * Class PrinterStateReasons is a printing attribute class, a set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * enumeration values, that provides additional information about the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * printer's current state, i.e., information that augments the value of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * printer's {@link PrinterState PrinterState} attribute.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * Instances of {@link PrinterStateReason PrinterStateReason} do not appear in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 *  a Print Service's attribute set directly. Rather, a PrinterStateReasons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * attribute appears in the Print Service's attribute set. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * PrinterStateReasons attribute contains zero, one, or more than one {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * PrinterStateReason PrinterStateReason} objects which pertain to the Print
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * Service's status, and each {@link PrinterStateReason PrinterStateReason}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * object is associated with a {@link Severity Severity} level of REPORT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *  (least severe), WARNING, or ERROR (most severe). The printer adds a {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * PrinterStateReason PrinterStateReason} object to the Print Service's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * PrinterStateReasons attribute when the corresponding condition becomes true
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * of the printer, and the printer removes the {@link PrinterStateReason
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * PrinterStateReason} object again when the corresponding condition becomes
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * false, regardless of whether the Print Service's overall
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * {@link PrinterState PrinterState} also changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Class PrinterStateReasons inherits its implementation from class {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * java.util.HashMap java.util.HashMap}. Each entry in the map consists of a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * {@link PrinterStateReason PrinterStateReason} object (key) mapping to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * {@link Severity Severity} object (value):
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * Unlike most printing attributes which are immutable once constructed, class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * PrinterStateReasons is designed to be mutable; you can add {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * PrinterStateReason PrinterStateReason} objects to an existing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * PrinterStateReasons object and remove them again. However, like class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *  {@link java.util.HashMap java.util.HashMap}, class PrinterStateReasons is
4245
8adbd99d7b8f 6890945: Typo in sentence about thread safety
jgodinez
parents: 2
diff changeset
    68
 * not multiple thread safe. If a PrinterStateReasons object will be used by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * multiple threads, be sure to synchronize its operations (e.g., using a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * synchronized map view obtained from class {@link java.util.Collections
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * java.util.Collections}).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * <B>IPP Compatibility:</B> The string values returned by each individual
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * {@link PrinterStateReason PrinterStateReason} object's and the associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 * {@link Severity Severity} object's <CODE>toString()</CODE> methods,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * concatenated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * together with a hyphen (<CODE>"-"</CODE>) in between, gives the IPP keyword
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * value. The category name returned by <CODE>getName()</CODE> gives the IPP
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * attribute name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @author  Alan Kaminsky
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
public final class PrinterStateReasons
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    extends HashMap<PrinterStateReason,Severity>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    implements PrintServiceAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
    private static final long serialVersionUID = -3731791085163619457L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Construct a new, empty printer state reasons attribute; the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * hash map has the default initial capacity and load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
    public PrinterStateReasons() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
        super();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * super a new, empty printer state reasons attribute; the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     * hash map has the given initial capacity and the default load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * @param  initialCapacity  Initial capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @throws IllegalArgumentException if the initial capacity is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     *     than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    public PrinterStateReasons(int initialCapacity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        super (initialCapacity);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     * Construct a new, empty printer state reasons attribute; the underlying
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
     * hash map has the given initial capacity and load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * @param  initialCapacity  Initial capacity.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @param  loadFactor       Load factor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @throws IllegalArgumentException if the initial capacity is less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     *     than zero.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    public PrinterStateReasons(int initialCapacity, float loadFactor) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        super (initialCapacity, loadFactor);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     * Construct a new printer state reasons attribute that contains the same
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * {@link PrinterStateReason PrinterStateReason}-to-{@link Severity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * Severity} mappings as the given map. The underlying hash map's initial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * capacity and load factor are as specified in the superclass constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * {@link java.util.HashMap#HashMap(java.util.Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <CODE>HashMap(Map)</CODE>}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param  map  Map to copy.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * @exception  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     *     (unchecked exception) Thrown if <CODE>map</CODE> is null or if any
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *     key or value in <CODE>map</CODE> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * @throws  ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *     (unchecked exception) Thrown if any key in <CODE>map</CODE> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     *   an instance of class {@link PrinterStateReason PrinterStateReason} or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     *     if any value in <CODE>map</CODE> is not an instance of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *     {@link Severity Severity}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    public PrinterStateReasons(Map<PrinterStateReason,Severity> map) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        this();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        for (Map.Entry<PrinterStateReason,Severity> e : map.entrySet())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            put(e.getKey(), e.getValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * Adds the given printer state reason to this printer state reasons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * attribute, associating it with the given severity level. If this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * printer state reasons attribute previously contained a mapping for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * given printer state reason, the old value is replaced.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @param  reason    Printer state reason. This must be an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *                    class {@link PrinterStateReason PrinterStateReason}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @param  severity  Severity of the printer state reason. This must be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     *                      an instance of class {@link Severity Severity}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * @return  Previous severity associated with the given printer state
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     *          reason, or <tt>null</tt> if the given printer state reason was
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *          not present.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @throws  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     *     (unchecked exception) Thrown if <CODE>reason</CODE> is null or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     *     <CODE>severity</CODE> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * @throws  ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     *     (unchecked exception) Thrown if <CODE>reason</CODE> is not an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *   instance of class {@link PrinterStateReason PrinterStateReason} or if
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     *     <CODE>severity</CODE> is not an instance of class {@link Severity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *     Severity}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public Severity put(PrinterStateReason reason, Severity severity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        if (reason == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            throw new NullPointerException("reason is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        if (severity == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throw new NullPointerException("severity is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        }
11813
643f5bef6ab4 7144475: fix some warnings in java.awt, javax.print.attribute.standard, and sun.beans.infos
chegar
parents: 5506
diff changeset
   183
        return super.put(reason, severity);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * Get the printing attribute class which is to be used as the "category"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * for this printing attribute value.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * For class PrinterStateReasons, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * category is class PrinterStateReasons itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @return  Printing attribute class (category), an instance of class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *          {@link java.lang.Class java.lang.Class}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
    public final Class<? extends Attribute> getCategory() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        return PrinterStateReasons.class;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * Get the name of the category of which this attribute value is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * instance.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * For class PrinterStateReasons, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * category name is <CODE>"printer-state-reasons"</CODE>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * @return  Attribute category name.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    public final String getName() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        return "printer-state-reasons";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * Obtain an unmodifiable set view of the individual printer state reason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * attributes at the given severity level in this PrinterStateReasons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * attribute. Each element in the set view is a {@link PrinterStateReason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * PrinterStateReason} object. The only elements in the set view are the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * {@link PrinterStateReason PrinterStateReason} objects that map to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * given severity value. The set view is backed by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * PrinterStateReasons attribute, so changes to this PrinterStateReasons
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * attribute are reflected  in the set view.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * The set view does not support element insertion or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * removal. The set view's iterator does not support element removal.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * @param  severity  Severity level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * @return  Set view of the individual {@link PrinterStateReason
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     *          PrinterStateReason} attributes at the given {@link Severity
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *          Severity} level.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * @exception  NullPointerException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *     (unchecked exception) Thrown if <CODE>severity</CODE> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    public Set<PrinterStateReason> printerStateReasonSet(Severity severity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        if (severity == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            throw new NullPointerException("severity is null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
        return new PrinterStateReasonSet (severity, entrySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    private class PrinterStateReasonSet
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        extends AbstractSet<PrinterStateReason>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
        private Severity mySeverity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        private Set myEntrySet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        public PrinterStateReasonSet(Severity severity, Set entrySet) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            mySeverity = severity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            myEntrySet = entrySet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        public int size() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            int result = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            Iterator iter = iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            while (iter.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                iter.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                ++ result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        public Iterator iterator() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            return new PrinterStateReasonSetIterator(mySeverity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                                                     myEntrySet.iterator());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    private class PrinterStateReasonSetIterator implements Iterator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        private Severity mySeverity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        private Iterator myIterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        private Map.Entry myEntry;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
        public PrinterStateReasonSetIterator(Severity severity,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                                             Iterator iterator) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            mySeverity = severity;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            myIterator = iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            goToNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        private void goToNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            myEntry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            while (myEntry == null && myIterator.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                myEntry = (Map.Entry) myIterator.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
                if ((Severity) myEntry.getValue() != mySeverity) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                    myEntry = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        public boolean hasNext() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            return myEntry != null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        public Object next() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (myEntry == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                throw new NoSuchElementException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            Object result = myEntry.getKey();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            goToNext();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        public void remove() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            throw new UnsupportedOperationException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
}