1 /* PrinterStateReasons.java --
2 Copyright (C) 2004, 2005 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
39 package javax
.print
.attribute
.standard
;
41 import java
.util
.Collections
;
42 import java
.util
.HashMap
;
43 import java
.util
.HashSet
;
44 import java
.util
.Iterator
;
48 import javax
.print
.attribute
.PrintServiceAttribute
;
51 * The <code>PrinterStateReasons</code> attribute provides the set of
52 * additional informations available about the current state of the printer
55 * The attribute is basically a map with <code>PrinterStateReason</code>
56 * objects as keys associated with their severity level as
57 * <code>Severity</code> instances. The IPP keyword value can be
58 * constructed as follows: <br>
59 * <code>reason.toString() + '-' + severity.toString()</code>
62 * <b>IPP Compatibility:</b> PrinterStateReasons is an IPP 1.1 attribute.
64 * @see javax.print.attribute.standard.PrinterState
65 * @see javax.print.attribute.standard.PrinterStateReason
66 * @see javax.print.attribute.standard.Severity
68 * @author Michael Koch (konqueror@gmx.de)
69 * @author Wolfgang Baer (WBaer@gmx.de)
71 public final class PrinterStateReasons
extends HashMap
72 implements PrintServiceAttribute
74 private static final long serialVersionUID
= -3731791085163619457L;
77 * Constructs an empty <code>PrinterStateReasons</code> attribute.
79 public PrinterStateReasons()
85 * Constructs an empty <code>PrinterStateReasons</code> attribute
86 * with the given initial capacity and load factor.
88 * @param initialCapacity the intial capacity.
89 * @param loadFactor the load factor of the underlying HashMap.
91 * @throws IllegalArgumentException if initialCapacity < 0
92 * @throws IllegalArgumentException if initialCapacity or loadFactor < 0
94 public PrinterStateReasons(int initialCapacity
, float loadFactor
)
96 super(initialCapacity
, loadFactor
);
100 * Constructs an empty <code>PrinterStateReasons</code> attribute
101 * with the given initial capacity and the default load factor.
103 * @param initialCapacity the intial capacity.
105 * @throws IllegalArgumentException if initialCapacity < 0
107 public PrinterStateReasons(int initialCapacity
)
109 super(initialCapacity
);
113 * Constructs a <code>PrinterStateReasons</code> attribute
114 * with the given content of the map.
116 * @param map the map for the initial values with the same
117 * <code>PrinterStateReason</code> to <code>Severity</code> mappings.
119 * @throws NullPointerException if map or any key/value is <code>null</code>.
120 * @throws ClassCastException if values of map are not of type
121 * <code>PrinterStateReason</code> and keys are not of type
122 * <code>Severity</code>.
124 public PrinterStateReasons(Map map
)
126 super(map
.size(), 0.75f
);
127 Iterator it
= map
.entrySet().iterator();
130 Map
.Entry entry
= (Map
.Entry
) it
.next();
131 put(entry
.getKey(), entry
.getValue());
136 * Constructs an unmodifiable view of the contained printer state reasons
137 * associated with the given severity level.
139 * @param severity the severity level for the constructed set.
140 * @return The set of printer state reasons.
142 public Set
printerStateReasonSet(Severity severity
)
144 if (severity
== null)
145 throw new NullPointerException("severity is null");
147 HashSet set
= new HashSet();
148 Iterator it
= entrySet().iterator();
151 Map
.Entry entry
= (Map
.Entry
) it
.next();
152 if (entry
.getValue().equals(severity
))
153 set
.add(entry
.getKey());
156 return Collections
.unmodifiableSet(set
);
160 * Puts the given reason object associated with the given severity object
163 * @param reason the reason of type <code>PrinterStateReason</code>.
164 * @param severity the severity of the reason of type <code>Severity</code>.
166 * @return The previously associated severity of the reason or
167 * <code>null</code> if the reason object was not in the map before.
169 * @throws NullPointerException if any of the values is <code>null</code>.
170 * @throws ClassCastException if reason is not a
171 * <code>PrinterStateReason</code> and severity is not a
172 * <code>Severity</code> instance.
174 public Object
put(Object reason
, Object severity
)
177 throw new NullPointerException("reason is null");
178 if (severity
== null)
179 throw new NullPointerException("severity is null");
181 return put((PrinterStateReason
) reason
, (Severity
) severity
);
185 * Returns category of this class.
187 * @return The class <code>PrintStateReasons</code> itself.
189 public Class
getCategory()
191 return PrinterStateReasons
.class;
195 * Returns the name of this attribute.
197 * @return The name "printer-state-reasons".
199 public String
getName()
201 return "printer-state-reasons";