GNU Classpath (0.20) | |
Frames | No Frames |
1: /* PrinterStateReasons.java -- 2: Copyright (C) 2004, 2005 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 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) 9: any later version. 10: 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. 15: 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 19: 02110-1301 USA. 20: 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 24: combination. 25: 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. */ 37: 38: 39: package javax.print.attribute.standard; 40: 41: import java.util.Collections; 42: import java.util.HashMap; 43: import java.util.HashSet; 44: import java.util.Iterator; 45: import java.util.Map; 46: import java.util.Set; 47: 48: import javax.print.attribute.PrintServiceAttribute; 49: 50: /** 51: * The <code>PrinterStateReasons</code> attribute provides the set of 52: * additional informations available about the current state of the printer 53: * device. 54: * <p> 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> 60: * </p> 61: * <p> 62: * <b>IPP Compatibility:</b> PrinterStateReasons is an IPP 1.1 attribute. 63: * </p> 64: * @see javax.print.attribute.standard.PrinterState 65: * @see javax.print.attribute.standard.PrinterStateReason 66: * @see javax.print.attribute.standard.Severity 67: * 68: * @author Michael Koch (konqueror@gmx.de) 69: * @author Wolfgang Baer (WBaer@gmx.de) 70: */ 71: public final class PrinterStateReasons extends HashMap 72: implements PrintServiceAttribute 73: { 74: private static final long serialVersionUID = -3731791085163619457L; 75: 76: /** 77: * Constructs an empty <code>PrinterStateReasons</code> attribute. 78: */ 79: public PrinterStateReasons() 80: { 81: super(); 82: } 83: 84: /** 85: * Constructs an empty <code>PrinterStateReasons</code> attribute 86: * with the given initial capacity and load factor. 87: * 88: * @param initialCapacity the intial capacity. 89: * @param loadFactor the load factor of the underlying HashMap. 90: * 91: * @throws IllegalArgumentException if initialCapacity < 0 92: * @throws IllegalArgumentException if initialCapacity or loadFactor < 0 93: */ 94: public PrinterStateReasons(int initialCapacity, float loadFactor) 95: { 96: super(initialCapacity, loadFactor); 97: } 98: 99: /** 100: * Constructs an empty <code>PrinterStateReasons</code> attribute 101: * with the given initial capacity and the default load factor. 102: * 103: * @param initialCapacity the intial capacity. 104: * 105: * @throws IllegalArgumentException if initialCapacity < 0 106: */ 107: public PrinterStateReasons(int initialCapacity) 108: { 109: super(initialCapacity); 110: } 111: 112: /** 113: * Constructs a <code>PrinterStateReasons</code> attribute 114: * with the given content of the map. 115: * 116: * @param map the map for the initial values with the same 117: * <code>PrinterStateReason</code> to <code>Severity</code> mappings. 118: * 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>. 123: */ 124: public PrinterStateReasons(Map map) 125: { 126: super(map.size(), 0.75f); 127: Iterator it = map.entrySet().iterator(); 128: while (it.hasNext()) 129: { 130: Map.Entry entry = (Map.Entry) it.next(); 131: put(entry.getKey(), entry.getValue()); 132: } 133: } 134: 135: /** 136: * Constructs an unmodifiable view of the contained printer state reasons 137: * associated with the given severity level. 138: * 139: * @param severity the severity level for the constructed set. 140: * @return The set of printer state reasons. 141: */ 142: public Set printerStateReasonSet(Severity severity) 143: { 144: if (severity == null) 145: throw new NullPointerException("severity is null"); 146: 147: HashSet set = new HashSet(); 148: Iterator it = entrySet().iterator(); 149: while (it.hasNext()) 150: { 151: Map.Entry entry = (Map.Entry) it.next(); 152: if (entry.getValue().equals(severity)) 153: set.add(entry.getKey()); 154: } 155: 156: return Collections.unmodifiableSet(set); 157: } 158: 159: /** 160: * Puts the given reason object associated with the given severity object 161: * into the set. 162: * 163: * @param reason the reason of type <code>PrinterStateReason</code>. 164: * @param severity the severity of the reason of type <code>Severity</code>. 165: * 166: * @return The previously associated severity of the reason or 167: * <code>null</code> if the reason object was not in the map before. 168: * 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. 173: */ 174: public Object put(Object reason, Object severity) 175: { 176: if (reason == null) 177: throw new NullPointerException("reason is null"); 178: if (severity == null) 179: throw new NullPointerException("severity is null"); 180: 181: return put((PrinterStateReason) reason, (Severity) severity); 182: } 183: 184: /** 185: * Returns category of this class. 186: * 187: * @return The class <code>PrintStateReasons</code> itself. 188: */ 189: public Class getCategory() 190: { 191: return PrinterStateReasons.class; 192: } 193: 194: /** 195: * Returns the name of this attribute. 196: * 197: * @return The name "printer-state-reasons". 198: */ 199: public String getName() 200: { 201: return "printer-state-reasons"; 202: } 203: }
GNU Classpath (0.20) |