Implement BugCollection.hashCode()
[cfb.git] / prod / net / jaekl / cfb / xml / BugCollection.java
1 package net.jaekl.cfb.xml;
2
3 import java.io.PrintWriter;
4 import java.util.ArrayList;
5 import java.util.Collections;
6 import java.util.List;
7
8 import net.jaekl.cfb.util.Util;
9 import net.jaekl.qd.xml.ParseResult;
10 import net.jaekl.qd.xml.XmlParseException;
11
12 public class BugCollection extends ParseResult {
13
14         static final String TAG = "BugCollection";
15         static final String[] INTERNAL = { };
16         static final Object[][] EXTERNAL = { { BugInstance.TAG, BugInstance.class} };
17
18         ArrayList<BugInstance> m_bugs;
19         
20         public BugCollection() {
21                 super(TAG, INTERNAL, EXTERNAL);
22                 m_bugs = new ArrayList<BugInstance>();
23         }
24         
25         public List<BugInstance> getBugs() { return Collections.unmodifiableList(m_bugs); }
26         public void add(BugInstance bug) { m_bugs.add(bug); }
27         
28         @Override
29         public void endContents(String uri, String localName, String qName,     String chars) 
30                 throws XmlParseException 
31         {
32                 // no-op
33         }
34
35         @Override
36         public void endExternal(String uri, String localName, String qName)
37                 throws XmlParseException 
38         {
39                 if (BugInstance.TAG.equals(localName)) {
40                         ParseResult[] collected = collectParsedChildren(BugInstance.class);
41                         for (ParseResult pr : collected) {
42                                 assert(pr instanceof BugInstance);
43                                 m_bugs.add((BugInstance) pr);
44                         }
45                 }
46         }
47         
48         @Override
49         public void dump(PrintWriter pw, int indent) {
50                 super.dump(pw, indent);
51                 for (BugInstance bug : m_bugs) {
52                         bug.dump(pw, indent + 2);
53                 }
54         }
55
56         @Override
57         public boolean equals(Object obj) {
58                 if (null == obj) {
59                         return false;
60                 }
61                 if (! (obj instanceof BugCollection)) {
62                         return false;
63                 }
64                 BugCollection other = (BugCollection)obj;
65                 
66                 return Util.listsAreEqual(this.m_bugs, other.m_bugs);
67         }
68         
69         @Override
70         public int hashCode() {
71                 return Util.objHashCode(m_bugs);
72         }
73 }