SimpleViolation.java


Package: org.hammurapi

Results
Date2007/07/27
Codebase1262
Reviews2269
DPMO158
Sigma5.101

Metrics
NameNumberMinAvgMaxTotal
Class complexity125.0025.0025.0025.00
Code length71.007.8527.0055.00
File length1136.00136.00136.00136.00
Operation complexity71.003.5712.0025.00
Work order162.1262.1262.1262.12

Violations
#LineColumnNameSeverityDescription
1231ER-0233Packages should begin with []
252101ER-0363Line is too long
378120ER-0363Line is too long
49386ER-0363Line is too long
59481ER-0363Line is too long
69698ER-0363Line is too long
79793ER-0363Line is too long
810084ER-0363Line is too long
910781ER-0363Line is too long
1012493ER-0363Line is too long
1112533ER-0363Line is too long
12126109ER-0363Line is too long
13361ER-0492Unify logging strategy - define individual logger for class
143817ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
15469ER-1132Unused private/local variables
16529ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
17889ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
181199ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc

JavaDoc
SimpleViolation

1/*
2 * Hammurapi
3 * Automated Java code review system.
4 * Copyright (C) 2004 Hammurapi Group
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 * URL: http://www.hammurapi.org
21 * e-Mail: support@hammurapi.biz
22 */

23package org.hammurapi;
24
25import java.io.Serializable;
26import java.util.HashMap;
27import java.util.Map;
28
29import com.pavelvlasov.review.SourceMarker;
30import com.pavelvlasov.review.SourceMarkerComparator;
31
32/**
33 * @author Pavel Vlasov
34 * @version $Revision: 1.5 $
35 */

36public class SimpleViolation implements Violation, Serializable {
37 private static ThreadLocal inspectorMap=new ThreadLocal() {
38 protected Object initialValue() {
39 return new HashMap();
40 }
41 };
42
43 /**
44 * Comment for <code>serialVersionUID</code>
45 */

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 /**
68 * @return Returns the message.
69 */

70 public String getMessage() {
71 return message;
72 }
73
74 /**
75 * @return Returns the ruleName.
76 */

77 public InspectorDescriptor getDescriptor() {
78 return inspectorName==null ? null : (InspectorDescriptor) ((Map) inspectorMap.get()).get(inspectorName);
79 }
80
81 /**
82 * @return Returns the source.
83 */

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 // Inspector descriptor is ignored in equality.
126
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
137

Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.