Source for javax.print.attribute.standard.PrinterStateReasons

   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.Attribute;
  49: import javax.print.attribute.PrintServiceAttribute;
  50: 
  51: /**
  52:  * The <code>PrinterStateReasons</code> attribute provides the set of
  53:  * additional informations available about the current state of the printer
  54:  * device.
  55:  * <p>
  56:  * The attribute is basically a map with <code>PrinterStateReason</code>
  57:  * objects as keys associated with their severity level as
  58:  * <code>Severity</code> instances. The IPP keyword value can be
  59:  * constructed as follows: <br>
  60:  * <code>reason.toString() + '-' + severity.toString()</code>
  61:  * </p>
  62:  * <p>
  63:  * <b>IPP Compatibility:</b> PrinterStateReasons is an IPP 1.1 attribute.
  64:  * </p>
  65:  * @see javax.print.attribute.standard.PrinterState
  66:  * @see javax.print.attribute.standard.PrinterStateReason
  67:  * @see javax.print.attribute.standard.Severity
  68:  *
  69:  * @author Michael Koch (konqueror@gmx.de)
  70:  * @author Wolfgang Baer (WBaer@gmx.de)
  71:  */
  72: public final class PrinterStateReasons
  73:   extends HashMap<PrinterStateReason, Severity>
  74:   implements PrintServiceAttribute
  75: {
  76:   private static final long serialVersionUID = -3731791085163619457L;
  77: 
  78:   /**
  79:    * Constructs an empty <code>PrinterStateReasons</code> attribute.
  80:    */
  81:   public PrinterStateReasons()
  82:   {
  83:     super();
  84:   }
  85: 
  86:   /**
  87:    * Constructs an empty <code>PrinterStateReasons</code> attribute
  88:    * with the given initial capacity and load factor.
  89:    *
  90:    * @param initialCapacity the intial capacity.
  91:    * @param loadFactor the load factor of the underlying HashMap.
  92:    *
  93:    * @throws IllegalArgumentException if initialCapacity &lt; 0
  94:    * @throws IllegalArgumentException if initialCapacity or loadFactor &lt; 0
  95:    */
  96:   public PrinterStateReasons(int initialCapacity, float loadFactor)
  97:   {
  98:     super(initialCapacity, loadFactor);
  99:   }
 100: 
 101:   /**
 102:    * Constructs an empty <code>PrinterStateReasons</code> attribute
 103:    * with the given initial capacity and the default load factor.
 104:    *
 105:    * @param initialCapacity the intial capacity.
 106:    *
 107:    * @throws IllegalArgumentException if initialCapacity &lt; 0
 108:    */
 109:   public PrinterStateReasons(int initialCapacity)
 110:   {
 111:     super(initialCapacity);
 112:   }
 113: 
 114:   /**
 115:    * Constructs a <code>PrinterStateReasons</code> attribute
 116:    * with the given content of the map.
 117:    *
 118:    * @param map the map for the initial values with the same
 119:    * <code>PrinterStateReason</code> to <code>Severity</code> mappings.
 120:    *
 121:    * @throws NullPointerException if map or any key/value is <code>null</code>.
 122:    * @throws ClassCastException if values of map are not of type
 123:    * <code>PrinterStateReason</code> and keys are not of type
 124:    * <code>Severity</code>.
 125:    */
 126:   public PrinterStateReasons(Map<PrinterStateReason,Severity> map)
 127:   {
 128:     super(map.size(), 0.75f);
 129:     for (Map.Entry<PrinterStateReason,Severity> entry : map.entrySet())
 130:       {
 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<PrinterStateReason> 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 Severity put(PrinterStateReason reason,Severity 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 super.put(reason, severity);
 182:   }
 183: 
 184:   /**
 185:    * Returns category of this class.
 186:    *
 187:    * @return The class <code>PrintStateReasons</code> itself.
 188:    */
 189:   public Class< ? extends Attribute> 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: }