WaiverSet.java


Package: org.hammurapi

Results
Date2007/07/27
Codebase1509
Reviews2974
DPMO107
Sigma5.2

Metrics
NameNumberMinAvgMaxTotal
Class complexity123.0023.0023.0023.00
Code length61.0010.6635.0064.00
File length1150.00150.00150.00150.00
Operation complexity61.003.8312.0023.00
Work order164.8564.8564.8564.85

Violations
#LineColumnNameSeverityDescription
1241ER-0233Packages should begin with []
28582ER-0363Line is too long
387101ER-0363Line is too long
490126ER-0363Line is too long
594100ER-0363Line is too long
6105118ER-0363Line is too long
710681ER-0363Line is too long
812397ER-0363Line is too long
9129101ER-0363Line is too long
1013288ER-0363Line is too long
11401ER-0492Unify logging strategy - define individual logger for class
12449ER-1132Unused private/local variables
13609ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc
141229ER-1053Document all Interfaces and public methods. Use a Class header. Provide Javadoc

JavaDoc
WaiverSet

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 */

23
24package org.hammurapi;
25
26import java.util.Collection;
27import java.util.Date;
28import java.util.HashMap;
29import java.util.Iterator;
30import java.util.LinkedList;
31import java.util.Map;
32
33import com.pavelvlasov.review.Signed;
34import com.pavelvlasov.review.SourceMarker;
35
36/**
37 * @author Pavel Vlasov
38 * @version $Revision: 1.8 $
39 */

40public class WaiverSet {
41 /**
42 * Comment for <code>serialVersionUID</code>
43 */

44 private static final long serialVersionUID = 4873150699959326186L;
45 private Map signatureMap=new HashMap();
46 private Collection rejectedRequests=new LinkedList();
47
48 /**
49 * @return Collection of waivers remaining in the set
50 */

51 public Collection getWaivers() {
52 Collection ret=new LinkedList();
53 Iterator it=signatureMap.values().iterator();
54 while (it.hasNext()) {
55 ret.addAll(((Map) it.next()).values());
56 }
57 return ret;
58 }
59
60 public int size() {
61 int ret=0;
62 Iterator it=signatureMap.values().iterator();
63 while (it.hasNext()) {
64 ret+=((Map) it.next()).size();
65 }
66 return ret;
67 }
68
69 /**
70 * @return Collection of violations which requested waivers, but
71 * weren't granted ones.
72 */

73 public Collection getRejectedRequests() {
74 return rejectedRequests;
75 }
76
77 /**
78 * Requests and removes a waiver from the set. Waivers with signature==null
79 * aren't removed as they apply to multiple violations.
80 * @param violation
81 * @param peek Just peek for waiver.
82 * @return Waiver if there is one for the violation, null otherwise.
83 */

84 public Waiver requestWaiver(Violation violation, boolean peek) {
85 if (Boolean.TRUE.equals(violation.getDescriptor().isWaivable())) {
86 SourceMarker sm=violation.getSource();
87 String signature= sm instanceof Signed ? ((Signed) sm).getSignature() : null;
88 if (signature!=null) {
89 Map nameMap=(Map) signatureMap.get(signature);
90 Waiver ret = nameMap==null ? null : (Waiver) nameMap.get(violation.getDescriptor().getName());
91
92 if (ret!=null) {
93 if (!peek) {
94 nameMap.remove(violation.getDescriptor().getName());
95 }
96
97 if (ret.waive(violation, peek)) {
98 return ret;
99 }
100 }
101 }
102
103
104 Map nameMap=(Map) signatureMap.get(null);
105 Waiver ret = nameMap==null ? null : (Waiver) nameMap.get(violation.getDescriptor().getName());
106 boolean waived = ret!=null && ret.waive(violation, peek);
107
108 if (!waived) {
109 rejectedRequests.add(violation);
110 }
111
112 if (ret!=null && !ret.isActive()) {
113 nameMap.remove(ret.getInspectorName());
114 }
115
116 return waived ? ret : null;
117 }
118
119 return null;
120 }
121
122 public void addWaiver(Waiver waiver, Date now) {
123 if (waiver.getExpirationDate()==null || now.before(waiver.getExpirationDate())) {
124 Collection signatures = waiver.getSignatures();
125 if (signatures!=null && !signatures.isEmpty()) {
126 Iterator it=signatures.iterator();
127 while (it.hasNext()) {
128 String signature=(String) it.next();
129 getNameMap(signature).put(waiver.getInspectorName(), waiver);
130 }
131 } else {
132 getNameMap(null).put(waiver.getInspectorName(), waiver);
133 }
134 }
135 }
136
137 /**
138 * @param signature
139 * @return name map
140 */

141 private Map getNameMap(String signature) {
142 Map nameMap=(Map) signatureMap.get(signature);
143 if (nameMap==null) {
144 nameMap=new HashMap();
145 signatureMap.put(signature, nameMap);
146 }
147 return nameMap;
148 }
149}
150
151

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