Sie sind auf Seite 1von 10

SoItware DeIects Prevention Techniques Example Project

MapsObjects.jaa iolations
lxxi
Avoid unnecessary comparisons in boolean expressions 181 PMD Marker
Avoid unnecessary comparisons in boolean expressions 184 PMD Marker
Cyclomatic Complexity is 7 197 Metrics Marker
Lines of Code in Method is 23 197 Metrics Marker
Number of Statements is 42 197 Metrics Marker
Avoid using if statements without curly braces 204 PMD Marker
Avoid unnecessary comparisons in boolean expressions 206 PMD Marker
Avoid using if statements without curly braces 217 PMD Marker
Avoid using if statements without curly braces 218 PMD Marker
A method should have only one exit point, and that should be the last statement in the method 259 PMD Marker
Comparison of String parameter using == or != in MapObjects.removeRoute(String) 281 FindBugs
Cyclomatic Complexity is 9 288 Metrics Marker
Lines of Code in Method is 20 288 Metrics Marker
Number of Statements is 36 288 Metrics Marker
The method 'getDirection' has a Cyclomatic Complexity of 17. 288 PMD Marker
The method getDirection() has an NPath complexity of 6561 288 PMD Marker
Avoid using if statements without curly braces 296 PMD Marker
Avoid using if statements without curly braces 297 PMD Marker
Cyclomatic Complexity is 9 309 Metrics Marker
Lines of Code in Method is 29 309 Metrics Marker
Number of Statements is 48 309 Metrics Marker
Zarko Acimovic
MapObjects.jaa
1 /**
2 *
3 * Napb]ec1s con1ro1s appearance o1 a11 map ob]ec1s on curren1 screen
4 */
5 mpor1 ava.u11.*,
6 //InpoI1 ]ava.Io.*;
7 mpor1 avax.m1cJoed111oh.cdu1.*,
8
9 pub1c c1ass hap0bec1s {
10
11 hapBackgJouhd mb,
12 Pon1 cuJJeh1Pos111oh,
13 Pon1 pJev1ousPos111oh,
14 Pon1 des11ha11ohPos111oh,
15 Pvec1oJ 1JeeWaypo1h1s,
16 vec1or Jou1es,
17 Pvec1oJ cuJJeh1Rou1e,
18 vec1or dJawabePo1h1s,
19 hash1ab1e 1J1ehds,
20 booeah dJawL1he = 1a1se,
21 booeah des1Se1 = 1a1se,
22 booeah cuJJeh1Se1 = 1a1se,
23
24
25
26 hap0bec1s{hapBackgJouhd mb){
27 1hs.mb = mb,
28 cuJJeh1Pos111oh = mb.ge1hewEdge{),
29 des11ha11ohPos111oh = mb.ge1hewEdge{),
30 cuJJeh1Pos111oh.se1hame{"dummy"),
31 des11ha11ohPos111oh.se1hame{"dummy"),
32 Jou1es = neW vec1or{),
33 1J1ehds = neW hash1ab1e{),
34 }
35
36 /** 5e1s draWab1e Pon1s 1or curren1 5creen
37 *
38 */
39 pub1c vo1d se10JawabePo1h1s{){
40 vec1or 1emp1 = neW vec1or{),
41 vec1or 1emp2,
42
43 //check I1 cuIIen1 and des1Ina1Ion aIe vIsIb1e
44 1{1hs.cuJJeh1Pos111oh.check{mb.ge1hewEdge{), mb.ge10owhEhd{))) {
45
cuJJeh1Pos111oh.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
lxxii
SoItware DeIects Prevention Techniques Example Project
46 1emp1.addEemeh1{cuJJeh1Pos111oh),
47 }
48 1{1hs.des11ha11ohPos111oh.check{mb.ge1hewEdge{),
mb.ge10owhEhd{))) {
49
des11ha11ohPos111oh.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
50 1emp1.addEemeh1{des11ha11ohPos111oh),
51 }
52
53 //check |hIch 1Iee |aypoIn1s aIe vIsIb1e
54 1emp2 = 1JeeWaypo1h1s.ge1Po1h1s{mb.ge1hewEdge{),mb.ge10owhEhd{)),
55 1or {1h1 =0, <1emp2.s1ze{), ++){
56 Pon1 wp = {Pon1)1emp2.eemeh1A1{),
57 wp.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
58 1emp1.addEemeh1{wp),
59 }
60
61
62 //check |hIch Iou1e poIn1s aIe vIsIb1e
63 1or {1h1 1=0, 1<Jou1es.s1ze{), 1++){
64 Pvec1oJ v = {Pvec1oJ)Jou1es.eemeh1A1{1),
65 1 {v.ge1v1s1be{)==1rue){
66 1emp2 =
v.ge1Po1h1s{mb.ge1hewEdge{),mb.ge10owhEhd{)),
67
68 1or {1h1 =0, <1emp2.s1ze{), ++){
69 Pon1 wp = {Pon1)1emp2.eemeh1A1{),
70
wp.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
71 1emp1.addEemeh1{wp),
72 }
73 }
74 }
75 dJawabePo1h1s = 1emp1,
76 }
77
78 /** e1urns draWab1e Pon1s 1or curren1 5creen
79 * Qre1urn vec1or
86 */
81 pub1c vec1or ge10JawabePo1h1s0d{){
82
83 re1urn dJawabePo1h1s,
84 }
85
86 pub1c vec1or ge10JawabePo1h1s{){
87 1hs.se10JawabePo1h1s{),
88 re1urn dJawabePo1h1s,
89 }
90
91
92 pub1c vo1d se1CuJJeh1Pos111oh{Pon1 wp){
lxxiii
Zarko Acimovic
93 pJev1ousPos111oh = cuJJeh1Pos111oh,
94 cuJJeh1Pos111oh = wp,
95
cuJJeh1Pos111oh.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
96 cuJJeh1Se1 = 1rue,
97 }
98
99 /** ese1 curren1 pos1on
166 */
101 pub1c vo1d Jese1CuJJeh1Pos111oh{){
102 cuJJeh1Pos111oh = mb.ge1hewEdge{),
103 dJawL1he = 1a1se,
104 cuJJeh1Se1 = 1a1se,
105 }
106
107 /** e1urns curren1 pos1on
168 * Qre1urn Pon1
169 */
110 pub1c Pon1 ge1CuJJeh1Pos111oh{){
111 re1urn cuJJeh1Pos111oh,
112 }
113
114
115 /** 5e1 des1na1on pos1on
116 */
117 pub1c vo1d se10es11ha11ohPos111oh{Pon1 wp){
118 des11ha11ohPos111oh = wp,
119 des1Se1 = 1rue,
120 }
121
122 /** ese1 des1na1on pos1on
123 */
124 pub1c vo1d Jese10es11ha11ohPos111oh{){
125 des11ha11ohPos111oh = mb.ge1hewEdge{),
126 dJawL1he = 1a1se,
127 des1Se1 = 1a1se,
128 }
129
130 /** e1urns des1na1on pos1on
131 * Qre1urn Pon1
132 */
133 pub1c Pon1 ge10es11ha11ohPos111oh{){
134 re1urn des11ha11ohPos111oh,
135 }
136
137 /** e1urns a11 rou1es
138 */
139 pub1c vec1or ge1Rou1es{){
140 re1urn Jou1es,
141 }
142
lxxiv
SoItware DeIects Prevention Techniques Example Project
143 /** e1urns 1ree vec1or o1 1ree Pon1s
144 */
145 pub1c Pvec1oJ ge1FJeeWaypo1h1s{){
146 re1urn 1JeeWaypo1h1s,
147 }
148
149 /** raWs Napb]ec1s --- 5LETE!
J50 */
151 pub1c vo1d dJawh0Bod{Craphcs g, booeah Jou1e){
152 ohg z = mb.ge1ZoomLeve{)+1,
153 Long zz = neW Long{z),
154 1h1 zoomL = In1eger.paJseTh1{zz.1oS1J1hg{)),
155 1hs.se10JawabePo1h1s{),
156
157 // 0Ia|Ing o1 1Ine bee1|en des1Ina1Ion and cuIIen1 posI1Ion
158 1{dJawL1he==1rue){
159
cuJJeh1Pos111oh.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
160
des11ha11ohPos111oh.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
161
g.dJawL1he{cuJJeh1Pos111oh.ge1XX{),cuJJeh1Pos111oh.ge1YY{),des11ha11ohPos111oh.ge1X
X{),des11ha11ohPos111oh.ge1YY{)),
162 }
163
164 // 0Ia|Ing o1 1Iee PoIn1s, cuIIen1 posI1Ion and des1Ina1Ion
posI1Ion
165 1or{1h1 1=0, 1<dJawabePo1h1s.s1ze{), 1++){
166 Pon1 wp = {Pon1)dJawabePo1h1s.eemeh1A1{1),
167 1{wp.ge1Tmage{).equas{"bahco")){
168 g.11Rec1{wp.ge1XX{),wp.ge1YY{),5*zoomL,5*zoomL),
169 g.dJawS1J1hg{wp.ge1hame{),wp.ge1XX{)+5,wp.ge1YY{)
+5,0),
170 } e1se {
171 Image 1mg = nu11,
172 1ry{
173 1mg =
Image.cJea1eTmage{wp.ge1Tmage{)),
174 }ca1ch{Excep1on e){}
175 g.dJawTmage{1mg,wp.ge1XX{),wp.ge1YY{),0),
176 }
177
178 }
179
180 // 0Ia|Ing o1 Iou1e
181 1{Jou1e==1rue){
182 1or{1h1 1=0, 1<Jou1es.s1ze{), 1++){
183 Pvec1oJ wpv = {Pvec1oJ)Jou1es.eemeh1A1{1),
184 1{wpv.ge1v1s1be{)==1rue){
185 1or{1h1 =0, <wpv.s1ze{)-1, ++){
lxxv
Zarko Acimovic
186 Pon1 wp1 = {Pon1)
wpv.eemeh1A1{),
187 Pon1 wp2 = {Pon1)
wpv.eemeh1A1{+1),
188
wp1.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
189
wp2.se1XY{mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{)),
190
g.dJawL1he{wp1.ge1XX{),wp1.ge1YY{),wp2.ge1XX{),wp2.ge1YY{)),
191 }
192 }
193 }
194 }
195 }
196
197 /** raWs Napb]ec1s
198 */
199 pub1c vo1d dJawh0B{Craphcs g, booeah Jou1e){
200 g.se1CooJ{0,0,0),
201
202
1JeeWaypo1h1s.dJawvec1oJ{g,1a1se,mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{),mb.g
e1ZoomLeve{)),
203
204 1{1J1ehds.s1ze{)!=0)
1hs.ge1FJ1ehds{).dJawvec1oJ{g,1a1se,mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{),
0),
205
206 1{Jou1e==1rue){
207 1or {1h1 1 =0, 1<Jou1es.s1ze{), 1++){
208 Pvec1oJ wpv = {Pvec1oJ)Jou1es.eemeh1A1{1),
209
wpv.dJawvec1oJ{g,Jou1e,mb.ge1hewEdge{),mb.ge1P1xLoh{),mb.ge1P1xLa1{),mb.ge1ZoomLeve
{)),
210 }
211 }
212
213 1{cuJJeh1Se1) {
214
cuJJeh1Pos111oh.dJawPo1h1{g,mb.ge1hewEdge{),mb.ge1P1xLa1{),mb.ge1P1xLoh{),mb.ge1Zoo
mLeve{)),
215
216 }
217 1{des1Se1)
des11ha11ohPos111oh.dJawPo1h1{g,mb.ge1hewEdge{),mb.ge1P1xLa1{),mb.ge1P1xLoh{),mb.ge
1ZoomLeve{)),
218 1{cuJJeh1Se1 && des1Se1)
g.dJawL1he{cuJJeh1Pos111oh.ge1XX{),cuJJeh1Pos111oh.ge1YY{),des11ha11ohPos111oh.ge1X
X{),des11ha11ohPos111oh.ge1YY{)),
219 }
lxxvi
SoItware DeIects Prevention Techniques Example Project
220
221
222
223
224 /** Adds 1ree Pon1
225 */
226 pub1c vo1d addFJeeWaypo1h1{Pon1 wp){
227 1hs.1JeeWaypo1h1s.addEemeh1{wp),
228 }
229
230 /** Adds neW rou1e
231 */
232 pub1c vo1d addRou1e{Pvec1oJ v){
233 1hs.Jou1es.addEemeh1{v),
234 }
235
236 /** Adds neW Pon1 1o rou1e W1h rou1eI on pos1on pos
237 */
238 pub1c vo1d addWP2Rou1e{Pon1 wp, 1h1 Jou1eT0, 1h1 pos) {
239 Pvec1oJ Jou1e,
240 1or {1h1 1=0, 1<Jou1es.s1ze{), 1++){
241 Jou1e = {Pvec1oJ)Jou1es.eemeh1A1{1),
242 1{Jou1e.ge1T0{)==Jou1eT0){
243 Jou1e.1hseJ1Eemeh1A1{wp,pos),
244 1=1000,
245 }
246 }
247 }
248
249 /** 5e1s 1ree Waypon1s vec1or
256 */
251 pub1c vo1d se1FJeeWaypo1h1sv{Pvec1oJ wpv){
252 1hs.1JeeWaypo1h1s = wpv,
253 }
254
255 /** Neasure ds1ance
256 */
257 pub1c ohg measuJe01s1ahce{Pon1 wp){
258 1 {cuJJeh1Pos111oh.equas{mb.ge1hewEdge{))) {
259 re1urn -1,
260 } e1se {
261 re1urn cuJJeh1Pos111oh.measuJe01s1ahce{wp),
262 }
263 }
264
265 pub1c booeah cuJJeh1Se1{){
266 re1urn cuJJeh1Se1,
267 }
268
269 pub1c booeah des1Se1{){
270 re1urn des1Se1,
lxxvii
Zarko Acimovic
271 }
272
273
274 pub1c vo1d JemoveRou1e{Pvec1oJ wJ){
275 Jou1es.JemoveEemeh1{wJ),
276 }
277
278 pub1c vo1d JemoveRou1e{51rng s){
279 1or{1h1 1=0, 1<Jou1es.s1ze{), 1++){
280 Pvec1oJ J1 = {Pvec1oJ)Jou1es.eemeh1A1{1),
281 1 {J1.ge1hame{)==s) {
282 Jou1es.JemoveEemeh1A1{1),
283 1=1000,
284 }
285 }
286 }
287
288 pub1c ohg ge101Jec11oh{){
289
290 ohg d1Jec11oh = 0,
291 ohg a1P = pJev1ousPos111oh.ge1La1{),
292 ohg ohP = pJev1ousPos111oh.ge1Loh{),
293 ohg a1C = cuJJeh1Pos111oh.ge1La1{),
294 ohg ohC = cuJJeh1Pos111oh.ge1Loh{),
295
296 1{a1C>a1P && ohP==ohC) d1Jec11oh = ha1hFP.1oFP{"0"),
297 1{a1C>a1P && ohC>ohP) d1Jec11oh = ha1hFP.1oFP{"45"),
298 1{a1P==a1C && ohC>ohP) d1Jec11oh = ha1hFP.1oFP{"90"),
299 1{a1C<a1P && ohC>ohP) d1Jec11oh = ha1hFP.1oFP{"135"),
300 1{a1C<a1P && ohP==ohC) d1Jec11oh = ha1hFP.1oFP{"180"),
301 1{a1C<a1P && ohC<ohP) d1Jec11oh = ha1hFP.1oFP{"225"),
302 1{a1P==a1C && ohC<ohP) d1Jec11oh = ha1hFP.1oFP{"270"),
303 1{a1C>a1P && ohC<ohP) d1Jec11oh = ha1hFP.1oFP{"315"),
304
305 d1Jec11oh = CooJd1ha1es.degJeesToRad1ahs{d1Jec11oh),
306 re1urn d1Jec11oh,
307 }
308
309 /** Ths s no1 Workng We11
316 */
311 pub1c ohg ge1BeaJ1hg{){
312
313 ohg beaJ1hg = 0,
314 ohg a1P = pJev1ousPos111oh.ge1La1{),
315 ohg ohP = pJev1ousPos111oh.ge1Loh{),
316 ohg a10 = des11ha11ohPos111oh.ge1La1{),
317 ohg oh0 = des11ha11ohPos111oh.ge1Loh{),
318
319
320 //I1]1a10>1a1P 55 1on0==1onP) beaIIng = |a1hFP.1oFP]"0");
lxxviii
SoItware DeIects Prevention Techniques Example Project
321 1{ a10>a1P && ha1hFP.abs{ha1hFP.sub{oh0,ohP))<ha1hFP.1oFP{"5")
) beaJ1hg = ha1hFP.1oFP{"0"),
322 1{a10>a1P && oh0>ohP) beaJ1hg = ha1hFP.1oFP{"45"),
323 //I1]1a10==1a1P 55 1on0>1onP) beaIIng = |a1hFP.1oFP]"0");
324 1{ha1hFP.abs{ha1hFP.sub{a10,a1P))<ha1hFP.1oFP{"5") && oh0>ohP)
beaJ1hg = ha1hFP.1oFP{"90"),
325 1{a10<a1P && oh0>ohP) beaJ1hg = ha1hFP.1oFP{"135"),
326 //I1]1a10<1a1P 55 1onP==1on0) beaIIng = |a1hFP.1oFP]"J80");
327 1{a10<a1P &&
ha1hFP.abs{ha1hFP.sub{oh0,ohP))<ha1hFP.1oFP{"5") ) beaJ1hg = ha1hFP.1oFP{"180"),
328 1{a10<a1P && oh0<ohP) beaJ1hg = ha1hFP.1oFP{"225"),
329 //I1]1a1P==1a10 55 1on0<1onP) beaIIng = |a1hFP.1oFP]"270");
330 1{ha1hFP.abs{ha1hFP.sub{a10,a1P))<ha1hFP.1oFP{"5") && oh0<ohP)
beaJ1hg = ha1hFP.1oFP{"270"),
331 1{a10>a1P && oh0<ohP) beaJ1hg = ha1hFP.1oFP{"315"),
332
333
334 beaJ1hg = CooJd1ha1es.degJeesToRad1ahs{beaJ1hg),
335 re1urn beaJ1hg,
336
337 }
338
339
340 pub1c vo1d addhewFJ1ehd{1h1 1J1ehdT0){
341 Pon1 dummy = neW Pon1{cuJJeh1Pos111oh,1a1se),
342 In1eger 1JT0 = neW In1eger{1J1ehdT0),
343 1J1ehds.pu1{1JT0,dummy),
344 }
345
346 pub1c vo1d upda1eFJ1ehd{In1eger 1J1ehdT0,Pon1 p){
347 1J1ehds.pu1{1J1ehdT0,p),
348 }
349
350 pub1c vo1d dee1eFJ1ehd{1h1 1J1ehdT0){
351 In1eger 1JT0 = neW In1eger{1J1ehdT0),
352 1J1ehds.Jemove{1JT0),
353 5ys1em.ou1.pJ1h1h{1J1ehds),
354 }
355
356 pub1c vo1d dee1eAFJ1ehds{){
357 //Sys1en.ou1.pIIn11n]"YJPJ Y444 YEEEEE");
358 1J1ehds.ceaJ{),
359 //Sys1en.ou1.pIIn11n]1IIends);
360 }
361
362
363 /** Converson o1 hash1ab1e n1o vec1or
364 */
365 pub1c Pvec1oJ ge1FJ1ehds{){
366 vec1or v = neW vec1or{),
367 Enumera1on e = 1J1ehds.eemeh1s{),
lxxix
Zarko Acimovic
368 Wh1e{e.hashoJeEemeh1s{)){
369 v.addEemeh1{{Pon1)e.hex1Eemeh1{)),
370 }
371
372 Pvec1oJ PFJ1ehds = neW Pvec1oJ{v,1a1se),
373 re1urn PFJ1ehds,
374 }
375
376
377
378 }
lxxx

Das könnte Ihnen auch gefallen