(Finally) reach the point where we have some useful, if basic, functionality.
[cfb.git] / prod / net / jaekl / cfb / store / Location.java
index 8755fe6cc5945a7e18d298f6bb3f09bcad450de5..51857eb48c2289ca6aa94991dcec7b2ed4716927 100644 (file)
@@ -1,5 +1,8 @@
 package net.jaekl.cfb.store;
 
+import java.io.PrintWriter;
+
+import net.jaekl.cfb.util.Util;
 import net.jaekl.cfb.xml.BugClass;
 import net.jaekl.cfb.xml.BugMethod;
 import net.jaekl.cfb.xml.SourceLine;
@@ -9,8 +12,8 @@ public class Location {
        String m_className;
        String m_methodName;
        String m_methodRole;
-       int m_startLine;
-       int m_endLine;
+       Integer m_startLine;
+       Integer m_endLine;
        
        public Location(SourceLine sourceLine)
        {
@@ -39,9 +42,14 @@ public class Location {
                m_className = bugClass.getClassName();
        }
        
-       public Location(Long id, String className, String methodName, String methodRole, long startLine, long endLine)
+       public Location(Long id, String className, String methodName, String methodRole, Integer startLine, Integer endLine)
        {
-               
+               m_id = id;
+               m_className = className;
+               m_methodName = methodName;
+               m_methodRole = methodRole;
+               m_startLine = startLine;
+               m_endLine = endLine;
        }
        
        public String getClassName() { return m_className; }
@@ -50,6 +58,68 @@ public class Location {
        public int getStart() { return m_startLine; }
        public int getEnd() { return m_endLine; }
        
+       public void dump(PrintWriter pw, int indent) 
+       {
+               String margin = String.format("%" + indent + "s", "");
+               String tab = margin + "  ";
+               pw.println(margin + "Location");
+               if (null != m_className) {
+                       pw.println(tab + "classname = " + m_className);
+               }
+               if (null != m_methodName) {
+                       if (null != m_methodRole) {
+                               pw.println(tab + "method = " + m_methodName + " (" + m_methodRole + ")");
+                       }
+                       else {
+                               pw.println(tab + "method = " + m_methodName);
+                       }
+               }
+               if (null != m_startLine) {
+                       pw.println(tab + "lines = " + m_startLine + " .. " + m_endLine);
+               }
+       }
+
+       public boolean fuzzyEquals(Location that)
+       {
+               if (null == that) {
+                       return false;
+               }
+               
+               if (! Util.objsAreEqual(this.m_className, that.m_className)) {
+                       return false;
+               }
+               
+               if (! Util.objsAreEqual(this.m_methodName, that.m_methodName)) {
+                       return false;
+               }
+               
+               if (! Util.objsAreEqual(this.m_methodRole, that.m_methodRole)) {
+                       return false;
+               }
+               
+               return true;
+       }
+       
+       @Override
+       public boolean equals(Object other)
+       {
+               if (null == other) {
+                       return false;
+               }
+               if (other instanceof Location) {
+                       return fuzzyEquals((Location)other);
+               }
+               return false;
+       }
+       
+       @Override
+       public int hashCode()
+       {
+               return   Util.objHashCode(m_className)
+                          ^ Util.objHashCode(m_methodName)
+                          ^ Util.objHashCode(m_methodRole);
+       }
+       
        private void init(SourceLine[] sourceLines) 
        {
                if (sourceLines.length > 0) {