1 7 package javax.print.attribute.standard; 8 9 import java.util.AbstractSet ; 10 import java.util.Iterator ; 11 import java.util.Map ; 12 import java.util.NoSuchElementException ; 13 import java.util.HashMap ; 14 import java.util.Set ; 15 16 import javax.print.attribute.Attribute ; 17 import javax.print.attribute.PrintServiceAttribute ; 18 19 66 public final class PrinterStateReasons 67 extends HashMap <PrinterStateReason ,Severity > 68 implements PrintServiceAttribute 69 { 70 71 private static final long serialVersionUID = -3731791085163619457L; 72 73 77 public PrinterStateReasons() { 78 super(); 79 } 80 81 90 public PrinterStateReasons(int initialCapacity) { 91 super (initialCapacity); 92 } 93 94 104 public PrinterStateReasons(int initialCapacity, float loadFactor) { 105 super (initialCapacity, loadFactor); 106 } 107 108 127 public PrinterStateReasons(Map <PrinterStateReason ,Severity > map) { 128 this(); 129 for (Map.Entry <PrinterStateReason ,Severity > e : map.entrySet()) 130 put(e.getKey(), e.getValue()); 131 } 132 133 157 public Severity put(PrinterStateReason reason, Severity severity) { 158 if (reason == null) { 159 throw new NullPointerException ("reason is null"); 160 } 161 if (severity == null) { 162 throw new NullPointerException ("severity is null"); 163 } 164 return super.put((PrinterStateReason ) reason, 165 (Severity ) severity); 166 } 167 168 178 public final Class <? extends Attribute > getCategory() { 179 return PrinterStateReasons .class; 180 } 181 182 191 public final String getName() { 192 return "printer-state-reasons"; 193 } 194 195 216 public Set <PrinterStateReason > printerStateReasonSet(Severity severity) { 217 if (severity == null) { 218 throw new NullPointerException ("severity is null"); 219 } 220 return new PrinterStateReasonSet (severity, entrySet()); 221 } 222 223 private class PrinterStateReasonSet 224 extends AbstractSet <PrinterStateReason > 225 { 226 private Severity mySeverity; 227 private Set myEntrySet; 228 229 public PrinterStateReasonSet(Severity severity, Set entrySet) { 230 mySeverity = severity; 231 myEntrySet = entrySet; 232 } 233 234 public int size() { 235 int result = 0; 236 Iterator iter = iterator(); 237 while (iter.hasNext()) { 238 iter.next(); 239 ++ result; 240 } 241 return result; 242 } 243 244 public Iterator iterator() { 245 return new PrinterStateReasonSetIterator(mySeverity, 246 myEntrySet.iterator()); 247 } 248 } 249 250 private class PrinterStateReasonSetIterator implements Iterator { 251 private Severity mySeverity; 252 private Iterator myIterator; 253 private Map.Entry myEntry; 254 255 public PrinterStateReasonSetIterator(Severity severity, 256 Iterator iterator) { 257 mySeverity = severity; 258 myIterator = iterator; 259 goToNext(); 260 } 261 262 private void goToNext() { 263 myEntry = null; 264 while (myEntry == null && myIterator.hasNext()) { 265 myEntry = (Map.Entry ) myIterator.next(); 266 if ((Severity ) myEntry.getValue() != mySeverity) { 267 myEntry = null; 268 } 269 } 270 } 271 272 public boolean hasNext() { 273 return myEntry != null; 274 } 275 276 public Object next() { 277 if (myEntry == null) { 278 throw new NoSuchElementException (); 279 } 280 Object result = myEntry.getKey(); 281 goToNext(); 282 return result; 283 } 284 285 public void remove() { 286 throw new UnsupportedOperationException (); 287 } 288 } 289 290 } 291 | Popular Tags |