1 23 package org.hammurapi; 24 25 import java.io.Serializable ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import com.pavelvlasov.review.SourceMarker; 30 import com.pavelvlasov.review.SourceMarkerComparator; 31 32 36 public class SimpleViolation implements Violation, Serializable { 37 private static ThreadLocal inspectorMap=new ThreadLocal () { 38 protected Object initialValue() { 39 return new HashMap (); 40 } 41 }; 42 43 46 private static final long serialVersionUID = -6111796217286959070L; 47 private SourceMarker source; 48 private String message; 49 50 private String inspectorName; 51 52 public SimpleViolation(SourceMarker source, String message, InspectorDescriptor descriptor) { 53 super(); 54 this.source=source; 55 56 if (descriptor!=null) { 57 Map iMap = (Map ) inspectorMap.get(); 58 if (iMap!=null) { 59 iMap.put(descriptor.getName(), descriptor); 60 } 61 inspectorName=descriptor.getName(); 62 } 63 64 this.message=message; 65 } 66 67 70 public String getMessage() { 71 return message; 72 } 73 74 77 public InspectorDescriptor getDescriptor() { 78 return inspectorName==null ? null : (InspectorDescriptor) ((Map ) inspectorMap.get()).get(inspectorName); 79 } 80 81 84 public SourceMarker getSource() { 85 return source; 86 } 87 88 public int compareTo(Object o) { 89 if (o==this) { 90 return 0; 91 } else if (o instanceof Violation) { 92 Violation v=(Violation) o; 93 int vline = v.getSource()==null ? 0 : v.getSource().getLine(); 94 int line = getSource()==null ? 0 : getSource().getLine(); 95 if (vline==line) { 96 int vcolumn = v.getSource()==null ? 0 : v.getSource().getColumn(); 97 int column = getSource()==null ? 0 : getSource().getColumn(); 98 if (vcolumn==column) { 99 if (message==null) { 100 return v.getMessage()==null ? 0 : 1; 101 } 102 103 if (v.getMessage()==null) { 104 return -1; 105 } 106 107 return message.compareTo(v.getMessage()); 108 } 109 110 return column-vcolumn; 111 } 112 113 return line-vline; 114 } else { 115 return 1; 116 } 117 } 118 119 public boolean equals(Object obj) { 120 if (obj==this) { 121 return true; 122 } else if (obj instanceof Violation) { 123 Violation v=(Violation) obj; 124 if (SourceMarkerComparator._compare(getSource(), v.getSource())==0) { 125 return message==null ? v.getMessage()==null : message.equals(v.getMessage()); 127 } 128 129 return false; 130 } else { 131 return super.equals(obj); 132 } 133 } 134 135 } 136 | Popular Tags |