PrinterStateReasons.java 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /* PrinterStateReasons.java --
  2. Copyright (C) 2004, 2005 Free Software Foundation, Inc.
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  15. 02110-1301 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package javax.print.attribute.standard;
  32. import java.util.Collections;
  33. import java.util.HashMap;
  34. import java.util.HashSet;
  35. import java.util.Iterator;
  36. import java.util.Map;
  37. import java.util.Set;
  38. import javax.print.attribute.Attribute;
  39. import javax.print.attribute.PrintServiceAttribute;
  40. /**
  41. * The <code>PrinterStateReasons</code> attribute provides the set of
  42. * additional informations available about the current state of the printer
  43. * device.
  44. * <p>
  45. * The attribute is basically a map with <code>PrinterStateReason</code>
  46. * objects as keys associated with their severity level as
  47. * <code>Severity</code> instances. The IPP keyword value can be
  48. * constructed as follows: <br>
  49. * <code>reason.toString() + '-' + severity.toString()</code>
  50. * </p>
  51. * <p>
  52. * <b>IPP Compatibility:</b> PrinterStateReasons is an IPP 1.1 attribute.
  53. * </p>
  54. * @see javax.print.attribute.standard.PrinterState
  55. * @see javax.print.attribute.standard.PrinterStateReason
  56. * @see javax.print.attribute.standard.Severity
  57. *
  58. * @author Michael Koch (konqueror@gmx.de)
  59. * @author Wolfgang Baer (WBaer@gmx.de)
  60. */
  61. public final class PrinterStateReasons
  62. extends HashMap<PrinterStateReason, Severity>
  63. implements PrintServiceAttribute
  64. {
  65. private static final long serialVersionUID = -3731791085163619457L;
  66. /**
  67. * Constructs an empty <code>PrinterStateReasons</code> attribute.
  68. */
  69. public PrinterStateReasons()
  70. {
  71. super();
  72. }
  73. /**
  74. * Constructs an empty <code>PrinterStateReasons</code> attribute
  75. * with the given initial capacity and load factor.
  76. *
  77. * @param initialCapacity the intial capacity.
  78. * @param loadFactor the load factor of the underlying HashMap.
  79. *
  80. * @throws IllegalArgumentException if initialCapacity &lt; 0
  81. * @throws IllegalArgumentException if initialCapacity or loadFactor &lt; 0
  82. */
  83. public PrinterStateReasons(int initialCapacity, float loadFactor)
  84. {
  85. super(initialCapacity, loadFactor);
  86. }
  87. /**
  88. * Constructs an empty <code>PrinterStateReasons</code> attribute
  89. * with the given initial capacity and the default load factor.
  90. *
  91. * @param initialCapacity the intial capacity.
  92. *
  93. * @throws IllegalArgumentException if initialCapacity &lt; 0
  94. */
  95. public PrinterStateReasons(int initialCapacity)
  96. {
  97. super(initialCapacity);
  98. }
  99. /**
  100. * Constructs a <code>PrinterStateReasons</code> attribute
  101. * with the given content of the map.
  102. *
  103. * @param map the map for the initial values with the same
  104. * <code>PrinterStateReason</code> to <code>Severity</code> mappings.
  105. *
  106. * @throws NullPointerException if map or any key/value is <code>null</code>.
  107. * @throws ClassCastException if values of map are not of type
  108. * <code>PrinterStateReason</code> and keys are not of type
  109. * <code>Severity</code>.
  110. */
  111. public PrinterStateReasons(Map<PrinterStateReason,Severity> map)
  112. {
  113. super(map.size(), 0.75f);
  114. for (Map.Entry<PrinterStateReason,Severity> entry : map.entrySet())
  115. {
  116. put(entry.getKey(), entry.getValue());
  117. }
  118. }
  119. /**
  120. * Constructs an unmodifiable view of the contained printer state reasons
  121. * associated with the given severity level.
  122. *
  123. * @param severity the severity level for the constructed set.
  124. * @return The set of printer state reasons.
  125. */
  126. public Set<PrinterStateReason> printerStateReasonSet(Severity severity)
  127. {
  128. if (severity == null)
  129. throw new NullPointerException("severity is null");
  130. HashSet set = new HashSet();
  131. Iterator it = entrySet().iterator();
  132. while (it.hasNext())
  133. {
  134. Map.Entry entry = (Map.Entry) it.next();
  135. if (entry.getValue().equals(severity))
  136. set.add(entry.getKey());
  137. }
  138. return Collections.unmodifiableSet(set);
  139. }
  140. /**
  141. * Puts the given reason object associated with the given severity object
  142. * into the set.
  143. *
  144. * @param reason the reason of type <code>PrinterStateReason</code>.
  145. * @param severity the severity of the reason of type <code>Severity</code>.
  146. *
  147. * @return The previously associated severity of the reason or
  148. * <code>null</code> if the reason object was not in the map before.
  149. *
  150. * @throws NullPointerException if any of the values is <code>null</code>.
  151. * @throws ClassCastException if reason is not a
  152. * <code>PrinterStateReason</code> and severity is not a
  153. * <code>Severity</code> instance.
  154. */
  155. public Severity put(PrinterStateReason reason,Severity severity)
  156. {
  157. if (reason == null)
  158. throw new NullPointerException("reason is null");
  159. if (severity == null)
  160. throw new NullPointerException("severity is null");
  161. return super.put(reason, severity);
  162. }
  163. /**
  164. * Returns category of this class.
  165. *
  166. * @return The class <code>PrintStateReasons</code> itself.
  167. */
  168. public Class< ? extends Attribute> getCategory()
  169. {
  170. return PrinterStateReasons.class;
  171. }
  172. /**
  173. * Returns the name of this attribute.
  174. *
  175. * @return The name "printer-state-reasons".
  176. */
  177. public String getName()
  178. {
  179. return "printer-state-reasons";
  180. }
  181. }