Implement BugCollection.hashCode()
[cfb.git] / prod / net / jaekl / cfb / xml / BugCollection.java
index 9078e2fe95ef73f1a946ee397331264e33de470b..168c8f1c5787935a5c6badab052d291c2d1e74b0 100644 (file)
@@ -1,32 +1,73 @@
 package net.jaekl.cfb.xml;
 
-import org.xml.sax.Attributes;
+import java.io.PrintWriter;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
+import net.jaekl.cfb.util.Util;
 import net.jaekl.qd.xml.ParseResult;
 import net.jaekl.qd.xml.XmlParseException;
 
 public class BugCollection extends ParseResult {
 
-       static final String ROOT_TAG = "BugCollection";
+       static final String TAG = "BugCollection";
        static final String[] INTERNAL = { };
-       static final Object[][] EXTERNAL = { { BugInstance.ROOT_TAG, BugInstance.class} };
+       static final Object[][] EXTERNAL = { { BugInstance.TAG, BugInstance.class} };
 
+       ArrayList<BugInstance> m_bugs;
+       
        public BugCollection() {
-               super(ROOT_TAG, INTERNAL, EXTERNAL);
+               super(TAG, INTERNAL, EXTERNAL);
+               m_bugs = new ArrayList<BugInstance>();
        }
        
+       public List<BugInstance> getBugs() { return Collections.unmodifiableList(m_bugs); }
+       public void add(BugInstance bug) { m_bugs.add(bug); }
+       
        @Override
-       public void endContents(String uri, String localName, String qName,
-                       String chars, Attributes attr) throws XmlParseException {
-               // TODO Auto-generated method stub
-
+       public void endContents(String uri, String localName, String qName,     String chars) 
+               throws XmlParseException 
+       {
+               // no-op
        }
 
        @Override
        public void endExternal(String uri, String localName, String qName)
-                       throws XmlParseException {
-               // TODO Auto-generated method stub
-
+               throws XmlParseException 
+       {
+               if (BugInstance.TAG.equals(localName)) {
+                       ParseResult[] collected = collectParsedChildren(BugInstance.class);
+                       for (ParseResult pr : collected) {
+                               assert(pr instanceof BugInstance);
+                               m_bugs.add((BugInstance) pr);
+                       }
+               }
+       }
+       
+       @Override
+       public void dump(PrintWriter pw, int indent) {
+               super.dump(pw, indent);
+               for (BugInstance bug : m_bugs) {
+                       bug.dump(pw, indent + 2);
+               }
        }
 
+       @Override
+       public boolean equals(Object obj) {
+               if (null == obj) {
+                       return false;
+               }
+               if (! (obj instanceof BugCollection)) {
+                       return false;
+               }
+               BugCollection other = (BugCollection)obj;
+               
+               return Util.listsAreEqual(this.m_bugs, other.m_bugs);
+       }
+       
+       @Override
+       public int hashCode() {
+               return Util.objHashCode(m_bugs);
+       }
 }