KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > projectimport > j2seimport > WarningContainer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.projectimport.j2seimport;
21 import java.util.Collection JavaDoc;
22 import java.util.Iterator JavaDoc;
23 import java.util.LinkedHashSet JavaDoc;
24 import java.util.LinkedList JavaDoc;
25 import java.util.logging.Logger JavaDoc;
26
27 /**
28  *
29  * @author Radek Matous
30  */

31 public final class WarningContainer {
32     public static final WarningContainer EMPTY = new WarningContainer();
33     private static final Logger JavaDoc logger =
34             LoggerFactory.getDefault().createLogger(WarningContainer.class);
35
36
37     private LinkedHashSet JavaDoc allWarnings = new LinkedHashSet JavaDoc();
38
39     public boolean add(final String JavaDoc message, final boolean notifyUser) {
40         if (this == EMPTY) {
41             logger.warning("unexpected call on EMPTY WarningSupport ");//NOI18N
42
return false;
43         }
44         return allWarnings.add(new WarningContainer.Warning(message, notifyUser));
45     }
46     
47     public boolean addAll(final WarningContainer toAdd) {
48         if (this == EMPTY) {
49             logger.warning("unexpected call on EMPTY WarningSupport ");//NOI18N
50
return false;
51         }
52         
53         return this.allWarnings.addAll(toAdd.allWarnings);
54     }
55     
56     public boolean isEmpty() {
57         return allWarnings.isEmpty();
58     }
59
60     public int size() {
61         return allWarnings.size();
62     }
63     
64     public Collection JavaDoc getAllWarnings() {
65         return new LinkedList JavaDoc(allWarnings);
66     }
67     
68     public Iterator JavaDoc/*<WarningSupport.Warning>*/ getIterator() {
69         return allWarnings.iterator();
70     }
71     
72             
73     public static final class Warning {
74         private String JavaDoc message;
75         private boolean userNotification;
76         /** Creates a new instance of Warning */
77         private Warning(final String JavaDoc message, final boolean notifyUser) {
78             this.message = message;
79             this.userNotification = notifyUser;
80         }
81         
82         public String JavaDoc getMessage() {
83             return message;
84         }
85         
86         public boolean isUserNotification() {
87             return userNotification;
88         }
89         
90         
91         public String JavaDoc toString() {
92             return getMessage();
93         }
94     }
95 }
96
97
98
Popular Tags