Вы находитесь на странице: 1из 184

Class Name

MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

Example Java Project Tested by


VizzMaintenance Metrics Eclipse Plugin

Zarko Acimovic
Copyright 2013 Zarko Acimovic
All rights reserved.

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

DEDICATION
I dedicate this book to my parents, Ivana and Goran

CONTENTS
1

Introduction

Means and Practices for Defect Prevention in Java


Software Development

EXAMPLE TOOLS FOR DEFECT PREVENTION IN


JAVA PROJECTS

Sample Project Specifications

METRICS

VizzMaintenance Report For Sample Project

Java Source Code

About the Author

170

Zarko Acimovic

1 INTRODUCTION
I present 5000 lines of Java source code mostly written by using trial-error, code-test, design-at-keyboard
techniques without using VizzMaintenance defect prevention tool. After the project was written,
VizzMaintenace tool was run against it and delivered report for it. Each class is preceded with VizzMaintenace
report and comment about class design issue based on VizzMaintenance judgment.
The code was written for prototype project in three months. I wrote the code in 2004 and ever since had several
business offers to commercialize it which I resisted due to complexity of the code.
I recommend readers to switch to formal software development, such as B, Event-B, VDM or Z.

2 MEANS AND PRACTICES FOR DEFECT PREVENTION


Prototyping (modeling) defect prevention method has efficiency 52%. Before implementing this method
defect potential per 1 FP (function point) was 5, after, 2.4.
Tool: ArgoUML

Static analysis of source code defect prevention method has efficiency 44%. Defect potential per 1 FP was
5, after implementing this method is 2.8.
Tool: Coverity

Mathematical test case design defect prevention efficiency was 34%. Defect potential per 1 FP is 5, after
is 3.3.
Tool: Bullseye

Bonus: Root cause analysis 1044-1993 - IEEE Standard Classification for Software Anomalies. Efficiency
41% - Before 5 After 2.95

Source: Chapter 3. Estimating and Measuring Software Quality. The Economics of Software Quality, ISBN:
9780132564762 , Capers Jones, Olivier Bonsignour

iv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

http://www.amazon.com/Economics-Software-Quality-Capers-Jones/dp/0132582201
http://www.informit.com/store/product.aspx?isbn=0132582201

3 EXAMPLE TOOLS FOR DEFECT PREVENTION IN JAVA PROJECTS


Source: http://codedependents.com/2009/07/01/top-5-static-analysis-plugins-for-eclipse/

Code Coverage tool EclEmma http://www.eclemma.org/


Byte Code Analysis FindBugs http://findbugs.sourceforge.net/
Code Complexity Analysis http://www.stateofflow.com/projects/16/eclipsemetrics
Dependency Analysis JDepend4Eclipse http://andrei.gmxhome.de/jdepend4eclipse/
Source Code Analysis PMD http://pmd.sourceforge.net/

4 SAMPLE PROJECT SPECIFICATION


Project duration 3 months, single developer , 5000 lines of code (including comments), 15 Java 2 Micro Edition
classes

Tools used: Sun J2ME Wireless Toolkit, Eclipse, IBM WebSphere Device Developer 5.5, CVS, Motorola and
Nokia phone emulators and SDKs. Technology: J2ME, MIDP 2.0, CLDC 1.1.
Device-independent Java 2 Micro Edition (J2ME) midlet, executable in any emulator or mobile device, for
displaying map with scale, following moving objects, zoom in-out and pan, selection of location , measuring
distance, following individual or vehicle on map with route presentation, presentation of waypoints on map,
presentation of list of existing waypoints (sorted by name, type, distance) for selecting destination or editing and
deletion, creating, editing and deletion of waypoint points with coordinates, name, type, icon; coordinates are
defined by current position, selected location on map or inserted in textual form, selection of waypoint as
destination and navigation towards that destination. Some classes implemented: MapBackground, MapObject,
v

Zarko Acimovic

Point, SelectorPoint, PVector, MapsMIDlet

5 METRICS (CLICK ON LINK FOR DETAILS)

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)

vi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

Coupling Factor (CF)


Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

5 VIZZMAINTENANCE REPORT FOR SAMPLE PROJECT

vii

Zarko Acimovic
Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

6 SOURCE CODE
As you can see in the above table the problem with below CommaHyphenString class is that LD metric is zero.
From http://www.arisa.se/compendium/node112.html we learn more about Loclity of Data metric:
The Locality of Data metric relates the amount of data being local the class to the total amount of data used by the
class. This relates to the quality of abstraction embodied by the class and allows conclusions on the reuse potential
of the class and testability. To find out precisely how this metric is calculated and how it affects software quality
attributes such as testability or maintainability please check http://www.arisa.se/compendium/node112.html
Also there is problem with Tight Class Cohesion. The Tight Class Cohesion metric measures the cohesion
between the public methods of a class. That is the relative number of directly connected public methods in the
class. Classes having a low cohesion indicate errors in the design. http://www.arisa.se/compendium/node118.html

Here is the CommaHyphenString.java source code


1
2
3

/**
*
* CommaHyphenString parses .properties file. It eliminates commas or low

lines
4
* from .properties file so items in it( such as categories) could be
properly
5
* showed on screen
6
*/
7 import java.util.*;
8
9 public class CommaHyphenString {
10
11
//String s;
12
int lastIndex;

viii

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63

CommaHyphenString(){}

/** Eliminates commas, returns array of strings with low line


* @return String[]
*/
String[] getWithLowLine(String s) {
int lastIndex = defineLast(s);
if(lastIndex==0){
String[] ss = new String[1];
ss[0] = s;
return ss;
} else {
int start = -1;
Vector v = new Vector();
int current = s.indexOf(',');
do {
v.addElement(s.substring(start+1,current));
start = current;
current = s.indexOf(',',current+1);
} while (start!=lastIndex);
String[] ss = new String[v.size()+1];
for(int i=0; i<v.size(); i++){
ss[i] = (String)v.elementAt(i);
}
ss[v.size()] = s.substring(lastIndex+1,s.length());
return ss;
}
}
/** Eliminates low line
* @return String[]
*/
String[] getStringsOnly(String s){
String[] temp = this.getWithLowLine(s);
for (int i=0; i<temp.length; i++){
char[] tempChar = temp[i].toCharArray();
String k = "";
for (int j=0; j<tempChar.length; j++){
if(tempChar[j]=='_') tempChar[j]=' ';
k+=tempChar[j];
}
temp[i] = k;
}
return temp;
}

/** Returns categories with low line


* @return String[]
ix

Zarko Acimovic

64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

*/
String[] getCategoriesHyphen(String s){
return this.getWithLowLine(s);
}
/** Returns categories
* @return String[]
*/
String[] getCategories(String s){
return this.getStringsOnly(s);
}
/** Defines index of last comma in string
* @return integer
*/
public int defineLast(String s){
int lastIndex = 0;
char c[] = s.toCharArray();
for (int i=0; i<c.length; i++){
if(c[i]==',') lastIndex=i;
}
return lastIndex;
}
}

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions

xi

Zarko Acimovic

Documentation
Lack Of Documentation (LOD)
Code Conventions

As you can see on the above table the problem with below class CompassCanvas is that LOD metric is zero. Lack
Of Documentation description: How many comments are lacking in a class, considering one class comment and a
comment per method as optimum. Structure and content of the comments are ignored. To find out how this metric
is calculated please check http://www.arisa.se/compendium/node121.html .

CompassCanvas.java source code


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

/**
*
* ComapssCanvas draws compass on screen
*/
import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;

public class CompassCanvas extends Canvas implements Runnable{


long north;
long south;
long east;
long west;
int bigRadius;
int smallRadius;
int smallestRadius;
Coordinates c;
long delta = 0;
Thread t;
boolean end = false;
boolean switchVar = false;
boolean switched = false;
MapObjects mob;
int dummy1
int dummy2
int dummy3
int dummy4
Image img;

=
=
=
=

0;
0;
0;
0;

Image imgDest;
long destUp;
long destDown;
long gama;

xii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


36
37
38
CompassCanvas(MapObjects mob){
39
this.mob = mob;
40
north = MathFP.toFP("0");
41
south = MathFP.div(Coordinates.MathFP_2PI,MathFP.toFP("2"));
42
east = MathFP.mul(Coordinates.MathFP_2PI,MathFP.toFP("0.25"));
43
west = MathFP.mul(Coordinates.MathFP_2PI,MathFP.toFP("0.75"));
44
45
destUp = MathFP.toFP("0");
46
destDown = MathFP.div(Coordinates.MathFP_2PI,MathFP.toFP("2"));
47
48
bigRadius = Math.min(this.getWidth(),this.getHeight());
49
smallRadius = (int)(0.75*bigRadius);
50
smallestRadius = (int)(0.37*bigRadius);
51
try{
52
img = Image.createImage("Arrow2.jpg");
53
}catch(Exception e){}
54
55
try{
56
imgDest = Image.createImage("Dest.jpg");
57
}catch(Exception e){}
58
59
t = new Thread(this);
60
t.start();
61
}
62
63
public void paint(Graphics g){
64
//System.out.println("delta="+MathFP.toString(delta));
65
g.setColor(255,255,255);
66
g.fillRect(0,0,this.getWidth(),this.getHeight());
67
g.setColor(0,0,0);
68
if(end == false){
69
g.drawImage(img,75,25,0);
70
71
//System.out.println("this.getWidth()="+this.getWidth());
72
//System.out.println("this.getHeight()="+this.getHeight());
73
g.drawArc(8,0,bigRadius,bigRadius,0,360);
74
g.drawArc(30,22,smallRadius,smallRadius,0,360);
75
76
String sx =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(75),MathFP.sin(Ma
thFP.sub(north,delta)))));
77
String sy =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(75),MathFP.cos(Ma
thFP.sub(north,delta)))));
78
int ix = sx.indexOf('.');
79
sx = sx.substring(0,ix);
80
int iy = sy.indexOf('.');
xiii

Zarko Acimovic

81
sy = sy.substring(0,iy);
82
83
int x = Integer.parseInt(sx);
84
int y = Integer.parseInt(sy);
85
86
String s9 =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(smallestRadius),M
athFP.sin(MathFP.sub(north,delta)))));
87
ix = s9.indexOf('.');
88
s9 = s9.substring(0,ix);
89
int NX = Integer.parseInt(s9);
90
String s10 =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(smallestRadius),M
athFP.cos(MathFP.sub(north,delta)))));
91
iy = s10.indexOf('.');
92
s10 = s10.substring(0,iy);
93
int NY = Integer.parseInt(s10);
94
95
g.drawString("N",x,y,0);
96
97
sx =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(75),MathFP.sin(Ma
thFP.sub(south,delta)))));
98
sy =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(75),MathFP.cos(Ma
thFP.sub(south,delta)))));
99
ix = sx.indexOf('.');
100
sx = sx.substring(0,ix);
101
iy = sy.indexOf('.');
102
sy = sy.substring(0,iy);
103
104
x = Integer.parseInt(sx);
105
y = Integer.parseInt(sy);
106
107
String s11 =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(smallestRadius),M
athFP.sin(MathFP.sub(south,delta)))));
108
ix = s11.indexOf('.');
109
s11 = s11.substring(0,ix);
110
int SX = Integer.parseInt(s11);
111
String s12 =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(smallestRadius),M
athFP.cos(MathFP.sub(south,delta)))));
112
iy = s12.indexOf('.');
113
s12 = s12.substring(0,iy);
114
int SY = Integer.parseInt(s12);
115
116
117
118
g.drawString("S",x,y,0);
119
int del = 0;
xiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


120
g.drawLine(NX-del,NY-del,SX-del,SY-del);
121
122
int mediumX = (int)Math.abs((NX-SX)/2);
123
int mediumY = (int)Math.abs((NY-SY)/2);
124
125
String s1 =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(10),MathFP.sin(Ma
thFP.sub(east,delta)))));
126
String s2 =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(10),MathFP.cos(Ma
thFP.sub(east,delta)))));
127
128
String s3 =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(10),MathFP.sin(Ma
thFP.sub(west,delta)))));
129
String s4 =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(10),MathFP.cos(Ma
thFP.sub(west,delta)))));
130
131
ix = s1.indexOf('.');
132
s1 = s1.substring(0,ix);
133
dummy1 = Integer.parseInt(s1);
134
135
ix = s2.indexOf('.');
136
s2 = s2.substring(0,ix);
137
dummy2 = Integer.parseInt(s2);
138
139
ix = s3.indexOf('.');
140
s3 = s3.substring(0,ix);
141
dummy3 = Integer.parseInt(s3);
142
143
ix = s4.indexOf('.');
144
s4 = s4.substring(0,ix);
145
dummy4 = Integer.parseInt(s4);
146
147
g.drawLine(NX-del,NY-del,dummy1,dummy2);
148
g.drawLine(dummy1,dummy2,SX-del,SY-del);
149
g.drawLine(NX-del,NY-del,dummy3,dummy4);
150
g.drawLine(dummy3,dummy4,SX-del,SY-del);
151
152
sx =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(75),MathFP.sin(Ma
thFP.sub(east,delta)))));
153
sy =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(75),MathFP.cos(Ma
thFP.sub(east,delta)))));
154
ix = sx.indexOf('.');
155
sx = sx.substring(0,ix);
156
iy = sy.indexOf('.');
157
sy = sy.substring(0,iy);
158
xv

Zarko Acimovic

159
x = Integer.parseInt(sx);
160
y = Integer.parseInt(sy);
161
162
g.drawString("E",x,y,0);
163
164
sx =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(75),MathFP.sin(Ma
thFP.sub(west,delta)))));
165
sy =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(75),MathFP.cos(Ma
thFP.sub(west,delta)))));
166
ix = sx.indexOf('.');
167
sx = sx.substring(0,ix);
168
iy = sy.indexOf('.');
169
sy = sy.substring(0,iy);
170
171
x = Integer.parseInt(sx);
172
y = Integer.parseInt(sy);
173
174
g.drawString("W",x,y,0);
175
176
177
178
179
gama = MathFP.sub(delta,gama);
180
//gama = MathFP.toFP("314");
181
long gamaDegrees =
Coordinates.radiansToDegrees(gama);
182
//long gamaDegrees = gama;
183
//System.out.println("gama="+MathFP.toString(gamaDegrees));
184
//gama = Coordinates.degreesToRadians(gama);
185
186
long corrX =
MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(smallestRadius),MathFP.sin(MathFP
.sub(destUp,gama))));
187
long corrY =
MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(smallestRadius),MathFP.cos(MathFP
.sub(destUp,gama))));
188
189
long dx = 0;
190
long dy = 0;
191
192
if(gamaDegrees<=0) {
193
gama =
MathFP.add(gama,Coordinates.MathFP_2PI);
194
gamaDegrees =
MathFP.add(gamaDegrees,MathFP.toFP("360"));
195
}
196
197
// Correction of position for imgDest
xvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


198
if(MathFP.toFP("0")<=gamaDegrees && gamaDegrees
<MathFP.toFP("10")){
199
dx = 0MathFP.mul(MathFP.toFP("10"),MathFP.cos(gama));
200
dy = 0MathFP.mul(MathFP.toFP("23"),MathFP.cos(gama));
201
}
202
203
204
if(MathFP.toFP("10")<=gamaDegrees && gamaDegrees
<MathFP.toFP("50")){
205
dx = 0MathFP.mul(MathFP.toFP("25"),MathFP.cos(gama));
206
dy = 0MathFP.mul(MathFP.toFP("23"),MathFP.cos(gama));
207
}
208
209
if(MathFP.toFP("50")<=gamaDegrees && gamaDegrees
<MathFP.toFP("67")){
210
dx = 0MathFP.mul(MathFP.toFP("40"),MathFP.cos(gama));
211
dy = 0MathFP.mul(MathFP.toFP("30"),MathFP.cos(gama));
212
}
213
214
if(MathFP.toFP("67")<=gamaDegrees && gamaDegrees
<MathFP.toFP("85")){
215
dx = 0MathFP.mul(MathFP.toFP("25"),MathFP.sin(gama));
216
dy = 0MathFP.mul(MathFP.toFP("12"),MathFP.sin(gama));
217
}
218
219
if(MathFP.toFP("85")<=gamaDegrees &&
gamaDegrees<MathFP.toFP("175")){
220
dx = 0MathFP.mul(MathFP.toFP("25"),MathFP.sin(gama));
221
dy = 0MathFP.mul(MathFP.toFP("12"),MathFP.sin(gama));
222
}
223
224
225
if(MathFP.toFP("175")<=gamaDegrees &&
gamaDegrees<MathFP.toFP("275")){
226
dx =
MathFP.mul(MathFP.toFP("7"),MathFP.cos(gama));
227
dy =
MathFP.mul(MathFP.toFP("7"),MathFP.sin(gama));
228
}
229

xvii

Zarko Acimovic

230
if(MathFP.toFP("275")<=gamaDegrees &&
gamaDegrees<=MathFP.toFP("360")){
231
dx = 0MathFP.mul(MathFP.toFP("8"),MathFP.cos(gama));
232
dy = 0MathFP.mul(MathFP.toFP("25"),MathFP.cos(gama));
233
234
}
235
236
237
238
239
long prevCorrX=corrX;
240
long prevCorrY=corrY;
241
242
corrX = MathFP.add(corrX,dx);
243
corrY = MathFP.add(corrY,dy);
244
245
246
247
sx = MathFP.toString(corrX);
248
sy = MathFP.toString(corrY);
249
ix = sx.indexOf('.');
250
sx = sx.substring(0,ix);
251
iy = sy.indexOf('.');
252
sy = sy.substring(0,iy);
253
int xbear1 = Integer.parseInt(sx);
254
int ybear1 = Integer.parseInt(sy);
255
256
257
sx = MathFP.toString(prevCorrX);
258
sy = MathFP.toString(prevCorrY);
259
ix = sx.indexOf('.');
260
sx = sx.substring(0,ix);
261
iy = sy.indexOf('.');
262
sy = sy.substring(0,iy);
263
int xbear3 = Integer.parseInt(sx);
264
int ybear3 = Integer.parseInt(sy);
265
266
267
268
sx =
MathFP.toString(MathFP.add(MathFP.toFP(93),MathFP.mul(MathFP.toFP(smallestRadius),M
athFP.sin(MathFP.sub(destDown,gama)))));
269
sy =
MathFP.toString(MathFP.sub(MathFP.toFP(85),MathFP.mul(MathFP.toFP(smallestRadius),M
athFP.cos(MathFP.sub(destDown,gama)))));
270
271
272
ix = sx.indexOf('.');
273
sx = sx.substring(0,ix);
xviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300

iy = sy.indexOf('.');
sy = sy.substring(0,iy);
int xbear2 = Integer.parseInt(sx);
int ybear2 = Integer.parseInt(sy);
g.drawLine(xbear2,ybear2,xbear3,ybear3);
g.drawImage(imgDest,xbear1,ybear1,0);
}
}
public void run(){
while(end == false){
delta = mob.getDirection();
gama = mob.getBearing();
repaint();
try{
Thread.sleep(100);
}catch(Exception e){}
}
}
public void setEnd(){
end = true;
}
}

xix

Zarko Acimovic
Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

xx

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

As you can see on above table, Coordinates class has problem with metrics LD and TCC. TCC or Tight Class
Cohesion Description: The Tight Class Cohesion metric measures the cohesion between the public methods of a
class. That is the relative number of directly connected public methods in the class. Classes having a low cohesion
indicate errors in the design. http://www.arisa.se/compendium/node118.html
Locality of Data. Description. The Locality of Data metric relates the amount of data being local the class to the
total amount of data used by the class. This relates to the quality of abstraction embodied by the class and allows
conclusions on the reuse potential of the class and testability. http://www.arisa.se/compendium/node112.html

Coordinates.java source code

1
2
3
4
5
6
7
8

/**
*
* Coordinates class different performs geographical calculations
*/

//import net.jscience.math.MathFP;

xxi

Zarko Acimovic

9 public class Coordinates {


10
/**
11
* Earth's radius (in meters)
12
*/
13
public static final long EARTH_RADIUS = MathFP.toFP(6367000);
14
public static final long EARTH_RADIUS2 = MathFP.toFP(6367000*2);
15
/**
16
* the WGS-84 latitude of a location
17
*/
18
private long latitude;
19
/**
20
* the WGS-84 longitude of a location
21
*/
22
private long longitude;
23
/**
24
* The altitude of the location in meters, defined as height above WGS-84
ellipsoid. Float.NaN can be used to indicate that the altitude is not known.
25
*/
26
27
28
/**
29
* Constructor
30
* @param
latitude
latitude as WGS-84 system coordinate
31
* @param
longitude
longitude as WGS-84 system coordinate
32
* @param
altitude
the altitude in meters, if known, or Float.NaN
33
* @param
timestamp
the time when information stored in this object
was created, in milliseconds since midnight January 1, 1970 GMT, or -1
34
* @param
source
the short string describing where data contained
in this object came from, like "GPS", "Network", "Database", etc
35
* @param
horizontalAccuracy
the horizontal accuracy of coordinates
in meters, or Float.NaN
36
* @param
verticalAccuracy
vertical accuracy of coordinates in
meters, or Float.NaN
37
*/
38
public Coordinates(long latitude, long longitude){
39
this.latitude=latitude;
40
this.longitude=longitude;
41
}
42
43
/**
44
* Copy constructor
45
* @param
original
copied object
46
*/
47
public Coordinates(Coordinates original){
48
this.latitude=original.latitude;
49
this.longitude=original.longitude;
50
}
51
52
53
/**
54
* The WGS-84 latitude of a location
xxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


55
* @return WGS-84 latitude
56
*/
57
public long getLatitude(){
58
return latitude;
59
}
60
61
/**
62
* The WGS-84 longitude of a location
63
* @return WGS-84 longitude
64
*/
65
public long getLongitude(){
66
return longitude;
67
}
68
69
70
/**
71
* Set latitude as WGS-84 system coordinate.
72
* @param latitude latitude as WGS-84 system coordinate
73
*/
74
public void setLatitude(long latitude){
75
this.latitude=latitude;
76
}
77
78
/**
79
* Set longitude as WGS-84 system coordinate.
80
* @param longitude longitude as WGS-84 system coordinate
81
*/
82
public void setLongitude(long longitude){
83
this.longitude=longitude;
84
}
85
86
/**
87
* Calculate bearing to another location on the surface of the Earth,
using the Great Circle.
88
* bearing - 1.way of behaving 2.connection 3.direction shown by
compass 4.understanding of one's position
89
* @param to another point
90
* @return long representing angle in degrees [0,360) between
corresponding meridian in first point and line on the Great Circle between those
points
91
*/
92
public long bearing(Coordinates to){
93
return bearing(getLatitude(), getLongitude(), to.getLatitude(),
to.getLongitude());
94
}
95
/**
96
* Calculate bearing between points (latFrom, lonFrom) and (latTo,lonTo)
on the surface of the Earth, using the Great Circle.
97
* @param latFrom latitude of the first point
98
* @param lonFrom longitude of the first point
99
* @param latTo latitude of the second point
xxiii

Zarko Acimovic

100
* @param lonTo longitude of the second point
101
* @return long representing angle in degrees [0,360) between
corresponding meridian in first point and line on the Great Circle between those
points
102
*/
103
protected static long bearing(long latFrom, long lonFrom, long latTo,
long lonTo){
104
//BMa: Some numeric with MathFP still happen - but error is mostly
below 16 degrees
105
// This should be fixed only if the final target device stays without
not have floats or doubles (e.g. it is not CLDC 1.1)
106
long bearing;
107
long deltaLat=latTo-latFrom;
108
long deltaLon=lonTo-lonFrom;
109
if (MathFP.abs(deltaLat)<MathFP_1 && MathFP.abs(deltaLon)<MathFP_1) {
110
// longiude and latitude distance within one deegre, could invent
better condition
111
//This approximation works better for smaller distances
112
latFrom = degreesToRadians(latFrom);
113
deltaLon=MathFP.mul(deltaLon, MathFP.cos(latFrom));
114
bearing = MathFP.atan2(deltaLat,deltaLon);
115
}else{
116
latFrom = degreesToRadians(latFrom);
117
latTo = degreesToRadians(latTo);
118
lonFrom = degreesToRadians(lonFrom);
119
lonTo = degreesToRadians(lonTo);
120
121
122
if (latFrom==latTo && lonFrom==lonTo)
123
return 0;
124
//if (MathFP.cos(latFrom) < Double.MIN_VALUE)
// Double.MIN_VALUE a
small number ~ machine precision, so here we check for +/-0
125
if (MathFP.cos(latFrom) == 0 )
// Double.MIN_VALUE a small number ~
machine precision, so here we check for +/-0
126
if (latFrom > 0)
127
return MathFP.PI;
// starting from N pole
128
else
129
return MathFP_2PI;
// starting from S pole
130
//double bearing = radiansToDegrees(Math.atan2(Math.sin(lon2lon1)*Math.cos(lat2),Math.cos(lat1)*Math.sin(lat2)Math.sin(lat1)*Math.cos(lat2)*Math.cos(lon2-lon1))%(2*Math.PI));
131
132
bearing = MathFP.atan2(
133
MathFP.mul(MathFP.sin(deltaLon),MathFP.cos(latTo)),
134
MathFP.mul(MathFP.cos(latFrom),MathFP.sin(latTo))135
MathFP.mul(MathFP.mul(MathFP.sin(latFrom),MathFP.cos(latTo)),MathFP.cos(deltaLon)))
;
136
}
137
bearing = MathFP.mod(radiansToDegrees(bearing), MathFP_360);
138
xxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


139
if (bearing<0) bearing = MathFP_360 + bearing;
140
return bearing;
141
}
142
143
/**
144
* Calculate distance to another location on the surface of the Earth,
using the Great Circle.
145
* @param to another point
146
* @return distance to another location in meters, using the line on the
Great Circle
147
*/
148
public long distance(Coordinates to){
149
//BMa: Some numeric with MathFP are still possible - errors happen
sometimes
150
// This should be fixed only if the final target device stays without
not have floats or doubles (e.g. it is not CLDC 1.1)
151
return calculateDistance(getLatitude(), getLongitude(),
to.getLatitude(), to.getLongitude());
152
}
153
154
/**
155
* Calculate distance between points (latFrom, lonFrom) and (latTo,lonTo)
on the surface of the Earth, using the Great Circle.
156
* lat , lon - degrees ([-90, +90]; [-180, +180])
157
*
158
* @param latFrom latitude of the first point
159
* @param lonFrom longitude of the first point
160
* @param latTo latitude of the second point
161
* @param lonTo longitude of the second point
162
* @return distance to another location in meters, using the line on the
Great Circle
163
*/
164
public static long calculateDistance(long latFrom, long lonFrom, long
latTo, long lonTo){
165
/*
166
* d=2*asin(sqrt((sin((latFrom-latTo)/2))^2 +
cos(latFrom)*cos(latTo)*(sin((lonFrom-lonTo)/2))^2))
167
* or
168
* d=2*asin(sqrt((sin((latFrom-latTo)/2))^2 +
cos(latFrom)*cos(latTo)*(sin((lonTo-lonFrom)/2))^2))
169
* distance = R*d
170
*/
171
172
latFrom = degreesToRadians(latFrom);
173
latTo = degreesToRadians(latTo);
174
lonFrom = degreesToRadians(lonFrom);
175
lonTo = degreesToRadians(lonTo);
176
//long distance = R * MathFP.acos(MathFP.sin(latFrom)*MathFP.sin(latTo)
+ MathFP.cos(latFrom)*MathFP.cos(latTo)*MathFP.cos(lonTo-lonFrom));
177
/*
178
double distance = R * 2 * Math.asin(
xxv

Zarko Acimovic

179
Math.sqrt(
180
Math.pow(Math.sin((lat1-lat2)/2), 2)
181
+
182
Math.cos(lat1)*Math.cos(lat2)*Math.pow(Math.sin((lon2-lon1)/2), 2)
183
)
184
);
185
*/
186
187 /*
188
System.out.print("latFrom: "+MathFP.toString(latFrom));
189
System.out.println(" lonFrom: "+MathFP.toString(lonFrom));
190
System.out.print("latTo: "+MathFP.toString(latTo));
191
System.out.println(" lonTo: "+MathFP.toString(lonTo));
192
*/
193
194
long p1=MathFP.sin(MathFP.div((latFrom-latTo), MathFP_2));
195
p1 = MathFP.mul(p1, MathFP.toFP(1000000));
196
//System.out.println(" p1: "+MathFP.toString(p1));
197
p1 = MathFP.mul(p1, p1);
198
//System.out.println(" p1: "+MathFP.toString(p1));
199
200
long p2=MathFP.sin(MathFP.div((lonTo-lonFrom), MathFP_2));
201
p2 = MathFP.mul(p2, MathFP.toFP(1000000));
202
//System.out.println(" p2: "+MathFP.toString(p2));
203
p2 = MathFP.mul(p2, p2);
204
//System.out.println(" p2: "+MathFP.toString(p2));
205
206
long sqrtarg=p1
+MathFP.mul(MathFP.mul(MathFP.cos(latFrom),MathFP.cos(latTo)),p2);
207
//System.out.println(" sqrtarg: "+MathFP.toString(sqrtarg));
208
209
sqrtarg=MathFP.sqrt(sqrtarg);
210
//System.out.println(" sqrtarg: "+MathFP.toString(sqrtarg));
211
212
long distance;
213
if (sqrtarg>MathFP.toFP(19000)) { //toFP("0.019")*1000000 - boundary
for MathFP.asin approximation by X
214
// calculation is erroneus for small angles
215
long asinarg=MathFP.div(sqrtarg, MathFP.toFP(1000000));
216
//System.out.println(" > asinarg: "+MathFP.toString(asinarg));
217
asinarg=MathFP.asin(asinarg);
218
//System.out.println(" > asinarg: "+MathFP.toString(asinarg));
219
distance = MathFP.mul(EARTH_RADIUS2, asinarg);
220
//System.out.println(" distance asin: "+MathFP.toString(distance));
221
} else {
222
//asin(X) is aproximately equall to X,
223
//This approximation allow us to change the order of multiplication
and division in order to reduce loss of significant digits
224
225
distance = MathFP.mul(EARTH_RADIUS2, sqrtarg);
xxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


226
//System.out.println(" > distance: "+MathFP.toString(distance));
227
distance=MathFP.div(distance, MathFP.toFP(1000000));
228
229
}
230
231
//System.out.println(" distance: "+MathFP.toString(distance));
232
233
//if (Double.isNaN(distance)) //equivalent to (distance=0), but safer
234
// return 0;
235
return distance;
236
}
237
238
239
/**
240
* Convert degrees to radians
241
* @return value transformed to radians
242
* @param
degrees
value to be transformed to radians
243
*/
244
public static long degreesToRadians(long degrees){
245
return MathFP.div(degrees,MathFP_180DivPI);
246
}
247
248
/**
249
* Convert radians to degrees
250
* @return value transformed to degrees
251
* @param
radians
value to be transformed to degrees
252
*/
253
public static long radiansToDegrees(long radians){
254
return MathFP.mul(radians,MathFP_180DivPI);
255
}
256
257
public static final long MathFP_2 = MathFP.toFP(2);
258
public static final long MathFP_1 = MathFP.toFP(1);
259
public static final long MathFP_2PI = MathFP.mul(MathFP_2, MathFP.PI);
260
public static final long MathFP_1000 = MathFP.toFP(1000);
261
public static final long MathFP_360 = MathFP.toFP(360);
262
public static final long MathFP_180DivPI = MathFP.div(MathFP.toFP(180),
MathFP.PI);
263
public static final long MathFP_0_5 = MathFP.toFP("0.5");
264
265
266 }

xxvii

Zarko Acimovic

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
xxviii

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

McCabe Cyclomatic Complexity (CC)


Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

xxix

Zarko Acimovic

DelRoute class seems to be perfect


DelRoute.java class source code
1 /**
2
*
3
* DelRoute is used when deleting route
4
*/
5 public class DelRoute {
6
int index;
7
int routeID;
8
DelRoute(int index, int routeID){
9
this.index = index;
10
this.routeID = routeID;
11
}
12
int getIndex(){
13
return index;
14
}
15
int getRouteID(){
16
return routeID;
17
}
18
19
public String toString(){
20
return "ID Route is "+routeID+"\n"+"Index of element to
delet is "+index;
21
}
22
23 }

xxx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

xxxi

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Efferent Coupling (Ce)


Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

Friend class has problem with Lack of Documentation. Lack Of Documentation Description. How many
comments are lacking in a class, considering one class comment and a comment per method as optimum.
Structure and content of the comments are ignored. http://www.arisa.se/compendium/node121.html

Friend.java source code

1
2
3
4
5
6
7
8
9
10

/**
*
* Friend class holds all important data for a friend
*/
public class Friend {
String name;
String resource;
int hashThread;
Thread4Friend t;

xxxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


11

Friend(String name, String resource, int hashThread, Thread4Friend

t){
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

this.name = name;
this.resource = resource;
this.hashThread = hashThread;
this.t = t;
}
public String getName(){
return name;
}
public String getResource(){
return resource;
}
public int getHash(){
return hashThread;
}
public void setID(int hash){
hashThread = hash;
}
public String toString(){
return "Friend is "+name+"\n"+"Hash is "+hashThread;
}
public void setFirst(){
t.setFirst();
}
public boolean getThread(){
if (t==null){ return false; }
else {return true; }
}
public void setThread(Thread4Friend t){
this.t = t;
}
}

xxxiii

Zarko Acimovic

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
xxxiv

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

Weighted Method Count (WMC)


Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

xxxv

Zarko Acimovic

HeapSorter class has problem with LD, TCC and LOD: Lack Of Documentation Description. How many
comments are lacking in a class, considering one class comment and a comment per method as optimum.
Structure and content of the comments are ignored. http://www.arisa.se/compendium/node121.html
Tight Class Cohesion Description
The Tight Class Cohesion metric measures the cohesion between the public methods of a class. That is the
relative number of directly connected public methods in the class. Classes having a low cohesion indicate errors
in the design. http://www.arisa.se/compendium/node118.html
HeapSorter.java source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

/**
*
* HeapSorter class sorts points by distance or by name
*/
public class HeapSorter{
HeapSorter(){}
public void heapsort(long[] a){
long[]A = setHeapWithSize(a,a.length);
buildHeap(A);
for(int i=0; i<A.length; i++){
System.out.println(A[i]);
}
for(int i=a.length; i>1; i--){
a[i-1]=A[0]; A[0]=A[i-1];
A=setHeapWithSize(A,A.length-1);
heapify(A,1);
}
a[0]=A[0];
}
public void heapsort(String[] as){
String[] AS = setHeapWithSize(as,as.length);
buildHeap(AS);
for(int i=0; i<AS.length; i++){
System.out.println(AS[i]);
}
for(int i=as.length; i>1; i--){
as[i-1]=AS[0]; AS[0]=AS[i-1];
AS=setHeapWithSize(AS,AS.length-1);
heapify(AS,1);
}
as[0]=AS[0];
xxxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
1]=tmp;
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
1].charAt(0)){
79
80
81
82
83

}
public void buildHeap(long[] a){
for(int i=a.length/2; i>0; i--) heapify(a,i);
}
public void buildHeap(String[] as){
for(int i=as.length/2; i>0; i--) heapify(as,i);
}
public void
int
int
int

heapify(long[]a, int i){


l=left(i);
r=right(i);
largest;

if(l<=heapSize(a) && a[l-1]>a[i-1]){


largest=l;
}else{
largest=i;
}
if(r<=heapSize(a) && a[r-1]>a[largest-1]){
largest=r;
}
if(largest!=i){
//exchange a[i], a[largest]
long tmp=a[i-1]; a[i-1]=a[largest-1]; a[largestheapify(a,largest);
}
}
public void
int
int
int

heapify(String[]as, int i){


l=left(i);
r=right(i);
largest;

if(l<=heapSize(as) && as[l-1].charAt(0)>as[i-1].charAt(0)){


largest=l;
}else{
largest=i;
}
if(r<=heapSize(as) && as[r-1].charAt(0)>as[largestlargest=r;
}
if(largest!=i){
//exchange a[i], a[largest]
xxxvii

Zarko Acimovic

84
as[largest-1]=tmpS;
85
86
87
}
88
89
90
public
91
92
}
93
94
public
95
96
}
97
98
public
99
100
}
101
102
public
103
104
}
105
106
public
107
108
}
109
110
public
111
112
113
114
115
116
}
117
118
public
119
120
121
122
123
124
}
125 };

String tmpS=as[i-1]; as[i-1]=as[largest-1];


heapify(as,largest);
}

int heapSize(long a[]){


return a.length;

int heapSize(String as[]){


return as.length;

int parent(int i){


return(i/2);

int left(int i){


return(2*i);

int right(int i){


return(2*i+1);

long[] setHeapWithSize(long[]m , int n){


long[] k = new long[n];
for(int i=0; i<n; i++){
k[i]=m[i];
}
return k;

String[] setHeapWithSize(String[]m , int n){


String[] k = new String[n];
for(int i=0; i<n; i++){
k[i]=m[i];
}
return k;

xxxviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

xxxix

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Efferent Coupling (Ce)


Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

ImageCnavas3 lacks documentation. Lack Of Documentation Description. How many comments are lacking in a
class, considering one class comment and a comment per method as optimum. Structure and content of the
comments are ignored. http://www.arisa.se/compendium/node121.html
ImageCanvas3.java source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14

/**
*
* ImageCanvas3 draws elements on screen and captures events on canvas
*/
//import java.io.IOException;
import javax.microedition.lcdui.*;
//import java.util.*;
public class ImageCanvas3 extends Canvas {
Outlook ol;
ImageCanvas3(Outlook ol){
xl

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61

this.ol =ol;
ol.setCanvasWH(this.getWidth(),this.getHeight());
}
public void paint(Graphics g) {
ol.drawOutlook(g);
}
public void keyPressed (int keyCode){
//keyCode+=disabler;
if(keyCode==49){
ol.ZoomIn();
repaint();
}
if(keyCode==50){
ol.ZoomOut();
repaint();
}
if(keyCode==51){
repaint();
}

switch (getGameAction(keyCode)) {
case Canvas.UP:
ol.setMap('u');
repaint();
break;
case Canvas.DOWN:
ol.setMap('d');
repaint();
break;
case Canvas.LEFT:
ol.setMap('l');
repaint();
break;
case Canvas.RIGHT:
ol.setMap('r');
repaint();
break;
}
}
}

xli

Zarko Acimovic

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
xlii

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

Weighted Method Count (WMC)


Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

MapBackground class seems to be well designed class.

xliii

Zarko Acimovic

MapBacground.java source code

1 /**
2
*
3
* MapBackground transforms map according to user actions, zoom In, zoom
out or pan
4
*/
5 import java.util.*;
6 import java.io.*;
7 import javax.microedition.lcdui.*;
8
9
10 public class MapBackground {
11
12
/** Current JPEG Background of map
13
*/
14
private Image img;
15
16
/** Images for Different Zoom Levels;
17
*/
18
private Image[] zoomImg = new Image[3];
19
20
private int zoomLevel = 0;
21
22
/** Width of current background image
23
*/
24
private long sizeX;
25
26
/** Height of current background image
27
*/
28
private long sizeY;
29
30
31
/** Float-point value of upper limit
32
*/
33
private long upLat;
34
35
/** Float-point value of lower limit
36
*/
37
private long downLat;
38
39
/** Side of upper limit
40
*/
41
//private char upNS;
42
43
/** Side of lower limit
44
*/

xliv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

//private char downNS;


/** Float-point value of left limit
*/
private long leftLon;
/** Float-point value of right limit
*/
private long rightLon;
/** Side of left limit
*/
//private char leftWE;
/** Side of right limit
*/
///private char rightWE;
/** Integer value of latitude degrees of upper limit
*/
private long upDlat;
/** Integer value of latitude minutes of upper limit
*/
private long upMlat;
/** Integer value of latitude seconds of upper limit
*/
private long upSlat;
/** Integer value of latitude degrees of lower limit
*/
private long dwDlat;
/** Integer value of latitude minutes of lower limit
*/
private long dwMlat;
/** Integer value of latitude seconds of upper limit
*/
private long dwSlat;

/** Integer value of longitude degrees of left limit


*/
private long lfDlon;
/** Integer value of longitude minutes of left limit
*/
private long lfMlon;

xlv

Zarko Acimovic

96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146

/** Integer value of longitude seconds of left limit


*/
private long lfSlon;
/** Integer value of longitude degrees of right limit
*/
private long rtDlon;
/** Integer value of longitude minutes of right limit
*/
private long rtMlon;
/** Integer value of longitude seconds of right limit
*/
private long rtSlon;

/** Scale of map


*/
private long scale;
/** Number of lat-seconds per pixel
*/
private long pixLat;
/** Number of lon-seconds per pixel
*/
private long pixLon;

/** Total number of Latitude seconds for upper limit point


*/
long totLatSec ;
/** Total number of Longitude seconds for left limit point
*/
long totLonSec ;
/** new upper left edge due to pan or Zoom;
* newEdge represents Point of upper left corner of visible screen
*/
Point newEdge;
/** new upper left edge due to pan or Zoom;
* newEdge represents Point of upper left corner of visible screen
*/
Point previousEdge;

/** World coordinates of Down end of Image


*/
xlvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197

Point downEnd;
/** Character that represents side of Pan
*/
char sidePan;
/** x-coordinate of begining of image
*/
long x = 0;
/** y-coordinate of begining of image
*/
long y = 0;
/** Indicates beginning of pan range verticaly
*/
boolean reachBeginV = true;
/** Indicates end of pan range verticaly
*/
boolean reachEndV = false;
/** Indicates beginning of pan range horizontaly
*/
boolean reachBeginH = true;
/** Indicates end of pan range horizontaly
*/
boolean reachEndH = false;
/** Step of panning
*/
long step = 30;
/** Counter of shifts vertically
*/
long movV=0;
/** Counter of shifts horizontally
*/
long movH=0;
/** Name of smallest image
*/
String[] imgArray = new String[3];
/** Canvas Height
*/
private long canvasHeight;
/** Canvas Width
xlvii

Zarko Acimovic

198
*/
199
private long canvasWidth;
200
201
202
long previousPixLat;
203
long previousPixLon;
204
205
long minX;
206
long minY;
207
208
boolean param = false;
209
210
211
MapBackground( String name0, String name1, String name2,
212
String latStr1,
213
String lonStr1,
214
String latStr2,
215
String lonStr2 ) {
216
if(MathFP.toFP(latStr1)>MathFP.toFP(latStr2)){
217
this.upLat
= MathFP.toFP(latStr1);
218
this.downLat = MathFP.toFP(latStr2);
219
} else {
220
this.upLat
= MathFP.toFP(latStr2);
221
this.downLat = MathFP.toFP(latStr1);
222
}
223
224
if(MathFP.toFP(lonStr1)>MathFP.toFP(lonStr2)){
225
this.leftLon = MathFP.toFP(lonStr2);
226
this.rightLon = MathFP.toFP(lonStr1);
227
} else {
228
this.leftLon
= MathFP.toFP(lonStr1);
229
this.rightLon = MathFP.toFP(lonStr2);
230
}
231
232
233
imgArray[0] = name0;
234
imgArray[1] = name1;
235
imgArray[2] = name2;
236
237
try {
238
zoomImg[0] = Image.createImage(imgArray[0]);
239
} catch (IOException e) {}
240
241
img = zoomImg[0];
242
sizeX = img.getWidth();
243
sizeY = img.getHeight();
244
245
newEdge = new
Point(MathFP.toString(upLat),MathFP.toString(leftLon),"newEdge","","blanco",false);
246

xlviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


247
downEnd = new
Point(MathFP.toString(downLat),MathFP.toString(rightLon),"downEnd","","blanco",fals
e);
248
249
this.totLatSec =
MathFP.mul(this.upLat,MathFP.toFP("3600"));
250
this.totLonSec =
MathFP.mul(this.leftLon,MathFP.toFP("3600"));
251
252
253
this.setPixels();
254
}
255
256
257
258
/** Returns number of longitude seconds per pixel
259
* @return int
260
*
261
*/
262
public long getPixLon(){
263
return pixLon;
264
}
265
266
/** Returns number of latitude seconds per pixel
267
* @return int
268
*/
269
public long getPixLat(){
270
return pixLat;
271
}
272
273
/** Sets pixels as Float-Point when main constructor is called
274
* and when Zoom In/Out is applied
275
*/
276
public void setPixels(){
277
long pxy1 =
MathFP.mul(MathFP.sub(rightLon,leftLon),MathFP.toFP("3600"));
278
pixLon = MathFP.div(pxy1,MathFP.toFP(sizeX));
279
280
long pxy2 =
MathFP.mul(MathFP.sub(upLat,downLat),MathFP.toFP("3600"));
281
pixLat = MathFP.div(pxy2,MathFP.toFP(sizeY));
282
}
283
284
/** Returns image to draw
285
*
286
* @return Image
287
*/
288
public Image getImage(){
289
return img;
290
}
291
xlix

Zarko Acimovic

292
293
/** Returns total number of seconds for LEFT LONGITUDE
294
* @return int
295
*/
296
public long getLonSec() {
297
return this.totLonSec;
298
}
299
300
/** Returns total number of seconds for UPPER LATITUDE
301
* @return int
302
*/
303
public long getLatSec() {
304
return this.totLatSec;
305
}
306
307
308
/** Returns Canvas height
309
*
310
* @return int
311
*/
312
public long getCanvasHeight(){
313
return canvasHeight;
314
}
315
316
/** Returns Canvas width
317
*
318
* @return int
319
*/
320
public long getCanvasWidth(){
321
return canvasWidth;
322
}
323
324
/** Sets newEdge; new Edge is created every time when user pans or zooms
map ;
325
* newEdge represents Point of upper left corner of visible screen (x=0
and
326
* y=0 for newEdge)
327
*
328
* @return Point
329
*/
330
public void setNewEdge(){
331
previousEdge = newEdge;
332
333
long tt1 =
MathFP.mul(this.getPixLat(),MathFP.toFP(Math.abs(this.getY())));
334
long tt2 =
MathFP.mul(this.getPixLon(),MathFP.toFP(Math.abs(this.getX())));
335
336
newEdge = new Point(MathFP.sub(this.getLatSec(),tt1),
337
MathFP.add(this.getLonSec(),tt2),"","",false);
l

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388

}
/** Returns new edge
*/
public Point getNewEdge(){
return newEdge;
}
/** Returns down End
*/
public Point getDownEnd(){
return downEnd;
}
/** Returns new Edge as String
*
* @return String
*/
public String getNEdgeStr(){
return newEdge.toString();
}

/** Sets map due to Pan transformation


*
*/
public void setMap(char side){
if (side=='u'){
if(reachBeginV==false){
y+=((this.img.getHeight() - canvasHeight)/step);
if(y>0) y=0;
movV--;
}
reachEndV=false;
if(movV==0) reachBeginV=true;
}
if (side=='d'){
if(reachEndV==false){
y-=((this.img.getHeight()-canvasHeight)/step);
movV++;
reachBeginV=false;
if(movV==step) reachEndV=true;
}
}
if (side=='l'){
if(reachBeginH==false){
li

Zarko Acimovic

389
x+=((this.img.getWidth()-canvasWidth)/step);
390
if(x>0) x=0;
391
movH--;
392
reachEndH=false;
393
if(movH==0) reachBeginH=true;
394
}
395
396
}
397
398
if (side=='r'){
399
if(reachEndH==false) {
400
x-=((this.img.getWidth()-canvasWidth)/step);
401
movH++;
402
reachBeginH=false;
403
if(movH==step) reachEndH=true;
404
405
}
406
}
407
408
this.setNewEdge();
409
410
}
411
412
413
/** returns x-coordinate of begining of Image
414
*/
415
public long getX(){
416
return x;
417
}
418
419
/** returns y-coordinate of begining of Image
420
*/
421
public long getY(){
422
return y;
423
}
424
425
/** Zoom In
426
*/
427
public boolean ZoomIn(){
428
boolean zoom = false;
429
if(zoomLevel<2){
430
zoom = true;
431
this.setPreviousEdge();
432
433
zoomLevel++;
434
if (zoomImg[zoomLevel]==null){
435
try{
436
zoomImg[zoomLevel] =
Image.createImage(imgArray[zoomLevel]);
437
} catch(Exception e){}
438
}
lii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489

this.img = zoomImg[zoomLevel];
this.sizeX = this.img.getWidth();
this.sizeY = this.img.getHeight();
this.setPixels();
x=0-(((this.img.getWidth()-canvasWidth)/step)*movH);
y=0-(((this.img.getHeight()-canvasHeight)/step)*movV);
this.setNewEdge();
}
return zoom;
}
/** Zoom Out
*/
public boolean ZoomOut(){
boolean zoom = false;
if(zoomLevel>0){
zoom = true;
this.setPreviousEdge();
zoomLevel--;
this.img = zoomImg[zoomLevel];
this.sizeX = this.img.getWidth();
this.sizeY = this.img.getHeight();
this.setPixels();
x=0-(((this.img.getWidth()-canvasWidth)/step)*movH);
y=0-(((this.img.getHeight()-canvasHeight)/step)*movV);
this.setNewEdge();
}
return zoom;
}

/** Increments Pan level


*/
public void incPan(Vector v){
if (step<10) step++;
}
/** Decrements Pan level
*/
public void decPan(Vector v){
if (step>3) step--;
}
/** Draws Layout
*/
liii

Zarko Acimovic

490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540

public void drawMapBackground(Graphics g){


Long lx = new Long(x);
Long ly = new Long(y);
int xx = Integer.parseInt(lx.toString());
int yy = Integer.parseInt(ly.toString());
g.drawImage(img,xx,yy,0);
}
/** Set Canvas width and height
*/
public void setCanvasWH(int canvasWidth, int canvasHeight){
this.canvasWidth = (long)canvasWidth;
this.canvasHeight = (long)canvasHeight;
}
public Point getPreviousEdge(){
return previousEdge;
}
public void setPreviousEdge(){
previousEdge = newEdge;
previousPixLat = pixLat;
previousPixLon = pixLon;
}
public long getPreviousPixLat(){
return previousPixLat;
}
public long getPreviousPixLon(){
return previousPixLon;
}
public long getZoomLevel(){
return zoomLevel;
}
public long imageHeight(){
return (long)img.getHeight();
}
public long imageWidth(){
return (long)img.getWidth();
}
public long getStep(){
return step;
}

liv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


541
542
/** Sets Background for selected Point
543
* Used in SelectorPoint.selectWP
544
*/
545
public void setBackground(Point ww){
546
547
long imgWidth = (long) this.img.getWidth();
548
long imgHeight= (long) this.img.getHeight();
549
minX = -Math.abs(imgWidth-canvasWidth);
550
minY = -Math.abs(imgHeight-canvasHeight);
551
552
long difLat = MathFP.div(Math.abs(ww.getLatSec()this.getLatSec()),pixLat); //x pixel of ww
553
long difLon = MathFP.div(Math.abs(ww.getLonSec()this.getLonSec()),pixLon); //y pixel of ww
554
long p1 = MathFP.div(difLat,MathFP.div((this.img.getHeight()canvasHeight),step));
555
long p2 = MathFP.div(difLon,MathFP.div((this.img.getWidth()canvasWidth),step));
556
557
p1 = MathFP.toLong(p1);
558
p2 = MathFP.toLong(p2);
559
p1--;
560
p2--;
561
562
563
564
p1*=((this.img.getHeight()-canvasHeight)/step);
565
p2*=((this.img.getWidth()-canvasWidth)/step);
566
567
/**
568
if(param==true) {
569
p1 -=((this.img.getHeight()-canvasHeight)/step);
570
p2-=((this.img.getWidth()-canvasWidth)/step);
571
572
p1 -=((this.img.getHeight()-canvasHeight)/step);
573
p2-=((this.img.getWidth()-canvasWidth)/step);
574
p2-=((this.img.getWidth()-canvasWidth)/step);
575
}*/
576
577
578
this.x = 0 - p2; // x value of screen begining
579
this.y = 0 - p1; // y value of screen begining
580
581
582
583
movV = p1/((this.img.getHeight()-canvasHeight)/step);
584
movH = p2/((this.img.getWidth()-canvasWidth)/step);
585
586
if(x<minX){
587
x=minX;
lv

Zarko Acimovic

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626

movH=step;
}
if(y<minY){
y=minY;
movV=step;
}
if(x>0) x=0;
if(y>0) y=0;
if(movV<0) movV=0;
if(movH<0) movH=0;
if
if
if
if

(movV==step) {reachEndV=true;} else {reachEndV=false;}


(movV==0) {reachBeginV=true;} else {reachBeginV=false;}
(movH==step) {reachEndH=true;} else {reachEndH=false;}
(movH==0) {reachBeginH=true;} else {reachBeginH=false;}

this.setNewEdge();

}
/**
public void stela(long p1,long p2){
p1 -=((this.img.getHeight()-canvasHeight)/step);
p2+=((this.img.getWidth()-canvasWidth)/step);
p1 -=((this.img.getHeight()-canvasHeight)/step);
p2+=((this.img.getWidth()-canvasWidth)/step);
p2+=((this.img.getWidth()-canvasWidth)/step);
p2+=((this.img.getWidth()-canvasWidth)/step);
}*/

lvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

lvii

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Efferent Coupling (Ce)


Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

Problem with MapBackgroundFactory is Length of class name (LEN).


MapBackgroundFactory.java source code

1 /**
2
*
3
* Different map formats could be implemented and dealt with with
MapBackgroundFactory
4
*/
5 public class MapBackgroundFactory {
6
7
MapBackground m;
8
9
/**
10
MapBackgroundFactory(String name0, String name1, String name2,
lviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


11
int dLat1, int mLat1, int
sLat1, char sdNS1,
12
int dLon1, int mLon1, int
sLon1, char sdWE1,
13
int dLat2, int mLat2, int sLat2, char sdNS2,
14
int dLon2, int mLon2, int sLon2, char sdWE2,
int scale){
15
16
//m = new MapBackground(name0,name1,name2,
17
dLat1,mLat1,sLat1,sdNS1,dLon1,mLon1,sLon1,sdWE1,
18
dLat2,mLat2,sLat2,sdNS2,dLon2,mLon2,sLon2,sdWE2,
scale);
19
}*/
20
21
MapBackgroundFactory(String name0, String name1, String name2,
22
String lat1, String lon1, String
lat2, String lon2){
23
m = new MapBackground(name0,name1,name2,
24
lat1,lon1,lat2,lon2);
25
}
26
27
28
public MapBackground getMapBackground(){
29
return m;
30
}
31
32 }

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size

lix

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Lines of Code (LOC)


Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

lx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

MapObjects seem to be well designed class.


MapObjects.java source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

/**
*
* MapObjects controls appearance of all map objects on current screen
*/
import java.util.*;
//import java.io.*;
import javax.microedition.lcdui.*;
public class MapObjects {
MapBackground mb;
Point currentPosition;
Point previousPosition;
Point destinationPosition;
PVector freeWaypoints;
Vector routes;
PVector currentRoute;
Vector drawablePoints;
Hashtable friends;
boolean drawLine = false;
boolean destSet = false;
boolean currentSet = false;

MapObjects(MapBackground mb){
this.mb = mb;
currentPosition = mb.getNewEdge();
destinationPosition = mb.getNewEdge();
currentPosition.setName("dummy");
destinationPosition.setName("dummy");
routes = new Vector();
friends = new Hashtable();
lxi

Zarko Acimovic

34
}
35
36
/** Sets drawable Points for current Screen
37
*
38
*/
39
public void setDrawablePoints(){
40
Vector temp1 = new Vector();
41
Vector temp2;
42
43
//check if current and destination are visible
44
if(this.currentPosition.check(mb.getNewEdge(), mb.getDownEnd())) {
45
currentPosition.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
46
temp1.addElement(currentPosition);
47
}
48
if(this.destinationPosition.check(mb.getNewEdge(),
mb.getDownEnd())) {
49
destinationPosition.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
50
temp1.addElement(destinationPosition);
51
}
52
53
//check which free waypoints are visible
54
temp2 = freeWaypoints.getPoints(mb.getNewEdge(),mb.getDownEnd());
55
for (int j=0; j<temp2.size(); j++){
56
Point wp = (Point)temp2.elementAt(j);
57
wp.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
58
temp1.addElement(wp);
59
}
60
61
62
//check which route points are visible
63
for (int i=0; i<routes.size(); i++){
64
PVector v = (PVector)routes.elementAt(i);
65
if (v.getVisible()==true){
66
temp2 =
v.getPoints(mb.getNewEdge(),mb.getDownEnd());
67
68
for (int j=0; j<temp2.size(); j++){
69
Point wp = (Point)temp2.elementAt(j);
70
wp.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
71
temp1.addElement(wp);
72
}
73
}
74
}
75
drawablePoints = temp1;
76
}
77
78
/** Returns drawable Points for current Screen
79
* @return Vector
lxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


80
*/
81
public Vector getDrawablePointsOld(){
82
83
return drawablePoints;
84
}
85
86
public Vector getDrawablePoints(){
87
this.setDrawablePoints();
88
return drawablePoints;
89
}
90
91
92
public void setCurrentPosition(Point wp){
93
previousPosition = currentPosition;
94
currentPosition = wp;
95
currentPosition.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
96
currentSet = true;
97
}
98
99
/** Reset current position
100
*/
101
public void resetCurrentPosition(){
102
currentPosition = mb.getNewEdge();
103
drawLine = false;
104
currentSet = false;
105
}
106
107
/** Returns current position
108
* @return Point
109
*/
110
public Point getCurrentPosition(){
111
return currentPosition;
112
}
113
114
115
/** Set destination position
116
*/
117
public void setDestinationPosition(Point wp){
118
destinationPosition = wp;
119
destSet = true;
120
}
121
122
/** Reset destination position
123
*/
124
public void resetDestinationPosition(){
125
destinationPosition = mb.getNewEdge();
126
drawLine = false;
127
destSet = false;
128
}
129
lxiii

Zarko Acimovic

130
/** Returns destination position
131
* @return Point
132
*/
133
public Point getDestinationPosition(){
134
return destinationPosition;
135
}
136
137
/** Returns all routes
138
*/
139
public Vector getRoutes(){
140
return routes;
141
}
142
143
/** Returns free Vector of free Points
144
*/
145
public PVector getFreeWaypoints(){
146
return freeWaypoints;
147
}
148
149
/** Draws MapObjects --- OBSOLETED!!!
150
*/
151
public void drawMOBold(Graphics g, boolean route){
152
long zl = mb.getZoomLevel()+1;
153
Long zzl = new Long(zl);
154
int zoomL = Integer.parseInt(zzl.toString());
155
this.setDrawablePoints();
156
157
// Drawing of line beetwen destination and current position
158
if(drawLine==true){
159
currentPosition.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
160
destinationPosition.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
161
g.drawLine(currentPosition.getXX(),currentPosition.getYY(),destinationPosition.getX
X(),destinationPosition.getYY());
162
}
163
164
// Drawing of free Points, current position and destination
position
165
for(int i=0; i<drawablePoints.size(); i++){
166
Point wp = (Point)drawablePoints.elementAt(i);
167
if(wp.getImage().equals("blanco")){
168
g.fillRect(wp.getXX(),wp.getYY(),5*zoomL,5*zoomL);
169
g.drawString(wp.getName(),wp.getXX()+5,wp.getYY()
+5,0);
170
} else {
171
Image img = null;
172
try{
173
img =
Image.createImage(wp.getImage());
lxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


174
}catch(Exception e){}
175
g.drawImage(img,wp.getXX(),wp.getYY(),0);
176
}
177
178
}
179
180
// Drawing of route
181
if(route==true){
182
for(int i=0; i<routes.size(); i++){
183
PVector wpv = (PVector)routes.elementAt(i);
184
if(wpv.getVisible()==true){
185
for(int j=0; j<wpv.size()-1; j++){
186
Point wp1 = (Point)
wpv.elementAt(j);
187
Point wp2 = (Point)
wpv.elementAt(j+1);
188
wp1.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
189
wp2.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
190
g.drawLine(wp1.getXX(),wp1.getYY(),wp2.getXX(),wp2.getYY());
191
}
192
}
193
}
194
}
195
}
196
197
/** Draws MapObjects
198
*/
199
public void drawMOB(Graphics g, boolean route){
200
g.setColor(0,0,0);
201
202
freeWaypoints.drawVector(g,false,mb.getNewEdge(),mb.getPixLon(),mb.getPixLat(),mb.g
etZoomLevel());
203
204
if(friends.size()!=0)
this.getFriends().drawVector(g,false,mb.getNewEdge(),mb.getPixLon(),mb.getPixLat(),
0);
205
206
if(route==true){
207
for (int i =0; i<routes.size(); i++){
208
PVector wpv = (PVector)routes.elementAt(i);
209
wpv.drawVector(g,route,mb.getNewEdge(),mb.getPixLon(),mb.getPixLat(),mb.getZoomLeve
l());
210
}
211
}
212
213
if(currentSet) {
lxv

Zarko Acimovic

214
currentPosition.drawPoint(g,mb.getNewEdge(),mb.getPixLat(),mb.getPixLon(),mb.getZoo
mLevel());
215
216
}
217
if(destSet)
destinationPosition.drawPoint(g,mb.getNewEdge(),mb.getPixLat(),mb.getPixLon(),mb.ge
tZoomLevel());
218
if(currentSet && destSet)
g.drawLine(currentPosition.getXX(),currentPosition.getYY(),destinationPosition.getX
X(),destinationPosition.getYY());
219
}
220
221
222
223
224
/** Adds free Point
225
*/
226
public void addFreeWaypoint(Point wp){
227
this.freeWaypoints.addElement(wp);
228
}
229
230
/** Adds new route
231
*/
232
public void addRoute(PVector v){
233
this.routes.addElement(v);
234
}
235
236
/** Adds new Point to route with routeID on position pos
237
*/
238
public void addWP2Route(Point wp, int routeID, int pos) {
239
PVector route;
240
for (int i=0; i<routes.size(); i++){
241
route = (PVector)routes.elementAt(i);
242
if(route.getID()==routeID){
243
route.insertElementAt(wp,pos);
244
i=1000;
245
}
246
}
247
}
248
249
/** Sets free waypoints vector
250
*/
251
public void setFreeWaypointsV(PVector wpv){
252
this.freeWaypoints = wpv;
253
}
254
255
/** Measure distance
256
*/
257
public long measureDistance(Point wp){
258
if (currentPosition.equals(mb.getNewEdge())) {
lxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309

return -1;
} else {
return currentPosition.measureDistance(wp);
}
}
public boolean currentSet(){
return currentSet;
}
public boolean destSet(){
return destSet;
}

public void removeRoute(PVector wr){


routes.removeElement(wr);
}
public void removeRoute(String s){
for(int i=0; i<routes.size(); i++){
PVector rt = (PVector)routes.elementAt(i);
if (rt.getName()==s) {
routes.removeElementAt(i);
i=1000;
}
}
}
public long getDirection(){
long
long
long
long
long

direction = 0;
latP = previousPosition.getLat();
lonP = previousPosition.getLon();
latC = currentPosition.getLat();
lonC = currentPosition.getLon();

if(latC>latP && lonP==lonC) direction = MathFP.toFP("0");


if(latC>latP && lonC>lonP) direction = MathFP.toFP("45");
if(latP==latC && lonC>lonP) direction = MathFP.toFP("90");
if(latC<latP && lonC>lonP) direction = MathFP.toFP("135");
if(latC<latP && lonP==lonC) direction = MathFP.toFP("180");
if(latC<latP && lonC<lonP) direction = MathFP.toFP("225");
if(latP==latC && lonC<lonP) direction = MathFP.toFP("270");
if(latC>latP && lonC<lonP) direction = MathFP.toFP("315");
direction = Coordinates.degreesToRadians(direction);
return direction;
}
/** This is not working well
lxvii

Zarko Acimovic

310
*/
311
public long getBearing(){
312
313
long bearing = 0;
314
long latP = previousPosition.getLat();
315
long lonP = previousPosition.getLon();
316
long latD = destinationPosition.getLat();
317
long lonD = destinationPosition.getLon();
318
319
320
//if(latD>latP && lonD==lonP) bearing = MathFP.toFP("0");
321
if( latD>latP && MathFP.abs(MathFP.sub(lonD,lonP))<MathFP.toFP("5")
) bearing = MathFP.toFP("0");
322
if(latD>latP && lonD>lonP) bearing = MathFP.toFP("45");
323
//if(latD==latP && lonD>lonP) bearing = MathFP.toFP("90");
324
if(MathFP.abs(MathFP.sub(latD,latP))<MathFP.toFP("5") && lonD>lonP)
bearing = MathFP.toFP("90");
325
if(latD<latP && lonD>lonP) bearing = MathFP.toFP("135");
326
//if(latD<latP && lonP==lonD) bearing = MathFP.toFP("180");
327
if(latD<latP &&
MathFP.abs(MathFP.sub(lonD,lonP))<MathFP.toFP("5") ) bearing = MathFP.toFP("180");
328
if(latD<latP && lonD<lonP) bearing = MathFP.toFP("225");
329
//if(latP==latD && lonD<lonP) bearing = MathFP.toFP("270");
330
if(MathFP.abs(MathFP.sub(latD,latP))<MathFP.toFP("5") && lonD<lonP)
bearing = MathFP.toFP("270");
331
if(latD>latP && lonD<lonP) bearing = MathFP.toFP("315");
332
333
334
bearing = Coordinates.degreesToRadians(bearing);
335
return bearing;
336
337
}
338
339
340
public void addNewFriend(int friendID){
341
Point dummy = new Point(currentPosition,false);
342
Integer frID = new Integer(friendID);
343
friends.put(frID,dummy);
344
}
345
346
public void updateFriend(Integer friendID,Point p){
347
friends.put(friendID,p);
348
}
349
350
public void deleteFriend(int friendID){
351
Integer frID = new Integer(friendID);
352
friends.remove(frID);
353
System.out.println(friends);
354
}
355
356
public void deleteAllFriends(){
lxviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378

//System.out.println("YIPI YAAA YEEEEE");


friends.clear();
//System.out.println(friends);
}

/** Conversion of hashtable into vector


*/
public PVector getFriends(){
Vector v = new Vector();
Enumeration e = friends.elements();
while(e.hasMoreElements()){
v.addElement((Point)e.nextElement());
}
PVector PFriends = new PVector(v,false);
return PFriends;
}

lxix

Zarko Acimovic
Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

lxx

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

MapsMIDlet class has problem with Lines of Code.


Lines of Code Description: Lines of code simply counts the lines of source code (line break characters) of a
certain software entity. It is a simple yet powerful metric to assess the complexity of software entities. Since it is
depending on code conventions and format, it is critical to use it in generated codes since it may lack of line
breaks. Additionally it can only be measured in the source code itself from the front-end and is therefore a frontend side metric. http://www.arisa.se/compendium/node91.html
Response For a Class Description
Count of (public) methods in a class and methods directly called by these. RFCis only applicable to objectoriented systems. http://www.arisa.se/compendium/node98.html
Message Passing Coupling Description
The MPC measures the number of method calls defined in methods of a class to methods in other classes, and
therefore the dependency of local methods to methods implemented by other classes. It allows for conclusions on
the message passing (method calls) between objects of the involved classes. This allows for conclusions on reuseability, maintenance and testing effort. http://www.arisa.se/compendium/node113.html
Weighted Method Count Description
A weighted sum of methods implemented within a class. It is parameterized by a way to compute the weight of
each method. Possible weight metrics are:

lxxi

Zarko Acimovic

McCabe Cyclomatic Complexity 3.1.3,


Lines of Code 3.1.1,
1 (unweighted WMC).
This variant of WMC uses McCabe Cyclomatic Complexity 3.1.3 metric for calculating the weight for each
method. Originally defined as an object-oriented metric, it can easily adapted to non-object-oriented systems
computing
the
weighted
sum
of
functions
implemented
within
a
module
or
file.
http://www.arisa.se/compendium/node97.html

MapsMIDlet.java

1 /**
2
*
3
* MapsMIDlet creates control menus due to user's actions and handles GPS
issues
4
*
5
*/
6 import javax.microedition.lcdui.*;
7
8 import javax.microedition.midlet.*;
9
10 import java.util.*;
11 import java.io.*;
12
13
14
15
16
17 public class MapsMIDlet extends MIDlet implements CommandListener,Runnable
{
18
19
20
MapBackgroundFactory mbf = new MapBackgroundFactory("/Mali2.png",
"/Srednji.png","/Veliki.png",
21
"44.83049905", "20.44570857", "44.79241639",
"20.48713523");
22
23
24
MapBackground mb;
25
MapObjects mob;
26
SelectorPoint selP;
27
Outlook oul;
28
29
PVector vwpF = new PVector("free",false);
30
ImageCanvas3 ic;
31
CompassCanvas cc;
32

lxxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


33
//Point wp3 = new
Point("44.81916183","20.45417165","Klub'Akademija'","j","/Cultural_or_Tourist/Event
.png",true);
34
Point wp2 = new Point("44.82990854","20.45661377","25.
maj","j","/Sport/Swimming.png",true);
35
Point wp1 = new Point("44.81573706","20.45998215","Sp. Knezu
Mihailu","j","/Cultural_or_Tourist/Monument.png",true);
36
37
Point wp4 = new Point("44.8178034","20.45177167","Saborna
crkva","j","/Cultural_or_Tourist/Church.png",true);
38
Point wp5 = new Point("44.82577520","20.45459270","Zooloski
vrt","j","/Cultural_or_Tourist/Zoo.png",true);
39
40
Point wp6 = new Point("44.81293225","20.46132951","Grinet
kafe","j","/Service_or_Utility/Cafe.png",true);
41
Point wp7 = new Point("44.81426084","20.45943480","Trzni centar
'Sremska'","j","/Service_or_Utility/Shop.png",true);
42
Point wp8 = new Point("44.81248939","20.46006637","Bioskop
20.oktobar","j","/Service_or_Utility/Cinema.png",true);
43
Point wp9 = new
Point("44.81293225","20.46743470","Policija","j","/Service_or_Utility/Police.png",t
rue);
44
Point wp10 = new Point("44.81854182","20.45711898","Filoloski
fakultet","j","/Service_or_Utility/School.png",true);
45
Point wp11 = new Point("44.82518476","20.45737165","Bioskop
REX","j","/Service_or_Utility/Cinema.png",true);
46
Point wp12 = new Point("44.80496078","20.47652941","Elektrotehnicki
fakultet","j","/Service_or_Utility/School.png",true);
47
Point wp13 = new
Point("44.80466556","20.47337150","RCUB","j","/Service_or_Utility/School.png",true)
;
48
Point wp14 = new
Point("44.80865126","20.46368736","Apoteka","j","/Service_or_Utility/Pharmacy.png",
true);
49
Point wp15 = new Point("44.80067980","20.45737165","Urgentni
centar","j","/Service_or_Utility/Redcross.png",true);
50
51
52
53
54 /**
Point wp3 = new Point(45,2 , 1,'N',22,20, 5,'E',"c1","j");
55
Point wp4 = new Point(45,13, 2,'N',21,58, 5,'E',"d1","j");
56
Point wp5 = new Point(46,45, 1,'N',21,20, 5,'E',"e1","j");
57
Point wp6 = new Point(46,48,23,'N',21,23, 9,'E',"f1","j");
58
Point wp7 = new Point(46,30,50,'N',22,25,50,'E',"g1","j");
59
Point wp8 = new Point(46,48,59,'N',20,27,17,'E',"a","j");
60
Point wp9 = new Point(46,45, 0,'N',20,26,15,'E',"b","j");
61
Point wp10 = new Point(46,42, 0,'N',20,29,15,'E',"c","j");
62
Point wp11 = new Point(46,39, 0,'N',20,29,15,'E',"d","j");
63
Point wp12 = new Point(46,10,23,'N',20,30, 9,'E',"e","j");
64
Point wp13 = new Point(45,50,23,'N',20,33, 9,'E',"f","j");
lxxiii

Zarko Acimovic

65
Point wp14 = new Point(46,30,23,'N',20,52, 9,'E',"g","j");
66
Point wp15 = new Point(46,25,23,'N',20,54, 0,'E',"h","j");
67
Point wp16 = new Point(46,20,23,'N',20,46, 0,'E',"i","j");
68
Point wp17 = new Point(46,10,23,'N',20,48, 0,'E',"j","j");
69
Point wp18 = new Point(45,50,23,'N',20,35, 0,'E',"k","j"); */
70
71
Point selectedWP;
72
73
74
///////////////////////COMMANDS,MENUS,BUTTONS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
75
Command DUMMY;
76
Command DELIM;
77
Command MAP_CMD;
78
79
Display d = Display.getDisplay(this);
80
81
List modes;
82
Command selectCmd;
83
Command mapviewCmd;
84
Command compassCmd;
85
86
87
88
Command opt;
89
Command mod;
90
91
List MVList;
92
Command Points;
93
Command routes;
94
Command gps;
95
Command friends;
96
Command ZoomIn;
97
Command ZoomOut;
98
Command exitCmd;
99
SimpleTextForm gpsTf;
100
Thread t1;
101
Thread t2;
102
103
static String resource="";
104
boolean gpsON = false;
105
static String show = "";
106
boolean first = false;
107
List friendList;
108
Command addNewFriend ;
109
Command onGPSc;
110
Command offGPSc;
111
List gpsList;
112
int gpsHash = 0;
113
114
int gpsThr = 0;
lxxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


115
int frndThr = 0;
116
int currentlyShowed = 0;
117
Hashtable thrHash = new Hashtable();
118
Vector listOfFriends = new Vector();
119
SimpleTextForm friendForm;
120
Command stopFollow;
121
Command deleteFriends;
122
boolean followFriends = false;
123
124
List oneFriend;
125
Command stopFollowOne;
126
Command deleteFriend;
127
128
Thread4Friend tff;
129
Vector whiteList;
130
String friend;
131
132
boolean syncFollow = false;
133
long globalTimeStamp = 0;
134
boolean synchronizationDone = false;
135
136
List WPselected;
137
Command setAsCurrent;
138
Command setDest1;
139
Command edit;
140
Command delete;
141
Command measDist;
142
Command setLine;
143
Command resetLine;
144
145
146
List WPnotSel;
147
Command setCurrent;
148
Command setDest2;
149
Command addWP;
150
151
CommaHyphenString chs = new CommaHyphenString();
152
TextForm tf1; // form for adding new Point on selected spot
153
TextForm tf2; // form for editing of selected Point
154
TextForm tf33; // form for adding waypoint with user entered data
for (lat,lon)
155
TextForm previous;
156
TextFormImage tf11; //form for adding new Point with images for
selected categories
157
TextFormImage tf22;
158
Command SAVE_CMD;
159
Command CONT_CMD;
160
Command BACK_CMD;
161
Alert a = new Alert("Warning","Please Select
Point!",null,AlertType.INFO);
162
lxxv

Zarko Acimovic

163
164
165
166
167
168
169
170
171
172
coordinates
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212

List WPList; //List of Points


Command addNewWP;
Command sortWP;
Command sortNameWP;
boolean showID = false;
Command showIDcom;
List previousList;

TextForm tfAdd; //form for adding Point with complete info about

List sorted;

List routeMain;
Command createNewRoute;
Command showRoutes;
Command delRoute;
List routeNew;
Command addPoint;
Command routeFin;
List routeList;
List routeOptions;
Command allRoutes;
Command hideRoutes;
List delRouteList;
Command delAllRoutes;
String nameR = "";
PVector newRouteVector;
SimpleTextForm tf3; ///form for defining name of route
String[] categories;
boolean routeSetting = false;
String[] pathToImage;
/**
* @see MIDlet#startApp()
*/
protected void startApp() throws MIDletStateChangeException {
mb = mbf.getMapBackground();
mob = new MapObjects(mb);
vwpF.addElement(wp1);
vwpF.addElement(wp2);
//vwpF.addElement(wp3);
vwpF.addElement(wp4);
lxxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


213
vwpF.addElement(wp5);
214
vwpF.addElement(wp6);
215
vwpF.addElement(wp7);
216
vwpF.addElement(wp8);
217
vwpF.addElement(wp9);
218
vwpF.addElement(wp10);
219
vwpF.addElement(wp11);
220
vwpF.addElement(wp12);
221
vwpF.addElement(wp13);
222
vwpF.addElement(wp14);
223
vwpF.addElement(wp15);
224
225
226
227
mob.setFreeWaypointsV(vwpF);
228
229
selP = new SelectorPoint(mb,mob);
230
231
oul = new Outlook(mb,mob,selP);
232
233
ic = new ImageCanvas3(oul);
234
235
236
//////////////////////////COMMANDS,MENUS,BUTTONS\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
237
238
DUMMY = new Command("
",Command.SCREEN,1);
239
DELIM = new Command("------------------",Command.SCREEN,1);
240
MAP_CMD = new Command("View on Map",Command.BACK,1);
241
BACK_CMD = new Command("Back to Previous
Screen",Command.BACK,1);
242
243
mod = new Command("Mode",Command.SCREEN,1);
244
modes = new List("",List.IMPLICIT);
245
selectCmd = new Command("Selection",Command.SCREEN,1);
246
mapviewCmd = new Command("Mapview",Command.SCREEN,1);
247
compassCmd = new Command("Compass",Command.SCREEN,1);
248
exitCmd = new Command("Exit",Command.SCREEN,1);
249
modes.append("PLEASE SELECT NEW MODE FROM MENU...",null);
250
modes.addCommand(DUMMY);
251
modes.addCommand(mapviewCmd);
252
modes.addCommand(selectCmd);
253
modes.addCommand(compassCmd);
254
modes.addCommand(exitCmd);
255
modes.setCommandListener(this);
256
257
opt = new Command("Option",Command.SCREEN,1);
258
259
260
261
// Map View options
lxxvii

Zarko Acimovic

262
MVList = new List("",List.IMPLICIT);
263
Points = new Command("Waypoints",Command.SCREEN,1);
264
routes
= new Command("Routes",Command.SCREEN,1);
265
gps
= new Command("GPS",Command.SCREEN,1);
266
267
friends
= new Command("Friends",Command.SCREEN,1);
268
ZoomIn
= new Command("Zoom In",Command.SCREEN,1);
269
ZoomOut
= new Command("Zoom Out",Command.SCREEN,1);
270
//Exit
= new Command("Exit",Command.EXIT,1);
271
272
MVList.addCommand(DUMMY);
273
MVList.addCommand(Points);
274
MVList.addCommand(routes);
275
MVList.addCommand(gps);
276
MVList.addCommand(friends);
277
MVList.addCommand(ZoomIn);
278
MVList.addCommand(ZoomOut);
279
MVList.addCommand(BACK_CMD);
280
MVList.setCommandListener(this);
281
282
CONT_CMD = new Command("Continue",Command.SCREEN,1);
283
gpsTf = new SimpleTextForm(false);
284
gpsTf.addCommand(CONT_CMD);
285
gpsTf.setCommandListener(this);
286
287
288
289
290
// If Point is selected
291
WPselected
= new List("",List.IMPLICIT);
292
setAsCurrent = new Command("Set as
Current",Command.SCREEN,1);
293
setDest1
= new Command("Set as
Destination",Command.SCREEN,1);
294
edit
= new Command("Edit",Command.SCREEN,1);
295
delete
= new Command("Delete",Command.SCREEN,1);
296
measDist
= new Command("Measure
Distance",Command.SCREEN,1);
297
298
299
WPselected.addCommand(DUMMY);
300
WPselected.addCommand(MAP_CMD);
301
WPselected.addCommand(setAsCurrent);
302
WPselected.addCommand(setDest1);
303
WPselected.addCommand(edit);
304
WPselected.addCommand(delete);
305
WPselected.addCommand(measDist);
306
WPselected.addCommand(BACK_CMD);
307
WPselected.setCommandListener(this);
308
309
lxxviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


310
311
// If Point is not selected
312
WPnotSel
= new List("",List.IMPLICIT);
313
setCurrent = new Command("Set Current",Command.SCREEN,1);
314
setDest2
= new Command("Set
Destination",Command.SCREEN,1);
315
addWP
= new Command("Add Waypoint",Command.SCREEN,1);
316
317
WPnotSel.addCommand(DUMMY);
318
WPnotSel.addCommand(setCurrent);
319
WPnotSel.addCommand(setDest2);
320
WPnotSel.addCommand(addWP);
321
WPnotSel.addCommand(measDist);
322
//WPnotSel.addCommand(MAP_CMD);
323
WPnotSel.addCommand(BACK_CMD);
324
WPnotSel.setCommandListener(this);
325
326
WPList = new List("",List.IMPLICIT);
327
addNewWP = new Command("Add Waypoint",Command.SCREEN,1);
328
sortWP
= new Command("Sort Waypoints by
Distance",Command.SCREEN,1);
329
sortNameWP
= new Command("Sort Waypoints by
Name",Command.SCREEN,1);
330
showIDcom = new Command("Show/Hide ID",Command.SCREEN,1);
331
332
tfAdd = new
TextForm(chs.getCategories(this.getAppProperty("Categories")),false);
333
334
tfAdd.addCommand(CONT_CMD);
335
tfAdd.setCommandListener(this);
336
337
sorted = new List("",List.IMPLICIT);
338
sorted.setCommandListener(this);
339
340
341
ic.addCommand(opt);
342
ic.addCommand(mod);
343
ic.setCommandListener(this);
344
345
346
tf1 = new
TextForm(chs.getCategories(this.getAppProperty("Categories")),false);///form for
adding new Point on selected spot
347
tf2 = new
TextForm(chs.getCategories(this.getAppProperty("Categories")),false);/// form for
editing of selected Point
348
tf33 = new
TextForm(chs.getCategories(this.getAppProperty("Categories")),true);/// form for
editing of selected Point
349
350
SAVE_CMD = new Command("Save",Command.SCREEN,1);
lxxix

Zarko Acimovic

351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401

tf1.addCommand(CONT_CMD);
tf1.addCommand(BACK_CMD);
tf1.setCommandListener(this);
tf2.addCommand(CONT_CMD);
tf2.addCommand(BACK_CMD);
tf2.setCommandListener(this);
tf33.addCommand(CONT_CMD);
tf33.addCommand(BACK_CMD);
tf33.setCommandListener(this);
whiteList = new Vector();
d.setCurrent(ic);
}

public void commandAction(Command c, Displayable s){


if (c==MAP_CMD) d.setCurrent(ic);
if (s==ic && c==mod){
d.setCurrent(modes);
}
if (s==modes && c==selectCmd){
oul.setSelect();
ic.repaint();
d.setCurrent(ic);
selP.resetBig();
selP.resetColor();
}
if (s==modes && c==mapviewCmd){
selP.resetColor();
selP.resetBig();
oul.resetSelect();
d.setCurrent(ic);
}
if (s==modes && c==compassCmd){
oul.resetSelect();
cc = new CompassCanvas(mob);
cc.addCommand(MAP_CMD);
cc.setCommandListener(this);
d.setCurrent(cc);
}
if (s==modes && c==exitCmd){
try{
destroyApp(false);
}catch(Exception e){}
notifyDestroyed();
return;
lxxx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
d.setCurrent(WPnotSel);
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
Point on selected spot
443
category");
444
445
446
447
448
449

}
if(s==cc && c==MAP_CMD){
cc.setEnd();
ic = new ImageCanvas3(oul);
ic.addCommand(opt);
ic.addCommand(mod);
ic.setCommandListener(this);
d.setCurrent(ic);
}
if (s==ic && c==opt && routeSetting==false){
if(oul.getSelect()==true) {
selectedWP = selP.getSelectedWP();
if(selectedWP.getName()=="selector")
if(selectedWP.getName()!="selector") {
d.setCurrent(WPselected);
previousList=null;
}
}
if(oul.getSelect()==false) d.setCurrent(MVList);
}

// IF Point NOT SELECTED


if(s==WPnotSel && c==setCurrent){
Point wp = selP.getSelector();
wp.setName("current");
mob.setCurrentPosition(wp);
d.setCurrent(ic);
}
if(s==WPnotSel && c==setDest2){
Point wp = selP.getSelector();
wp.setName("dest");
mob.setDestinationPosition(wp);
d.setCurrent(ic);
}
// ADD Point ON SELECTED SPOT
if(s==WPnotSel && c==addWP){
tf1.setName("default");

//form for adding new

//tf1.setType("Type will be set according to


tf1.setLat(selP.getSelector().getLat());
tf1.setLon(selP.getSelector().getLon());
d.setCurrent(tf1);
}
if (s.equals(tf1) && c == CONT_CMD){
lxxxi

Zarko Acimovic

450
String name = tf1.getName();
451
int sel = tf1.getSelected();
452
453
// chs is instance of CommaHypenString class
454
// which helps us process hyphens and commas in
455
//.properties file
456
String[] category =
chs.getCategories(this.getAppProperty("Categories"));
457
String[] categoryHyphen =
chs.getCategoriesHyphen(this.getAppProperty("Categories"));
458
459
// elements of a selected category: as simle
strings and as hyphen-strings
460
String catMatches =
this.getAppProperty(categoryHyphen[sel]);
461
String[] arCatMatches =
chs.getStringsOnly(catMatches);
462
String[] arCatHyphMatches =
chs.getWithLowLine(catMatches);
463
464
// images that correspond to category elements
465
String[] imageStr = new
String[arCatMatches.length];
466
Image[] img = new Image[arCatMatches.length];
467
for(int i=0; i<arCatMatches.length; i++){
468
imageStr[i] =
this.getAppProperty(""+arCatHyphMatches[i]+"");
469
imageStr[i] = this.compact(imageStr[i]);
470
}
471
472
pathToImage = new String[arCatMatches.length];
473
for (int i=0; i<arCatMatches.length; i++){
474
try{
475
String str = categoryHyphen[sel]
+"/"+imageStr[i];
476
str = compact(str); //getting rid
off blanco spots
477
pathToImage[i] = str;
478
img[i] = Image.createImage(str);
479
} catch(Exception e){}
480
}
481
482
tf11 = new TextFormImage("",arCatMatches,img);
483
tf11.setNameCHGR("Please select type");
484
tf11.setName(name);
485
//tf11.setType("Please select type");
486
tf11.addCommand(BACK_CMD);
487
tf11.addCommand(SAVE_CMD);
488
tf11.setCommandListener(this);
489
d.setCurrent(tf11);
490
}
lxxxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541

if(s==tf1 && c==BACK_CMD){


d.setCurrent(WPnotSel);
}
if(s==tf11 && c==BACK_CMD){
d.setCurrent(tf1);
}
if(s==tf11 && c==SAVE_CMD){
Point wp = selP.getSelector();
wp.setName(tf11.getName());
int sel = tf11.getSelected();
String cmpct = compact(pathToImage[sel]);
wp.setImage(cmpct);
mob.addFreeWaypoint(wp);
d.setCurrent(ic);
}
if(s==WPselected && c==setAsCurrent){
mob.setCurrentPosition(selectedWP);
d.setCurrent(ic);
}
if(s==WPselected && c==setDest1){
mob.setDestinationPosition(selectedWP);
d.setCurrent(ic);
}
//Edit of Point
if(s==WPselected && c==edit){
tf2.setName(selectedWP.getName());
tf2.setType(selectedWP.getType());
tf2.setLat(selectedWP.getLat());
tf2.setLon(selectedWP.getLon());
d.setCurrent(tf2);
}

//Editing of waypoint OR inserting waypoint from text form


if ( (s.equals(tf2)||s.equals(tf33)) && c == CONT_CMD){
String name ="";
int sel = 0;
if(s.equals(tf2)){
name = tf2.getName();
sel = tf2.getSelected();
previous = tf2;
}
if(s.equals(tf33)){
lxxxiii

Zarko Acimovic

542
name = tf33.getName();
543
sel = tf33.getSelected();
544
previous = tf33;
545
}
546
547
548
// chs is instance of CommaHypenString class
549
// which helps us process hyphens and commas in
550
//.properties file
551
String[] category =
chs.getCategories(this.getAppProperty("Categories"));
552
String[] categoryHyphen =
chs.getCategoriesHyphen(this.getAppProperty("Categories"));
553
554
// elements of a selected category: as simle
strings and as hyphen-strings
555
String catMatches =
this.getAppProperty(categoryHyphen[sel]);
556
String[] arCatMatches =
chs.getStringsOnly(catMatches);
557
String[] arCatHyphMatches =
chs.getWithLowLine(catMatches);
558
559
// images that correspond to category elements
560
String[] imageStr = new
String[arCatMatches.length];
561
Image[] img = new Image[arCatMatches.length];
562
for(int i=0; i<arCatMatches.length; i++){
563
imageStr[i] =
this.getAppProperty(""+arCatHyphMatches[i]+"");
564
imageStr[i] = this.compact(imageStr[i]);
565
}
566
567
pathToImage = new String[arCatMatches.length];
568
for (int i=0; i<arCatMatches.length; i++){
569
try{
570
String str = categoryHyphen[sel]
+"/"+imageStr[i];
571
str = compact(str); //getting rid
off blanco spots
572
pathToImage[i] = str;
573
img[i] = Image.createImage(str);
574
} catch(Exception e){}
575
}
576
577
tf22 = new TextFormImage("",arCatMatches,img);
578
tf22.setNameCHGR("Please select type");
579
tf22.setName(name);
580
tf22.addCommand(BACK_CMD);
581
tf22.addCommand(SAVE_CMD);
582
tf22.setCommandListener(this);
lxxxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


583
d.setCurrent(tf22);
584
}
585
586
if(s==tf2 && c==BACK_CMD){
587
d.setCurrent(WPselected);
588
}
589
590
if(s==tf22 && c==BACK_CMD){
591
d.setCurrent(previous);
592
}
593
594
if(s==tf22 && c==SAVE_CMD){
595
596
//Editing of waypoint
597
if(previous == tf2){
598
Point wp = selP.getSelectedWP();
599
if(wp.getLat()==0){
600
wp = new
Point(tf2.getLat(),tf2.getLon(),tf22.getName(),"","blanco",false);
601
}
602
wp.setName(tf22.getName());
603
int sel = tf22.getSelected();
604
String cmpct = compact(pathToImage[sel]);
605
wp.setImage(cmpct);
606
wp.setLat(tf2.getLat());
607
wp.setLon(tf2.getLon());
608
selP.deleteWP();
609
mob.addFreeWaypoint(wp);
610
selP.setColor();
611
d.setCurrent(ic);
612
}
613
614
// New waypoint from text form
615
if(previous==tf33){
616
Point wp = new
Point(tf33.getLat(),tf33.getLon(),tf22.getName(),"","blanco",false);
617
wp.setName(tf22.getName());
618
int sel = tf22.getSelected();
619
String cmpct = compact(pathToImage[sel]);
620
wp.setImage(cmpct);
621
wp.setLat(tf33.getLat());
622
wp.setLon(tf33.getLon());
623
mob.addFreeWaypoint(wp);
624
d.setCurrent(ic);
625
}
626
}
627
628
629
// Delete Point
630
if(s==WPselected && c==delete){
631
int k = selP.deleteWP();
lxxxv

Zarko Acimovic

632
if(k==-1){
633
a.setTimeout(3000);
634
a.setString("More than one Point
selected");
635
d.setCurrent(a);
636
} else {
637
selP.resetBig();
638
d.setCurrent(ic);
639
}
640
}
641
642
if(s==WPselected && c==BACK_CMD){
643
if(previousList==null) d.setCurrent(ic);
644
if(previousList!=null) d.setCurrent(previousList);
645
}
646
647
648
// Measuring distance between current position and selected
WAYPOINT
649
if(s==WPselected && c==measDist){
650
if(mob.getCurrentPosition().getName().equals("dummy")){
651
a.setTimeout(3000);
652
a.setString("Current position is not set");
653
d.setCurrent(a);
654
655
} else {
656
a.setTimeout(3000);
657
selectedWP = selP.getSelectedWP();
658
long k = mob.measureDistance(selectedWP);
659
a.setString("Distance is "+k+" m");
660
d.setCurrent(a);
661
}
662
663
}
664
665
666
// Measuring distance between current position and selected
LOCATION
667
if(s==WPnotSel && c==measDist){
668
selectedWP = selP.getSelector();
669
long k = mob.measureDistance(selectedWP);
670
if(mob.currentSet()==false){
671
a.setTimeout(3000);
672
a.setString("Current position is not set");
673
d.setCurrent(a);
674
675
} else {
676
a.setTimeout(3000);
677
a.setString("Distance is "+k+" m");
678
d.setCurrent(a);
lxxxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


679
}
680
}
681
682
if(s==WPnotSel && c==BACK_CMD) d.setCurrent(ic);
683
684
685
686
687
688
// -----------------Showing up all Points and some
operations--------------689
if(s==MVList && c==Points){
690
setWPList();
691
692
for(int i=0; i<mob.freeWaypoints.size(); i++){
693
Point wp =
(Point)mob.freeWaypoints.elementAt(i);
694
String name = "";
695
if(showID==true){
696
name = wp.getName()
+"_"+wp.getID();
697
} else {
698
name = wp.getName();
699
}
700
Command cc = new
Command(name,Command.SCREEN,1);
701
WPList.addCommand(cc);
702
}
703
d.setCurrent(WPList);
704
}
705
706
if(s==MVList && c==BACK_CMD){
707
d.setCurrent(ic);
708
}
709
710
if(s==MVList && c==ZoomIn){
711
oul.ZoomIn();
712
d.setCurrent(ic);
713
}
714
715
if(s==MVList && c==ZoomOut){
716
oul.ZoomOut();
717
d.setCurrent(ic);
718
}
719
720
721
// displaying of IDs of icons
722
if(s==WPList && c==showIDcom){
723
if(showID==true) {showID=false; } else
{showID=true;}
724
lxxxvii

Zarko Acimovic

725
setWPList();
726
727
for(int i=0; i<mob.freeWaypoints.size(); i++){
728
Point wp =
(Point)mob.freeWaypoints.elementAt(i);
729
String name = "";
730
if(showID==true){
731
name = wp.getName()
+"_"+wp.getID();
732
} else {
733
name = wp.getName();
734
}
735
Command cc = new
Command(name,Command.SCREEN,1);
736
WPList.addCommand(cc);
737
}
738
d.setCurrent(WPList);
739
}
740
741
742
// Adding new Point with all attributes such as
743
// LATITUDE and LONGITUDE
744
// We deal with tf33 same as with tf2 (tf2 is used for
745
// inserting new data for selected location
746
// Here default values for coordinates are those of center
of the map
747
748
if(s==WPList && c==addNewWP){
749
tf33.setName("Center of
Map");//44.80345511,20.42949821
750
tf33.setType("");
751
tf33.setLat("44.80345511");
752
tf33.setLon("20.42949821");
753
d.setCurrent(tf33);
754
}
755
756
757
758
if(s==tf33 && c==BACK_CMD){
759
d.setCurrent(WPList);
760
}
761
762
//sorting waypoints by distance
763
if(s==WPList && c==sortWP){
764
setWPList();
765
766
Vector sor =
mob.freeWaypoints.sortAscending(mob.getCurrentPosition());
767
for(int i=0; i<sor.size(); i++){
768
Point wp = (Point)sor.elementAt(i);
769
String name = "";
lxxxviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


770
if(showID==true){
771
name = wp.getName()+" "+wp.getID();
772
} else {
773
name = wp.getName();
774
}
775
Command cc = new
Command(name,Command.SCREEN,1);
776
WPList.addCommand(cc);
777
}
778
d.setCurrent(WPList);
779
}
780
781
//sorting waypoints by name
782
if(s==WPList && c==sortNameWP){
783
setWPList();
784
String[] sor = mob.freeWaypoints.sortByName();
785
for(int i=0; i<sor.length; i++){
786
Command cc = new
Command(sor[i],Command.SCREEN,1);
787
WPList.addCommand(cc);
788
}
789
d.setCurrent(WPList);
790
}
791
792
793
if(s==WPList && c==MAP_CMD){
794
d.setCurrent(ic);
795
}
796
797
if(s==WPList && c==BACK_CMD){
798
d.setCurrent(MVList);
799
}
800
801
//Displaying selected waypoint
802
if(s==WPList && c!=sortWP && c!=addNewWP && c!=MAP_CMD &&
c!=sortNameWP && c!=DUMMY && c!=BACK_CMD){
803
String name = c.getLabel();
804
mb.param=true;
805
selP.selectWP(name);
806
oul.setSelect();
807
oul.setWPselection();
808
d.setCurrent(WPselected);
809
previousList = WPList;
810
}
811
812
813
814
// -------------- ROUTES -------------------------------815
816
// Main Menu for Routes
817
if(s==MVList && c==routes){
lxxxix

Zarko Acimovic

818
routeMain = new List("",List.IMPLICIT);
819
createNewRoute = new Command("New
Route",Command.SCREEN,1);
820
routeMain.addCommand(DUMMY);
821
routeMain.addCommand(createNewRoute);
822
routeMain.addCommand(BACK_CMD);
823
routeMain.addCommand(DELIM);
824
routeMain.setCommandListener(this);
825
for(int i=0; i<mob.getRoutes().size(); i++){
826
PVector route =
(PVector)mob.getRoutes().elementAt(i);
827
String name = route.getName();
828
Command cr = new
Command(name,Command.SCREEN,1);
829
routeMain.addCommand(cr);
830
}
831
d.setCurrent(routeMain);
832
}
833
834
if(s==routeMain && c==BACK_CMD){
835
d.setCurrent(MVList);
836
}
837
838
//Creating a New Route
839
if(s==routeMain && c==createNewRoute){
840
tf3 = new SimpleTextForm(false);
841
tf3.addCommand(SAVE_CMD);
842
tf3.setCommandListener(this);
843
d.setCurrent(tf3);
844
}
845
846
847
if(s==tf3 && c==SAVE_CMD){
848
newRouteVector = new PVector("",true);
849
newRouteVector.setName(tf3.getName());
850
newRouteVector.setVisible();
851
mob.addRoute(newRouteVector);
852
853
routeNew = new List("",List.IMPLICIT);
854
addPoint = new Command("Add
Waypoint",Command.SCREEN,1);
855
routeFin = new Command("Route
Finished",Command.SCREEN,1);
856
routeNew.addCommand(addPoint);
857
routeNew.addCommand(routeFin);
858
routeNew.setCommandListener(this);
859
860
d.setCurrent(routeNew);
861
}
862
863
xc

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


864
// Selection of specific route
865
if(s==routeMain && c!=createNewRoute && c!=DUMMY && c!
=BACK_CMD && c!=DELIM){
866
nameR = c.getLabel();
867
routeOptions = new List("",List.IMPLICIT);
868
showRoutes = new Command("Show/Hide
Route",Command.SCREEN,1);
869
delRoute = new Command("Delete
Route",Command.SCREEN,1);
870
routeOptions.addCommand(DUMMY);
871
routeOptions.addCommand(MAP_CMD);
872
routeOptions.addCommand(showRoutes);
873
routeOptions.addCommand(delRoute);
874
routeOptions.addCommand(BACK_CMD);
875
routeOptions.setCommandListener(this);
876
d.setCurrent(routeOptions);
877
}
878
879
//Viewing selected route
880
if(s==routeOptions && c==showRoutes){
881
Vector allR = (Vector) mob.getRoutes();
882
for(int i=0; i<allR.size(); i++){
883
PVector rt = (PVector)allR.elementAt(i);
884
if(rt.getName()==nameR) {
885
if(rt.size()!=0){
886
if(rt.getVisible()==true){
887
rt.resetVisible();
888
d.setCurrent(ic);
889
}else{
890
rt.setVisible();
891
Point wp = (Point)
rt.elementAt(0);
892
String name =
wp.getName();
893
selP.selectWP(name);
894
oul.setSelect();
895
selP.resetColor();
896
selP.resetBig();
897
d.setCurrent(ic);
898
}
899
}
900
if(rt.size()==0){
901
a.setTitle("Warning");
902
a.setString("Route has no
points to show");
903
a.setTimeout(5000);
904
d.setCurrent(a);
905
}
906
907
}
xci

Zarko Acimovic

908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958

if(rt.getName()!=nameR) rt.resetVisible();
}
}

//Deletion of selected route


if(s==routeOptions && c==delRoute){
Vector v = mob.getRoutes();
for(int i=0; i<v.size(); i++){
PVector wpv = (PVector)v.elementAt(i);
if(wpv.getName()==nameR){
mob.removeRoute(nameR);
i=1000;
}
}
d.setCurrent(ic);
}

//Mapview
if(s==routeOptions && c==MAP_CMD){
Vector v = mob.getRoutes();
for(int i=0; i<v.size(); i++){
PVector wpv = (PVector)v.elementAt(i);
if(wpv.getName()==nameR){
Point p = (Point) wpv.elementAt(0);
selP.selectWP(p.getName());
oul.setSelect();
oul.setWPselection();
i=1000;
}
}
d.setCurrent(ic);
}
//Back on routeMain
if(s==routeOptions && c==BACK_CMD){
d.setCurrent(routeMain);
}

//Adding new point in current route


if(s==routeNew && c==addPoint){
if(oul.getSelect()==true){
mob.removeRoute(newRouteVector);
Point wp = selP.getSelector();
wp.setTypeID(newRouteVector.getID());
wp.setName(newRouteVector.getName());
xcii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


959
wp.setImage("route");
960
newRouteVector.addElement(wp);
961
mob.addRoute(newRouteVector);
962
d.setCurrent(ic);
963
}
964
965
if(oul.getSelect()==false){
966
oul.setSelect();
967
oul.setRoute();
968
routeSetting = true;
969
d.setCurrent(ic);
970
}
971
972
}
973
974
if(s==ic && routeSetting==true && c==opt){
975
d.setCurrent(routeNew);
976
}
977
978
if(s==routeNew && c==routeFin){
979
oul.resetSelect();
980
routeSetting = false;
981
d.setCurrent(ic);
982
}
983
984
985
986
987
988
989
//--------------------------------GPS
ON/OFF-----------------------------990
991
if(s==MVList && c==gps){
992
gpsList = new List("",List.IMPLICIT);
993
onGPSc
= new Command("On",Command.SCREEN,1);
994
offGPSc = new Command("Off",Command.SCREEN,1);
995
gpsList.addCommand(onGPSc);
996
gpsList.addCommand(offGPSc);
997
gpsList.setCommandListener(this);
998
d.setCurrent(gpsList);
999
}
1000
1001
if(s==gpsList && c==onGPSc){
1002
if(gpsON==false){
1003
gpsON=true;
1004
followFriends = false;
1005
//Specifying GPS coordinates resource
1006
gpsTf.setLabel("Please select source of GPS
coordinates, usually it's GPS.txt");
1007
gpsTf.setName("GPS.txt");
xciii

Zarko Acimovic

1008
gpsTf.setType("GPS.txt");
1009
d.setCurrent(gpsTf); //GPS textform
1010
} else {
1011
d.setCurrent(ic);
1012
}
1013
}
1014
1015
if(s==gpsList && c==offGPSc){
1016
gpsON=false;
1017
d.setCurrent(ic);
1018
}
1019
1020
1021
1022
if(s==gpsTf && c==CONT_CMD){
1023
resource = gpsTf.getName();
1024
1025
syncFollow = true;
1026
synchronizationDone=false;
1027
1028
t1=new Thread(this);
1029
currentlyShowed = t1.hashCode();
1030
gpsHash = t1.hashCode();
1031
t1.start();
1032
d.setCurrent(ic);
1033
1034
}
1035
1036
// --------------------------- HANDLING FRIENDS' ISSUES
------------------1037
1038
if(s==MVList && c==friends){
1039
friendList = new List("",List.IMPLICIT);
1040
addNewFriend = new Command("Add New Friend",
Command.SCREEN,1);
1041
stopFollow = new Command("Stop Follow Friends",
Command.SCREEN,1);
1042
deleteFriends = new Command("Delete Friends",
Command.SCREEN,1);
1043
friendList.addCommand(DUMMY);
1044
friendList.addCommand(addNewFriend);
1045
friendList.addCommand(stopFollow);
1046
friendList.addCommand(deleteFriends);
1047
friendList.addCommand(BACK_CMD);
1048
friendList.addCommand(DELIM);
1049
if(listOfFriends.size()>0){
1050
for (int i=0; i<listOfFriends.size(); i++){
1051
Friend f =
(Friend)listOfFriends.elementAt(i);
1052
Command cc = new
Command(f.getName(),Command.SCREEN,1);
xciv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


1053
friendList.addCommand(cc);
1054
}
1055
}
1056
friendList.setCommandListener(this);
1057
d.setCurrent(friendList);
1058
}
1059
1060
if(s==friendList && c==addNewFriend){
1061
friendForm = new SimpleTextForm(false);
1062
friendForm.setLabel("Friend");
1063
friendForm.setLabel2("Source of coordinates");
1064
friendForm.setName("Mika");
1065
friendForm.setType("Mika.txt");
1066
1067
friendForm.addCommand(CONT_CMD);
1068
friendForm.setCommandListener(this);
1069
1070
d.setCurrent(friendForm);
1071
}
1072
1073
if(s==friendForm && c==CONT_CMD){
1074
tff = new
Thread4Friend(whiteList,friendForm.getName(),mob,ic,mb,oul);
1075
Integer hID = new Integer(tff.getID());
1076
whiteList.addElement(hID);
1077
1078
tff.start();
1079
Friend f = new
Friend(friendForm.getName(),friendForm.getType(),tff.getID(),tff);
1080
listOfFriends.addElement(f);
1081
d.setCurrent(ic);
1082
}
1083
1084
if(s==friendList && c==stopFollow){
1085
whiteList.removeAllElements();
1086
mob.deleteAllFriends();
1087
ic.repaint();
1088
d.setCurrent(ic);
1089
}
1090
1091
if(s==friendList && c==deleteFriends){
1092
mob.deleteAllFriends();
1093
listOfFriends.removeAllElements();
1094
friendList = new List("",List.IMPLICIT);
1095
addNewFriend = new Command("Add New Friend",
Command.SCREEN,1);
1096
stopFollow = new Command("Stop Follow Friends",
Command.SCREEN,1);
1097
deleteFriends = new Command("Delete Friends",
Command.SCREEN,1);
1098
friendList.addCommand(DUMMY);
xcv

Zarko Acimovic

1099
friendList.addCommand(addNewFriend);
1100
friendList.addCommand(stopFollow);
1101
friendList.addCommand(deleteFriends);
1102
//friendList.addCommand(MAP_CMD);
1103
friendList.addCommand(BACK_CMD);
1104
friendList.addCommand(DELIM);
1105
if(listOfFriends.size()>0){
1106
for (int i=0; i<listOfFriends.size(); i++){
1107
Friend f =
(Friend)listOfFriends.elementAt(i);
1108
Command cc = new
Command(f.getName(),Command.SCREEN,1);
1109
friendList.addCommand(cc);
1110
}
1111
}
1112
friendList.setCommandListener(this);
1113
d.setCurrent(friendList);
1114
d.setCurrent(friendList);
1115
}
1116
1117
if(s==friendList && c!=addNewFriend && c!=stopFollow && c!
=deleteFriends && c!=MAP_CMD && c!=BACK_CMD && c!=DELIM){
1118
friend = c.getLabel();
1119
friend = compact(friend);
1120
oneFriend = new List("",List.IMPLICIT);
1121
stopFollowOne = new Command("Stop Follow",
Command.SCREEN,1);
1122
deleteFriend = new Command("Delete",
Command.SCREEN,1);
1123
oneFriend.addCommand(DUMMY);
1124
oneFriend.addCommand(MAP_CMD);
1125
oneFriend.addCommand(stopFollowOne);
1126
oneFriend.addCommand(deleteFriend);
1127
oneFriend.addCommand(BACK_CMD);
1128
oneFriend.setCommandListener(this);
1129
1130
d.setCurrent(oneFriend);
1131
}
1132
1133
if(s==friendList && c==BACK_CMD){
1134
d.setCurrent(MVList);
1135
}
1136
1137
if(s==oneFriend && c==MAP_CMD){
1138
for(int i=0; i<listOfFriends.size(); i++){
1139
Friend f =
(Friend)listOfFriends.elementAt(i);
1140
if(f.getName().equals(friend)) {
1141
1142
if(f.getThread()==false){

xcvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


1143
tff = new
Thread4Friend(whiteList,f.getName(),mob,ic,mb,oul);
1144
Integer hID = new
Integer(tff.getID());
1145
whiteList.addElement(hID);
1146
f.setID(tff.getID());
1147
f.setThread(tff);
1148
tff.setFirst();
1149
tff.start();
1150
} else {
1151
f.setFirst();
1152
}
1153
}
1154
}
1155
d.setCurrent(ic);
1156
}
1157
1158
if(s==oneFriend && c==BACK_CMD){
1159
d.setCurrent(friendList);
1160
}
1161
1162
if(s==oneFriend && c==stopFollowOne){
1163
for(int i=0; i<listOfFriends.size(); i++){
1164
Friend f =
(Friend)listOfFriends.elementAt(i);
1165
if(f.getName().equals(friend)) {
1166
whiteList.removeElement(new
Integer(f.getHash()));
1167
mob.deleteFriend(f.getHash());
1168
f.setThread(null);
1169
}
1170
}
1171
d.setCurrent(ic);
1172
}
1173
1174
if(s==oneFriend && c==deleteFriend){
1175
for(int i=0; i<listOfFriends.size(); i++){
1176
Friend f =
(Friend)listOfFriends.elementAt(i);
1177
if(f.getName().equals(friend)) {
1178
whiteList.removeElement(new
Integer(f.getHash()));
1179
mob.deleteFriend(f.getHash());
1180
listOfFriends.removeElementAt(i);
1181
}
1182
}
1183
d.setCurrent(ic);
1184
}
1185
1186
}
1187
xcvii

Zarko Acimovic

1188
1189
//----------------------This part of code deals with
GPS--------------------1190
public void run(){
1191
while(followFriends==true || gpsON==true){
1192
String s = this.getResourceAsString(resource);
1193
int nextIndex = 6;
1194
int index = s.indexOf('\n');
1195
1196
nextIndex = s.indexOf('\n',index+1);
1197
1198
int lastIndex = s.lastIndexOf('\n');
1199
1200
int begin = -2;
1201
int end = index;
1202
1203
String c1 = "";
1204
String c2 = "";
1205
String timeStamp = "";
1206
long currentTS = 0;
1207
1208
while(index<lastIndex && gpsON==true){
1209
Thread t = Thread.currentThread();
1210
if(t.hashCode()==currentlyShowed){
1211
/**
1212
if(synchronizationDone==false &&
syncFollow==true){
1213
do{ //Synchronization
1214
String temp =
s.substring(begin+2,end);
1215
temp =
compact(temp);
1216
int comma =
temp.indexOf(',');
1217
c1 =
temp.substring(0,comma);
1218
int nextComma =
temp.indexOf(',',comma+1);
1219
c2 =
temp.substring(comma+1,nextComma);
1220
timeStamp =
temp.substring(nextComma+1,temp.length());
1221
currentTS =
Long.parseLong(timeStamp);
1222
begin = index-1;
1223
end = nextIndex;
1224
index = nextIndex;
1225
nextIndex =
s.indexOf('\n',nextIndex+1);
1226
}
while(currentTS<this.getTimeStamp());
xcviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


1227
1228
1229
1230
1231
1232
Point(c2,c1,resource,"","blanco",true);
1233
1234
1235
this.setTimeStamp(currentTS);
1236
1237
1238
s.substring(begin+2,end);
1239
1240
temp da bude prazno
1241
1242
1243
1244
temp.indexOf(',');
1245
temp.substring(0,comma);
1246
temp.indexOf(',',comma+1);
1247
temp.substring(comma+1,nextComma);
1248
temp.substring(nextComma+1,temp.length());
1249
Long.parseLong(timeStamp);
1250
1251
1252
1253
1254
s.indexOf('\n',nextIndex+1);
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
mob.setCurrentPosition(wp);

xcix

synchronizationDone = true;
}*/
Point wp = null;
if(!c1.equals("")){
wp = new
}
if(syncFollow==true)

}
String temp =
temp = compact(temp);
if(temp.equals("")){ //na kraju ce
index = lastIndex+1;
} else {
temp = compact(temp);
int comma =
c1 =
int nextComma =
c2 =
timeStamp =
currentTS =

begin = index-1;
end = nextIndex;
index = nextIndex;
nextIndex =
}
try{
Thread.sleep(1000);
}catch(Exception e){}
if(wp!=null){
mob.setDrawablePoints();
if(gpsON==true){

Zarko Acimovic

1265
if((mob.getCurrentPosition().getX()>170 || mob.getCurrentPosition().getY()>160 ||
1266
mob.getCurrentPosition().getX()<10 || mob.getCurrentPosition().getY()<10) &&
oul.getSelect()==false )
1267
mb.setBackground(wp);
1268
ic.repaint();
1269
1270
}
1271
}
1272
}
1273
}
1274
}
1275
1276
}
1277
1278
/**
1279
* @see MIDlet#pauseApp()
1280
*/
1281
protected void pauseApp() {
1282
}
1283
1284
/**
1285
* @see MIDlet#destroyApp(boolean)
1286
*/
1287
protected void destroyApp(boolean flag) throws
MIDletStateChangeException {
1288
}
1289
1290
1291
/** Blanco characters are possible to occur in names of pictures;
1292
* Integer representations of blanko characters are 9 and 32
1293
* Also, characters with integer representation between 0 and 33
1294
* can not be printed out in WSDD console, so I excluded them too
1295
*/
1296
public String compact(String s){
1297
int k = s.length();
1298
char[] d = s.toCharArray();
1299
String ret = "";
1300
for(int i=0; i<d.length; i++){
1301
int temp = (int)d[i];
1302
if(temp>32) ret+=d[i];
1303
}
1304
int kk = ret.length();
1305
return ret;
1306
}
1307
1308
public String compactFine(String s){
1309
int k = s.length();
c

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360

char[] d = s.toCharArray();
String ret = "";
for(int i=0; i<d.length; i++){
int temp = (int)d[i];
if(temp!=32 && temp!=9) ret+=d[i];
}
int kk = ret.length();
return ret;
}
public String getResourceAsString(String resource){
InputStream is = null;
try{
is = this.getClass().getResourceAsStream(resource);
}catch(Exception e) {
a.setString("There is no such resource");
d.setCurrent(a);
}
//conversion of resource into string
String s = "";
char m =' ';
try{
m = (char)is.read();
}catch(Exception e){}
while(m!=65535){
s+=m;
try{
m = (char)is.read();
}catch(Exception e){}
}
try{
is.close();
}catch(Exception e){}

s=compactFine(s);
return s;
}
public long getTimeStamp(){
return globalTimeStamp;
}
public void setTimeStamp(long tms){
globalTimeStamp = tms;
}
public void setWPList(){
ci

Zarko Acimovic

1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375

WPList = new List("",List.IMPLICIT);


WPList.addCommand(DUMMY);
WPList.addCommand(addNewWP);
WPList.addCommand(sortWP);
WPList.addCommand(sortNameWP);
WPList.addCommand(showIDcom);
WPList.addCommand(BACK_CMD);
WPList.addCommand(DELIM);
WPList.setCommandListener(this);
}
}

cii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

ciii

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Efferent Coupling (Ce)


Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

MathFP suffers from Lack of Documentation and Number of Local Methods.


Number Of Local Methods Description
Number of local Methods measures the number of methods locally declared in a class. Inherited methods are not
considered. It is the size of the interface of a class and allows conclusions on its complexity.
http://www.arisa.se/compendium/node94.html

MathFP.java
1
2
3
4
5
6
7
8
9
10
11

/**
* MathFP implements fix point as a replacement for floating point
*/

// Processed by NMI's Java Code Viewer 4.8.1 1997-2000 B. Lemaire


// Website: http://njcv.htmlplanet.com E-mail: info@njcv.htmlplanet.com
// Copy registered to Evaluation Copy
public class MathFP {
civ

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


12
13
/** Modulo (% operator) implementaition missing in MathFP 2.0.6
14
* @author BMa
15
*/
16
public static long mod(long num, long by) {
17
//System.out.println("mod: "+MathFP.toString(num)+" by:
"+MathFP.toString(by));
18
long frac = MathFP.div(num, by);
19
//System.out.println("MathFP.div(num, by):
"+MathFP.toString(MathFP.div(num, by)));
20
//long frac = MathFP.round(frac, 0); does not work properly???
21
//System.out.println("MathFP.round(MathFP.div(num, by), 0):
"+MathFP.toString(MathFP.round(MathFP.div(num, by), 0)));
22
frac = MathFP.toFP(MathFP.toLong(frac));
23
//System.out.println("MathFP.better(MathFP.div(num, by), 0):
"+MathFP.toString(frac));
24
//System.out.println("MathFP.mul(by, frac):
"+MathFP.toString(MathFP.mul(by, frac)));
25
//System.out.println("MathFP.mod: "+MathFP.toString(num MathFP.mul(by, frac)));
26
return num - MathFP.mul(by, frac);
27
}
28
29
30
//private static long sinLimit=toFP("0.0055");
31
32
/** Fix of bad sin() in MathFP 2.0.6 - X is closer to real sin(X) than
calculated value for small X
33
* @author BMa
34
*/
35
public static long sin(long l) {
36
if (abs(l) > toFP("0.0055"))
37
return sinBad(l);
38
else
39
return l;
40
}
41
42
//private static long asinLimit=toFP("0.019");
43
44
/** Fix of bad asin() in MathFP 2.0.6 - X is closer to real asin(X) than
calculated value for small X
45
* @author BMa
46
*/
47
public static long asin(long l) {
48
if (abs(l) > toFP("0.019"))
49
return asinBad(l);
50
else
51
return l;
52
}
53
54
cv

Zarko Acimovic

55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105

private static int _fbits = 24;


private static int _digits = 8;
private static long _one;
private static long _fmask = 0xffffffL;
private static long _dmul = 0x5f5e100L;
private static long _flt = 0L;
private static long _pi;
private static long e[];
public static long PI;
public static long E;
public static final long MAX_VALUE = 0x7fffffffffffffffL;
public static final long MIN_VALUE = 0x8000000000000001L;
public static int setPrecision(int i) {
if(i > 24 || i < 0)
return _digits;
_fbits = i;
_one = 1L << i;
_flt = 24 - i;
_digits = 0;
_dmul = 1L;
_fmask = _one - 1L;
PI = _pi >> (int)_flt;
E = e[1] >> (int)_flt;
for(long l = _one; l != 0L;) {
l /= 10L;
_digits++;
_dmul *= 10L;
}
return _digits;
}
public static int getPrecision() {
return _fbits;
}
public static long toLong(long l) {
if(l < 0L)
return -(round(-l, 0) >> _fbits);
else
return round(l, 0) >> _fbits;
}
public static long toLongZare(long i) {
if(i >= 0)
i += 2048;
else
i -= 2048;
return i >> 12;
}
cvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


106
107
public static long toFP(long l) {
108
return l << _fbits;
109
}
110
111
public static long convert(long l, int i) {
112
long l1 = l >= 0L ? 1L : -1L;
113
if(abs(i) < 25L)
114
if(_fbits < i)
115
l = l + l1 * (1L << (i - _fbits >> 1)) >> i - _fbits;
116
else
117
l <<= _fbits - i;
118
return l;
119
}
120
121
public static long toFP(String s) {
122
int i = 0;
123
if(s.charAt(0) == '-')
124
i = 1;
125
String s1 = "-1";
126
int j = s.indexOf(46);
127
if(j >= 0) {
128
for(s1 = s.substring(j + 1, s.length()); s1.length() < _digits; s1 =
s1 + "0");
129
if(s1.length() > _digits)
130
s1 = s1.substring(0, _digits);
131
} else {
132
j = s.length();
133
}
134
long l = 0L;
135
if(i != j)
136
l = Long.parseLong(s.substring(i, j));
137
long l1 = Long.parseLong(s1) + 1L;
138
long l2 = (l << _fbits) + (l1 << _fbits) / _dmul;
139
if(i == 1)
140
l2 = -l2;
141
return l2;
142
}
143
144
public static String toString(long l) {
145
boolean flag = false;
146
if(l < 0L) {
147
flag = true;
148
l = -l;
149
}
150
long l1 = l >> _fbits;
151
long l2 = _dmul * (l & _fmask) >> _fbits;
152
String s;
153
for(s = Long.toString(l2); s.length() < _digits; s = "0" + s);
154
return (flag ? "-" : "") + Long.toString(l1) + "." + s;
155
}
cvii

Zarko Acimovic

156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206

public static String toString(long l, int i) {


if(i > _digits)
i = _digits;
String s = toString(round(l, i));
return s.substring(0, (s.length() - _digits) + i);
}
public static long getWholePart(String s){
int end = s.indexOf('.');
s = s.substring(0,end);
long wh = toFP(s);
return wh;
}
/**
public static long getWholePart(long l){
String s = toString(l);
int end = s.indexOf('.');
s = s.substring(0,end);
long wh = toFP(s);
return wh;
}*/
public static long max(long l, long l1) {
return l >= l1 ? l : l1;
}
public static long min(long l, long l1) {
return l1 >= l ? l : l1;
}
public static long round(long l, int i) {
long l1 = 10L;
for(int j = 0; j < i; j++)
l1 *= 10L;
l1 = div(toFP(5L), toFP(l1));
if(l < 0L)
l1 = -l1;
return l + l1;
}
public static long mul(long l, long l1) {
boolean flag = false;
int i = _fbits;
long l2 = _fmask;
if((l & l2) == 0L)
return (l >> i) * l1;
if((l1 & l2) == 0L)
return l * (l1 >> i);
cviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257

if(l < 0L && l1 > 0L || l > 0L && l1 < 0L)


flag = true;
if(l < 0L)
l = -l;
if(l1 < 0L)
l1 = -l1;
for(; max(l, l1) >= 1L << 63 - i; i--) {
l >>= 1;
l1 >>= 1;
l2 >>= 1;
}
long l3 = (l >> i) * (l1 >> i) << i;
long l4 = (l & l2) * (l1 & l2) >> i;
l4 += (l & ~l2) * (l1 & l2) >> i;
l3 = l3 + l4 + ((l & l2) * (l1 & ~l2) >> i) << _fbits - i;
if(l3 < 0L)
throw new ArithmeticException("Overflow");
else
return flag ? -l3 : l3;
}
public static long div(long l, long l1) {
boolean flag = false;
int i = _fbits;
if(l1 == _one)
return l;
if((l1 & _fmask) == 0L)
return l / (l1 >> i);
if(l < 0L && l1 > 0L || l > 0L && l1 < 0L)
flag = true;
if(l < 0L)
l = -l;
if(l1 < 0L)
l1 = -l1;
for(; max(l, l1) >= 1L << 63 - i; i--) {
l >>= 1;
l1 >>= 1;
}
long l2 = (l << i) / l1 << _fbits - i;
return flag ? -l2 : l2;
}
public static long add(long l, long l1) {
return l + l1;
}
public static long sub(long l, long l1) {
return l - l1;
}
cix

Zarko Acimovic

258
259
public static long abs(long l) {
260
if(l < 0L)
261
return -l;
262
else
263
return l;
264
}
265
266
public static long sqrt(long l, int i) {
267
if(l < 0L)
268
throw new ArithmeticException("Bad Input");
269
if(l == 0L)
270
return 0L;
271
long l1 = l + _one >> 1;
272
for(int j = 0; j < i; j++)
273
l1 = l1 + div(l, l1) >> 1;
274
275
if(l1 < 0L)
276
throw new ArithmeticException("Overflow");
277
else
278
return l1;
279
}
280
281
public static long sqrt(long l) {
282
return sqrt(l, 24);
283
}
284
285
//public static long sin(long l) {
286
private static long sinBad(long l) {
287
long l1 = mul(l, div(toFP(180L), PI));
288
l1 %= toFP(360L);
289
if(l1 < 0L)
290
l1 = toFP(360L) + l1;
291
long l2 = l1;
292
if(l1 >= toFP(90L) && l1 < toFP(270L))
293
l2 = toFP(180L) - l1;
294
else
295
if(l1 >= toFP(270L) && l1 < toFP(360L))
296
l2 = -(toFP(360L) - l1);
297
long l3 = l2 / 90L;
298
long l4 = mul(l3, l3);
299
long l5 = mul(mul(mul(mul(0xfffffffffffee21aL >> (int)_flt, l4) +
(0x14594dL >> (int)_flt), l4) - (0xa55b13L >> (int)_flt), l4) + (long)(0x1921f9c >>
(int)_flt), l3);
300
return l5;
301
}
302
303
//public static long asin(long l) {
304
private static long asinBad(long l) {
305
if(abs(l) > _one) {
306
throw new ArithmeticException("Bad Input");
cx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


307
} else {
308
boolean flag = l < 0L;
309
l = abs(l);
310
long l1 = mul(mul(mul(mul(0x236cf >> (int)_flt, l) - (long)(0x92748
>> (int)_flt), l) + (long)(0x15acb4 >> (int)_flt), l) - (long)(0x36d0dd >>
(int)_flt), l) + (long)(0x1921f27 >> (int)_flt);
311
long l2 = PI / 2L - mul(sqrt(_one - l), l1);
312
return flag ? -l2 : l2;
313
}
314
}
315
316
public static long cos(long l) {
317
return sin(PI / 2L - l);
318
}
319
320
public static long acos(long l) {
321
return PI / 2L - asin(l);
322
}
323
324
public static long tan(long l) {
325
return div(sin(l), cos(l));
326
}
327
328
public static long cot(long l) {
329
return div(cos(l), sin(l));
330
}
331
332
public static long atan(long l) {
333
return asin(div(l, sqrt(_one + mul(l, l))));
334
}
335
336
public static long exp(long l) {
337
if(l == 0L)
338
return _one;
339
boolean flag = l < 0L;
340
l = abs(l);
341
int i = (int)(l >> _fbits);
342
long l1 = _one;
343
for(int j = 0; j < i / 4; j++)
344
l1 = mul(l1, e[4] >> (int)_flt);
345
346
if(i % 4 > 0)
347
l1 = mul(l1, e[i % 4] >> (int)_flt);
348
l &= _fmask;
349
if(l > 0L) {
350
long l2 = _one;
351
long l3 = 0L;
352
long l4 = 1L;
353
for(int k = 0; k < 16; k++) {
354
l3 += l2 / l4;
355
l2 = mul(l2, l);
cxi

Zarko Acimovic

356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406

l4 *= k + 1;
if(l4 > l2 || l2 <= 0L || l4 <= 0L)
break;
}
l1 = mul(l1, l3);
}
if(flag)
l1 = div(_one, l1);
return l1;
}
public static long log(long l) {
if(l <= 0L)
throw new ArithmeticException("Bad Input");
long l1 = 0L;
long l2 = 0L;
int i;
for(i = 0; l >= _one << 1; i++)
l >>= 1;
long l4 = (long)i * (long)(0xb17218 >> (int)_flt);
long l5 = 0L;
if(l < _one)
return -log(div(_one, l));
l -= _one;
for(int j = 1; j < 20; j++) {
long l3;
if(l1 == 0L)
l3 = l;
else
l3 = mul(l1, l);
if(l3 == 0L)
break;
l5 += ((j % 2 != 0 ? 1L : -1L) * l3) / (long)j;
l1 = l3;
}
return l4 + l5;
}
public static long pow(long l, long l1) {
boolean flag = l1 < 0L;
long l2 = _one;
l1 = abs(l1);
for(int i = (int)l1 >> _fbits; i-- > 0;)
l2 = mul(l2, l);
if(l2 < 0L)
throw new ArithmeticException("Overflow");
if(l != 0L)
cxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440

l2 = mul(l2, exp(mul(log(l), l1 & _fmask)));


else
l2 = 0L;
if(flag)
return div(_one, l2);
else
return l2;
}
public static long atan2(long l, long l1) {
long l2 = 0L;
if(l1 > 0L)
l2 = atan(div(l, l1));
else
if(l1 < 0L) {
l2 = (l1 >= 0L ? PI : -PI) - atan(abs(div(l, l1)));
} else {
if(l1 == 0L && l == 0L)
throw new ArithmeticException("Bad Input");
l2 = (l >= 0L ? PI : -PI) / 2L;
}
return l2;
}
static {
_one = 0x1000000L;
_pi = 0x3243f6aL;
e = (new long[] {
_one, 0x2b7e151L, 0x763992eL, 0x1415e5bfL, 0x3699205cL
});
PI = _pi;
E = e[1];
}
}

cxiii

Zarko Acimovic
Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

cxiv

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

The problem with class Outlook is Lack of Documentation


Lack Of Documentation Description. How many comments are lacking in a class, considering one class comment
and a comment per method as optimum. Structure and content of the comments are ignored.
http://www.arisa.se/compendium/node121.html

Outlook.java
1
2
3
4
5
6
7
8
9
10
11
12
13

/**
*
* Outlook coordinates work MapBackground, MapObjects and SelectorPoint
*
*/
//import java.util.*;
//import java.io.*;
import javax.microedition.lcdui.*;
public class Outlook {
MapBackground mb;
MapObjects mob;
MapBackgroundFactory mbf;
cxv

Zarko Acimovic

14
SelectorPoint selP;
15
boolean select = false;
16
boolean route = false;
17
boolean startup = false;
18
boolean first = false;
19
Point center = new Point("44.83168","20.445","","","blanco",false);
20
boolean WPselection = false;
21
22
Outlook(MapBackground mb, MapObjects mob, SelectorPoint sp) {
23
24
this.mb = mb;
25
this.mob = mob;
26
this.selP = sp;
27
}
28
29
public void drawOutlook(Graphics g){
30
if(startup==false) {
31
mb.setBackground(center);
32
startup = true;
33
}
34
35
mb.drawMapBackground(g);
36
37
if(first==true && mob.currentSet()==false &&
WPselection==false){
38
selP.selP = new Point(mb.getNewEdge(),false);
39
first=false;
40
}
41
42
if(first==true && mob.currentSet()==true &&
WPselection==false){
43
selP.selectWP(mob.getCurrentPosition().getName());
44
mb.drawMapBackground(g);
45
first=false;
46
}
47
48
/**
49
if(route==false){
50
mob.drawMOB(g,route);
51
if(select==true) selP.drawSelP(g);
52
} else {
53
if(select==true) selP.drawSelP(g);
54
mob.drawMOB(g,route);
55
}*/
56
57
if(select==true) selP.drawSelP(g);
58
mob.drawMOB(g,route);
59
if(select==true) selP.drawCaption(g);
60
61
}
62
cxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

public void ZoomIn(){


boolean zoom = mb.ZoomIn();
if(zoom==true) selP.Zoom();
}
public void ZoomOut(){
boolean zoom = mb.ZoomOut();
if(zoom==true) selP.Zoom();
}
/** Sets map due to Pan transformation
*/
public void setMap(char side){
if(select == false) mb.setMap(side);
if(select == true) selP.setSelectorScreen(side);
}
public void setCanvasWH(int cW,int cH){
mb.setCanvasWH(cW,cH);
}
public void setSelect(){
select = true;
first = true;
//selP.resetBig();
}
public void setWPselection(){
WPselection = true;
}
public void resetSelect(){
select = false;
WPselection = false;
}
public boolean getSelect(){
return select;
}
public void setRoute(){
route = true;
}
public void resetRoute(){
route = false;
}

cxvii

Zarko Acimovic

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)

cxviii

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions
Improvement of LCOM Description

cxix

Zarko Acimovic

The Improvement of LCOM (cf. Lack of Cohesion in Methods 3.2.3) metric is a measure for the number of connected
components in a class. A component are methods of a class sharing (being connected by) instance variables of the class. The
less separate components there are the higher is the cohesion of the methods in the class.
http://www.arisa.se/compendium/node117.html
Lack of Cohesion in Methods Description
The Lack of Cohesion in Methods metric is a measure for the number of not connected method pairs in a class representing
independent parts having no cohesion. It represents the difference between the number of method pairs not having instance
variables in common, and the number of method pairs having common instance variables.
http://www.arisa.se/compendium/node116.html
Number Of local Methods Description
Number of local Methods measures the number of methods locally declared in a class. Inherited methods are not considered.
It is the size of the interface of a class and allows conclusions on its complexity.
http://www.arisa.se/compendium/node94.html
Tight Class Cohesion Description
The Tight Class Cohesion metric measures the cohesion between the public methods of a class. That is the relative number of
directly connected public methods in the class. Classes having a low cohesion indicate errors in the design.
http://www.arisa.se/compendium/node118.html

Point.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

/**
* Class Point represents geographical object
*/

//import java.util.*;
//import java.io.*;
import javax.microedition.lcdui.*;
public class Point {

/** type of Waypoint


* -2 - destination Point
* -1 - current Point
* 0 - free Point
* n - route Point
*/
private int typeID = 0;

/** Point ID
*
*/
private int ID = 0;

cxx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

/** Counter
*/
private static int cnt = 0;

/** Float-point representation of latitude


*/
private long lat;
/** Float-point representation of longitude
*/
private long lon;

/** Degrees of latitude in Integer


*/
private long degLat;
/** Minutes of latitude in Integer
*/
private long minLat;
/** Seconds of latitude in Integer
*/
private long secLat;
/** Side of the world, South or North
*/
//private char sideNS;

/** Degrees of longitude in Integer


*/
private long degLon;
/** Minutes of longitude in Integer
*/
private long minLon;
/** Seconds of longitude in Integer
*/
private long secLon;
/** Side of the world, West or East
*/
//private char sideWE;
/** Total number of latitude seconds
*/
cxxi

Zarko Acimovic

79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129

long totLatSec;
/** Total number of longitude seconds
*/
long totLonSec;
/** Name of the Point
*/
String name = "default";
/** Type of the Point
*/
String type = "default";
/** Distance between this point and point which asks sorting
*/
private long distance;
/** x coordinate of Point on Canvas
*/
private long x = 5;
/** y coordinate of Point on Canvas
*/
private long y = 5;

/** Help variable


*/
long dm1=0;
/** Help variable
*/
long dm2=0;
/** Help variable
*/
long rr=1000;
/** String that describes image
*/
String imgString = "blanco";

/** Regular constructor


* @author Zarko Acimovic
*/
Point(long dlat, long mlat, long slat, //char side1,
long dlon, long mlon, long slon, //char side2,
String n, String t,boolean setNewID){

cxxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


130
degLat=MathFP.toFP(dlat);
131
minLat=MathFP.toFP(mlat);
132
secLat=MathFP.toFP(slat);
133
//sideNS=side1;
134
135
136
degLon=MathFP.toFP(dlon);
137
minLon=MathFP.toFP(mlon);
138
secLon=MathFP.toFP(slon);
139
//sideWE=side2;
140
141
name=n;
142
type=t;
143
144
long sixty=MathFP.toFP("60");
145
146
lat =
MathFP.add(degLat,MathFP.div(MathFP.add(minLat,MathFP.div(secLat,sixty)),sixty));
147
lon =
MathFP.add(degLon,MathFP.div(MathFP.add(minLon,MathFP.div(secLon,sixty)),sixty));
148
149
totLatSec = MathFP.mul(lat,MathFP.toFP("3600"));
150
totLonSec =
MathFP.mul(lon,MathFP.toFP("3600"));
151
152
if(setNewID==true){
153
ID = cnt;
154
cnt++;
155
}
156
typeID = 0; //default type
157
//System.out.println("cnt="+cnt);
158
}
159
160
161
162
Point(long totLatSec,
163
//char s1,
164
long totLonSec,
165
//char s2,
166
String ss1, String ss2, boolean setNewID){
167
lat = MathFP.div(totLatSec, MathFP.toFP("3600"));
168
lon = MathFP.div(totLonSec, MathFP.toFP("3600"));
169
this.name = ss1;
170
this.type = ss2;
171
//this.sideNS = s1;
172
//this.sideWE = s2;
173
174
String latS = MathFP.toString(lat);
175
String lonS = MathFP.toString(lon);
176
177
this.degLat = MathFP.getWholePart(latS);
178
long temp = MathFP.sub(this.lat,this.degLat);
cxxiii

Zarko Acimovic

179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229

temp = MathFP.mul(temp,MathFP.toFP("60"));
this.minLat = MathFP.getWholePart(MathFP.toString(temp));
temp = MathFP.sub(this.lat,this.degLat);
temp = MathFP.mul(temp,MathFP.toFP("60"));
temp = MathFP.sub(temp,minLat);
this.secLat = MathFP.mul(temp,MathFP.toFP("60"));
this.degLon = MathFP.getWholePart(lonS);
temp = MathFP.sub(this.lon,this.degLon);
temp = MathFP.mul(temp,MathFP.toFP("60"));
this.minLon = MathFP.getWholePart(MathFP.toString(temp));
temp = MathFP.sub(this.lon,this.degLon);
temp = MathFP.mul(temp,MathFP.toFP("60"));
temp = MathFP.sub(temp,minLon);
this.secLon = MathFP.mul(temp,MathFP.toFP("60"));
this.totLatSec = totLatSec;
this.totLonSec = totLonSec;
if(setNewID==true){
ID = cnt;
cnt++;
}
typeID = 0; //default type
//System.out.println("cnt="+cnt);
}

Point(Point wp, boolean setNewID) {


degLat=wp.degLat;
minLat=wp.minLat;
secLat=wp.secLat;
//sideNS=wp.sideNS;

degLon=wp.degLon;
minLon=wp.minLon;
secLon=wp.secLon;
//sideWE=wp.sideWE;
name=wp.name;
type=wp.type;
this.lat = wp.lat;
this.lon = wp.lon;
this.totLatSec = wp.totLatSec;
this.totLonSec = wp.totLonSec;
cxxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280

if (setNewID==true){
ID = cnt;
cnt++;
}
typeID = 0; //default type
//System.out.println("cnt="+cnt);
imgString = wp.getImage();
}
Point (String lat,
//char sideNS,
String lon,
//char sideWE,
String name, String type, String img, boolean setNewID){
//this.sideNS = sideNS;
//this.sideWE = sideWE;
this.name = name;
this.type = type;
this.lat = MathFP.toFP(lat);
this.lon = MathFP.toFP(lon);
this.degLat = MathFP.getWholePart(lat);
long temp = MathFP.sub(this.lat,this.degLat);
temp = MathFP.mul(temp,MathFP.toFP("60"));
this.minLat = MathFP.getWholePart(MathFP.toString(temp));
temp = MathFP.sub(this.lat,this.degLat);
temp = MathFP.mul(temp,MathFP.toFP("60"));
temp = MathFP.sub(temp,minLat);
this.secLat = MathFP.mul(temp,MathFP.toFP("60"));
this.degLon = MathFP.getWholePart(lon);
temp = MathFP.sub(this.lon,this.degLon);
temp = MathFP.mul(temp,MathFP.toFP("60"));
this.minLon = MathFP.getWholePart(MathFP.toString(temp));
temp = MathFP.sub(this.lon,this.degLon);
temp = MathFP.mul(temp,MathFP.toFP("60"));
temp = MathFP.sub(temp,minLon);
this.secLon = MathFP.mul(temp,MathFP.toFP("60"));
this.totLatSec = MathFP.mul(this.lat,MathFP.toFP("3600"));
this.totLonSec = MathFP.mul(this.lon,MathFP.toFP("3600"));

if (setNewID==true) {
ID = cnt;
cnt++;
}
cxxv

Zarko Acimovic

281
typeID = 0; //default type
282
//System.out.println("cnt="+cnt);
283
imgString = img;
284
285
}
286
287
288
289
/**
290
Point(String lat, String lon, String name, String type, String
image, boolean setNewID){
291
this.name = name;
292
this.type = type;
293
this.lat = MathFP.toFP(lat);
294
this.lon = MathFP.toFP(lon);
295
296
this.degLat = MathFP.getWholePart(lat);
297
long temp = MathFP.sub(this.lat,this.degLat);
298
temp = MathFP.mul(temp,MathFP.toFP("60"));
299
this.minLat = MathFP.getWholePart(MathFP.toString(temp));
300
301
temp = MathFP.sub(this.lat,this.degLat);
302
temp = MathFP.mul(temp,MathFP.toFP("60"));
303
temp = MathFP.sub(temp,minLat);
304
this.secLat = MathFP.mul(temp,MathFP.toFP("60"));
305
306
this.degLon = MathFP.getWholePart(lon);
307
temp = MathFP.sub(this.lon,this.degLon);
308
temp = MathFP.mul(temp,MathFP.toFP("60"));
309
this.minLon = MathFP.getWholePart(MathFP.toString(temp));
310
311
temp = MathFP.sub(this.lon,this.degLon);
312
temp = MathFP.mul(temp,MathFP.toFP("60"));
313
temp = MathFP.sub(temp,minLon);
314
this.secLon = MathFP.mul(temp,MathFP.toFP("60"));
315
316
this.totLatSec = MathFP.mul(this.lat,MathFP.toFP("3600"));
317
this.totLonSec = MathFP.mul(this.lon,MathFP.toFP("3600"));
318
319
320
if (setNewID==true) {
321
ID = cnt;
322
cnt++;
323
}
324
typeID = 0; //default type
325
326
}*/
327
328
/** Calculates distance between two Points;
329
*
330
* @version advanced
cxxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381

* @return long
*/
public long measureDistance(Point wp){
Coordinates c1 = new Coordinates(this.lat,this.lon);
Coordinates c2 = new Coordinates(wp.lat, wp.lon);
return MathFP.toLong(c1.distance(c2));
}
/** Sets distance
*/
public void setDistance (long dist){
distance = dist;
}
/** Gets distance
* @return long
*/
public long getDistance (){
return distance;
}
/** Returns type of Point
* @return String
*/
public String getType() { return type; }
/** Sets type of Point
* @return String
*/
public void setType(String type) { this.type = type; }
/** Returns name of Point
* @return String
*/
public String getName() { return name; }
/** Sets type of Point
* @return String
*/
public void setName(String name) { this.name = name; }
/** Returns side of the world as String
* @return String
*
*/
//public char getNS(){
//
return sideNS;
//}
/** Returns side of
* @return String

the world as String

cxxvii

Zarko Acimovic

382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432

*
*/
//public char getWE(){
//
return sideWE;
//}
/** Returns degrees of latitiude
*
* @author Zarko Acimovic
* @version initial
*/
public long getDLat(){
return degLat;
}
/** Returns minutes of latitiude
*
* @author Zarko Acimovic
* @version initial
*/
public long getMLat(){
return minLat;
}
/** Returns seconds of latitiude
*
* @author Zarko Acimovic
* @version initial
*/
public long getSLat(){
return secLat;
}
/** Returns degrees of longitude
*
* @author Zarko Acimovic
* @version initial
*/
public long getDLon(){
return degLon;
}
/** Returns minutes of longitude
*
* @author Zarko Acimovic
* @version initial
*/
public long getMLon(){
return minLon;
}

cxxviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


433
/** Returns seconds of longitude
434
*
435
* @author Zarko Acimovic
436
* @version initial
437
* @return int
438
*/
439
public long getSLon(){
440
return secLon;
441
}
442
443
/** Returns latitude as floating point
444
*
445
* @author Zarko Acimovic
446
* @version initial
447
* @return Float-Point
448
*/
449
public long getLat(){
450
return lat;
451
}
452
453
/** Returns longitude as floating point
454
*
455
* @author Zarko Acimovic
456
* @version initial
457
* @return Float-Point
458
*/
459
public long getLon(){
460
return lon;
461
}
462
463
/** Prints Point
464
* @author Zarko Acimovic
465
* @version initial
466
* @return String
467
*/
468
public String toString(){
469
return "ID="+getID()+"\n"+"Longitude:
"+MathFP.toString(this.lon)+" "+MathFP.toString(this.degLon)
+","+MathFP.toString(this.minLon)+","+MathFP.toString(this.secLon)+","+"
x="+this.getX()+
470
"\nLatitude: "+MathFP.toString(this.lat)+"
"+MathFP.toString(this.degLat)+","+MathFP.toString(this.minLat)
+","+MathFP.toString(this.secLat)+","+" y="+this.getY()+" "+this.getName()+"\n"
471
+this.getImage();
472
}
473
474
/** Sets x and y coordinates on Canvas relative to wp
475
* Usually wp is newEdge
476
* @author Zarko Acimovic
477
* @version initial
478
*/
cxxix

Zarko Acimovic

479
public void setXY (Point wp, long pixLon, long pixLat){
480
//System.out.println("----this------------------"+this);
481
//System.out.println("-------newEdge---------------"+wp);
482
///System.out.println("this.getLat()="+MathFP.toString(this.getLat()));
483
//System.out.println("this.getLon()="+MathFP.toString(this.getLon()));
484
///System.out.println("wp.getLat()="+MathFP.toString(wp.getLat()));
485
///System.out.println("wp.getLon()="+MathFP.toString(wp.getLon()));
486
//System.out.println("pixLat="+MathFP.toString(pixLat));
487
///System.out.println("pixLon="+MathFP.toString(pixLon));
488
489
y =
MathFP.div(MathFP.mul(MathFP.sub(wp.getLat(),this.getLat()),MathFP.toFP("3600")),pi
xLat);
490
y = MathFP.toLong(y);
491
492
x =
MathFP.div(MathFP.mul(MathFP.sub(this.getLon(),wp.getLon()),MathFP.toFP("3600")),pi
xLon);
493
x = MathFP.toLong(x);
494
}
495
496
/** Checks if this Point is beetwen wp1 and wp2
497
*
498
* @version initial
499
* @return boolean
500
*/
501
public boolean check(Point wp1, Point wp2){
502
503
long lim1Lat = wp1.getLat();
504
long lim1Lon = wp1.getLon();
505
long lim2Lat = wp2.getLat();
506
long lim2Lon = wp2.getLon();
507
508
long bigLat;
509
long miniLat;
510
long bigLon;
511
long miniLon;
512
513
if (lim1Lat>lim2Lat){
514
bigLat=lim1Lat;
515
miniLat=lim2Lat;
516
} else {
517
bigLat=lim2Lat;
518
miniLat=lim1Lat;
519
}
520
521
if (lim1Lon>lim2Lon){
cxxx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572

bigLon=lim1Lon;
miniLon=lim2Lon;
} else {
bigLon=lim2Lon;
miniLon=lim1Lon;
}
if (miniLat<this.getLat() && this.getLat()<bigLat &&
miniLon<this.getLon() && this.getLon()<bigLon){
return true;
} else {
return false;
}
}

/** Returns x-position of Point on Canvas


*
* @author Zarko Acimovic
* @version initial
* @return long
*/
public long getX() {return x; }
/** Returns y-position of Point on Canvas
*
* @author Zarko Acimovic
* @version initial
* @return long
*/
public long getY() {return y; }
public int getXX() {
Long l = new Long(x);
int xx = Integer.parseInt(l.toString());
return xx;
}
public int getYY() {
Long l = new Long(y);
int yy = Integer.parseInt(l.toString());
return yy;
}
/** Adds inc on x
*/
public void addX(long inc ){
this.x+=inc;
}
cxxxi

Zarko Acimovic

573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623

/** Substracts dec from x


*/
public void subX(long dec){
this.x-=dec;
}
/** Adds inc on y
*/
public void addY(long inc){
this.y+=inc;
}
/** Substracts dec from y
*/
public void subY(long dec){
this.y-=dec;
}

/** Returns total number of lat-seconds for Point


*
* @author Zarko Acimovic
* @version initial
* @return long
*/
public long getLatSec() {
return totLatSec;
}
/** Returns total number of lon-seconds for Point
*
* @author Zarko Acimovic
* @version initial
* @return long
*/
public long getLonSec() {
return totLonSec;
}
/** Sets x-position of Point on screen
*/
public void setX(long x){
this.x=x;
}
/** Sets y-position of Point on screen
*/
public void setY(long y){
this.y=y;
}
cxxxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


624
625
/** Sets ID of Point
626
* 0 - simple Point
627
* 1 - current Point
628
* 2 - destination Point
629
*/
630
public void setTypeID(int i){
631
typeID = i;
632
}
633
634
/** Returns ID of Point
635
* 0 - simple Point
636
* 1 - current Point
637
* 2 - destination Point
638
*/
639
public int getTypeID(){
640
return typeID;
641
}
642
643
public int getID(){
644
return ID;
645
}
646
647
648
/** String that represents image
649
*/
650
public void setImage(String s){
651
imgString = s;
652
}
653
654
/** Returns name of the image
655
*/
656
public String getImage(){
657
return imgString;
658
}
659
660
public void drawPoint(Graphics g, Point newEdge, long pixLat, long
pixLon, long zoomLv){
661
662
this.setXY(newEdge,pixLon,pixLat);
663
if(this.getImage().equals("route")){
664
g.fillRect(this.getXX()-3,this.getYY()-3,6,6);
665
}
666
if(this.getImage().equals("blanco")){
667
g.fillRect(this.getXX()-3,this.getYY()-3,6,6);
668
if (this.getName().equals("current"))
669
g.drawString(this.getName(),this.getXX()-25,this.getYY()
+5,0);
670
671
if (this.getName().equals("dest"))

cxxxiii

Zarko Acimovic

672
g.drawString(this.getName(),this.getXX()-18,this.getYY()
+11,0);
673
674
if (this.getName().equals("GPS.txt"))
675
g.drawString(this.getName(),this.getXX()-18,this.getYY()
+11,0);
676
677
if (this.getName().equals("Mika.txt"))
678
g.drawString(this.getName(),this.getXX()-18,this.getYY()
+11,0);
679
680
if (this.getName().equals("GPS"))
681
g.drawString(this.getName(),this.getXX()-18,this.getYY()
+11,0);
682
683
if (this.getName().equals("Mika"))
684
g.drawString(this.getName(),this.getXX()-18,this.getYY()
+11,0);
685
686
if (this.getName().equals("Str8"))
687
g.drawString(this.getName(),this.getXX()-18,this.getYY()
+11,0);
688
}
689
690
if(!this.getImage().equals("blanco") && !
this.getImage().equals("route")){
691
Image img = null;
692
try{
693
img = Image.createImage(this.getImage());
694
}catch(Exception e){}
695
g.drawImage(img,this.getXX()-3,this.getYY()-3,0);
696
//g.drawString(this.getName(),this.getXX()15,this.getYY()+11,0);
697
}
698
}
699
700
public void setLat(String s){
701
lat = MathFP.toFP(s);
702
}
703
704
public void setLon(String s){
705
lon = MathFP.toFP(s);
706
}
707
708 }

cxxxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)

cxxxv

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Coupling Between Objects (CBO)


Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

PVector is OK.
PVector.java

1
2
3
4
5
6
7
8

/**
*
* PVector enables drawing and sorting of points by name and distance
*/

import java.util.*;
//import java.io.*;
cxxxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

import javax.microedition.lcdui.*;
public class PVector extends Vector {
/** ID of WP Vector
* 0 - simple Vector
* 1 - route
*/
private int ID = 0;
private static int cnt = 0;
private String name ="";
boolean visible = false;

PVector(String name,boolean route){


super();
if (route==true) {
this.name = name;
cnt++;
ID = cnt;
} else {
ID = 0;
}
}
PVector(Vector v, boolean route){
super();
if (route==true) {
ID = cnt;
cnt++;
} else {
ID = 0;
}
for (int i=0; i<v.size(); i++){
this.addElement(v.elementAt(i));
}
}

/** Returns vector of Points sorted by distance


* from Point wp in ascending order
*
* @version initial
* @return Vector
*/

cxxxvii

Zarko Acimovic

60
public Vector sortAscending(Point wp){
61
int size = this.size();
62
long[] distances = new long [size];
63
for (int i=0; i<size; i++) {
64
Point whs = (Point)this.elementAt(i); //from
warehouse
65
distances[i]=whs.measureDistance(wp);
66
whs.setDistance(distances[i]);
67
}
68
Hashtable ht = new Hashtable();
69
for (int i=0; i<size; i++){
70
ht.put(new Long(distances[i]),this.elementAt(i));
71
}
72
HeapSorter hp = new HeapSorter();
73
hp.heapsort(distances);
74
Vector sorted = new Vector();
75
for (int i=0;i<size;i++) sorted.addElement(ht.get(new
Long(distances[i])));
76
return sorted;
77
}
78
79
public String[] sortByName(){
80
//System.out.println("wwwwww");
81
//int size = this.size();
82
//long[] firstChars = new long[size];
83
//Hashtable ht = new Hashtable();
84
String names[] = new String[this.size()];
85
for(int i=0; i<this.size(); i++){
86
Point whs = (Point) this.elementAt(i);
87
//firstChars[i] = (long) whs.getName().charAt(0);
88
//ht.put(new
Long(firstChars[i]),this.elementAt(i));
89
names[i]=whs.getName();
90
}
91
HeapSorter hp = new HeapSorter();
92
hp.heapsort(names);
93
//Vector sorted = new Vector();
94
//for (int i=0;i<size;i++) sorted.addElement(ht.get(new
Long(firstChars[i])));
95
//System.out.println("wwwwww\n"+sorted);
96
return names;
97
}
98
99
/** Returns vector of Points sorted by distance
100
* from WayPint wp in descending order
101
*
102
* @version initial
103
* @return Vector
104
*/
105
public Vector sortDescending(Point wp){
106
int size = this.size();
cxxxviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


107
Vector temp1 = new Vector();
108
Vector temp2 = new Vector();
109
temp1 = this.sortAscending(wp);
110
for (int i=0; i<size;i++ )
temp2.addElement(temp2.elementAt(size-i));
111
return temp2;
112
}
113
114
/** Return vector of specific Points of type 'type'
115
* sorted by distance in ascending order from Point wp
116
*
117
* @version initial
118
* @return Vector
119
*/
120
public Vector sortAscending (Point wp, String type){
121
int size = this.size();
122
long[] distances = new long [size];
123
for (int i=0; i<size; i++){
124
Point whs = (Point)this.elementAt(i); //from
warehouse
125
distances[i]=wp.measureDistance(whs);
126
}
127
Hashtable ht = new Hashtable();
128
for (int i=0; i<size; i++){
129
ht.put(new Long(distances[i]),this.elementAt(i));
130
}
131
HeapSorter hp = new HeapSorter();
132
hp.heapsort(distances);
133
Vector sorted = new Vector();
134
for (int i=0;i<size;i++) {
135
Point wpnt = (Point)ht.get(new Long(distances[i]));
136
if (wp.getType().equals(type))
sorted.addElement(wpnt);
137
}
138
return sorted;
139
}
140
141
/** Prints array of Points
142
* @version initial
143
* @return String
144
*/
145
public String toString(){
146
String str="";
147
int size = this.size();
148
for (int i=0; i<size; i++){
149
Point wp =(Point)this.elementAt(i);
150
str += wp.toString();
151
}
152
return str;
153
}
154
cxxxix

Zarko Acimovic

155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205

/**Returns all Points in rectangle


* defined by wp1 and wp2 as points
* of diagonal
*
* @version initial
* @return Vector
*/
public Vector getPoints(Point wp1, Point wp2){
Vector v = new Vector();
long
long
long
long

lim1Lat
lim1Lon
lim2Lat
lim2Lon

long
long
long
long

bigLat;
miniLat;
bigLon;
miniLon;

=
=
=
=

wp1.getLat();
wp1.getLon();
wp2.getLat();
wp2.getLon();

if (lim1Lat>lim2Lat){
bigLat=lim1Lat;
miniLat=lim2Lat;
} else {
bigLat=lim2Lat;
miniLat=lim1Lat;
}
if (lim1Lon>lim2Lon){
bigLon=lim1Lon;
miniLon=lim2Lon;
} else {
bigLon=lim2Lon;
miniLon=lim1Lon;
}
for (int i=0; i<this.size();i++){
Point wp = (Point)this.elementAt(i);
if (miniLat<wp.getLat() && wp.getLat()<bigLat &&
miniLon<wp.getLon() && wp.getLon()<bigLon){
v.addElement(wp);
}
}
//System.out.println("Vektor je\n"+v);
return v;
}
/** Merges two vectors
*
* @version initial
*/
cxl

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


206
public void mergeWith(Vector v){
207
for (int i=0; i<v.size(); i++ ){
208
this.addElement(v.elementAt(i));
209
}
210
}
211
212
/** Deletes Point
213
*
214
* @author Zarko Acimovic
215
* @version initial
216
*/
217
public int deleteWP1(Point wp, int pixLat, int pixLon){
218
//System.out.println("Unutar DELETE");
219
//System.out.println(this.size());
220
Vector toDelete = new Vector();
221
long pixLat1 = MathFP.toLong(pixLat);
222
long pixLon1 = MathFP.toLong(pixLon);
223
224
for (int i=0; i<this.size(); i++){
225
Point wp2 = (Point)this.elementAt(i);
226
if ( Math.abs(wp2.getLatSec()wp.getLatSec())<5*pixLat1 &&
227
Math.abs(wp2.getLonSec()wp.getLonSec())<5*pixLon1 ){
228
toDelete.addElement(new Integer(i));
229
}
230
}
231
232
if(toDelete.size()>1 || toDelete.size()==0) {
233
return -1;
234
}
235
else {
236
Integer k = (Integer)toDelete.elementAt(0);
237
int c = k.intValue();
238
this.removeElementAt(c);
239
return c;
240
}
241
}
242
243
/** Edits Point
244
*
245
* @author Zarko Acimovic
246
* @version not yet implemented
247
*/
248
public void editWP(Point wp){
249
}
250
251
252
/** Sets ID of WPVector
253
* 0 - simple WPVector
254
* n - route
cxli

Zarko Acimovic

255
*
256
*/
257
public void setID(int i){
258
ID = i;
259
}
260
261
/** Returns ID of WPVector
262
* 0 - simple WPVector
263
* 1 - route
264
*/
265
public int getID(){
266
return ID;
267
}
268
269
/** Returns name WPVector
270
*/
271
public String getName(){
272
return name;
273
}
274
275
/** Returns name WPVector
276
*/
277
public void setName(String s){
278
name = s;
279
}
280
281
public void setVisible(){
282
visible = true;
283
}
284
285
public void resetVisible(){
286
visible = false;
287
}
288
289
public boolean getVisible(){
290
return visible;
291
}
292
293
public void drawVector(Graphics g, boolean route, Point newEdge, long
pixLon, long pixLat, long zoomL){
294
/////System.out.println("route="+route);
295
/////System.out.println("routeVisible="+this.getVisible());
296
if(route==true){
297
if(this.getVisible()==true){
298
if(this.size()==1){
299
Point wp1 = (Point) this.elementAt(0);
300
wp1.drawPoint(g,newEdge,pixLat,pixLon,zoomL);
301
} else {
302
for(int j=0; j<this.size()-1; j++){

cxlii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


303
Point wp1 = (Point)
this.elementAt(j);
304
Point wp2 = (Point)
this.elementAt(j+1);
305
//wp1.setXY(newEdge,pixLon,pixLat);
306
//wp2.setXY(newEdge,pixLon,pixLat);
307
wp1.drawPoint(g,newEdge,pixLat,pixLon,zoomL);
308
wp2.drawPoint(g,newEdge,pixLat,pixLon,zoomL);
309
g.drawLine(wp1.getXX(),wp1.getYY(),wp2.getXX(),wp2.getYY());
310
}
311
}
312
}
313
} else {
314
for(int i=0; i<this.size(); i++){
315
Point wp = (Point) this.elementAt(i);
316
wp.drawPoint(g,newEdge,pixLat,pixLon,zoomL);
317
}
318
}
319
320
}
321
322
323 };

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity

cxliii

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)
cxliv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

SelectorPoint is OK.
SelectorPoint.java

1 /**
2
* SelectorPoint controls selection and identification of geographical
object
3
*/
4 import java.util.*;
5 //import java.io.*;
6 import javax.microedition.lcdui.*;
7
8 public class SelectorPoint{
9
MapBackground mb;
10
MapObjects mob;
11
Point selP;
12
int m = 255;
13
int n = 200;
14
int s = 0;
15
boolean colorSet=false;
16
boolean big = false;
17
18
SelectorPoint(MapBackground mb, MapObjects mob){
19
20
this.selP = mob.getCurrentPosition();
21
this.mb = mb;
22
this.mob = mob;
23
}
24
25
/** Sets selector point on Screen due to user's left/right , up/down
commands
26
*/
27
public void setSelectorScreen(char s){
28
29
30
if(s=='r'){

cxlv

Zarko Acimovic

31
if (selP.getX()>0 && selP.getX()<mb.getCanvasWidth())
selP.addX(5);
32
if (selP.getX()>mb.getCanvasWidth()-5) {
33
// calculation of (deg,min,sec) for Selector before
panning
34
//dakle ja pre panovanja izracunam svetske
koordinate selektora,
35
//da bi znao gde je on stvarno, pa kad panujem mapu
(a samim
36
//tim i promenim njen newEdge onda odredjujem i
relativni polozaj
37
//selektorske tacke u odnosu na taj newEdge (jasno
je da pri panovanju mape
38
//nije doslo do promene svetskih koordinata
selektora)
39
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
40
//Paning
41
mb.setMap(s);
42
mob.setDrawablePoints();
43
//calculation of new Selector position on panned
map
44
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
45
46
}
47
}
48
if(s=='l'){
49
if (selP.getX()>6) selP.subX(5);
50
if (selP.getX()<=6) {
51
// calculation of (deg,min,sec) for Selector before
panning
52
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
53
//Paning
54
mb.setMap(s);
55
mob.setDrawablePoints();
56
//calculation of new Selector position on panned
map
57
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
58
}
59
}
60
if(s=='d'){
61
if (selP.getY()>0 && selP.getY()<mb.getCanvasHeight()-5)
selP.addY(5);
62
if (selP.getY()>=(mb.getCanvasHeight()-5)) {
63
//calculation of (deg,min,sec) for Selector before
panning
64
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
cxlvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


65
66
67
68

//Paning
mb.setMap(s);
mob.setDrawablePoints();
//calculation of new Selector position on panned

map
69
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
70
71
}
72
}
73
if(s=='u'){
74
if (selP.getY()>6) selP.subY(5);
75
if (selP.getY()<=6) {
76
//calculation of (deg,min,sec) for Selector before
panning
77
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
78
//Paning
79
mb.setMap(s);
80
mob.setDrawablePoints();
81
//calculation of new Selector position on panned
map
82
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
83
84
}
85
}
86
87
Point WP = this.getSelectedWP();
88
89
if (!WP.getName().equals("selector") && colorSet==false) {
90
setColor();
91
setBig();
92
}
93
if (WP.getName().equals("selector") && colorSet==true) {
94
resetColor();
95
resetBig();
96
}
97
//if (!WP.getImage().equals("blanco") && !
WP.getImage().equals("route") && big==false) setBig();
98
//if ((WP.getImage().equals("blanco")||
WP.getImage().equals("route")) && big==true) resetBig();
99
}
100
101
102
103
/** When selector is moved we only update its (x,y) 'descriptors',
104
* so when map has to be panned we need to find out (lat,lon) pair
105
* for selector on old screen and adjust its position (x',y') on new
screen
106
* in a way that (lat,lon) is unchanged
cxlvii

Zarko Acimovic

107
*/
108
public void setSelectorWorld(Point edge, long pixLon, long pixLat){
109
110
// pamtim trenutno x i y
111
long tx = selP.getX();
112
long ty = selP.getY();
113
114
// azuriram svetske kordinate
115
long dLatSec = MathFP.mul(pixLat,MathFP.toFP(selP.getY()));
116
long dLonSec = MathFP.mul(pixLon,MathFP.toFP(selP.getX()));
117
118
selP = new Point(MathFP.sub(edge.getLatSec(),dLatSec),
119
MathFP.add(edge.getLonSec(),dLonSec),"","",false);
120
121
// vracam trenutno x i y
122
selP.setX(tx);
123
selP.setY(ty);
124
}
125
126
/** Returns copy of SELECTOR Point
127
* @return Point
128
*/
129
public Point getSelector(){
130
this.setSelectorWorld(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
131
Point copy = new Point(selP,true);
132
133
copy.setName("");
134
return copy;
135
}
136
137
/** Returns x-coordinate of selector
138
* @return long
139
*/
140
long getSelX(){
141
return selP.getX();
142
}
143
144
/** Returns y-coordinate of selector
145
* @return long
146
*/
147
long getSelY(){
148
return selP.getY();
149
}
150
151
/** Returns user selected Point
152
* @return Point
153
*/
154
public Point getSelectedWP(){
155
Vector v = mob.getDrawablePoints();
cxlviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


156
Point ret = new Point(0,0,"selector","s",false);
157
for(int i=0; i<v.size(); i++){
158
Point fWhs = (Point) v.elementAt(i);
159
if( Math.abs(fWhs.getX()-selP.getX())<5 &&
160
Math.abs(fWhs.getY()-selP.getY())<5 ) {
161
ret=fWhs;
162
i=1000;
163
}
164
}
165
return ret;
166
}
167
168
169
/** Returns user selected Point with name s
170
* @return Point
171
*/
172
public void selectWP(String s) {
173
174
int len = s.length();
175
int blanco = s.indexOf('_');
176
if(blanco!=-1){
177
String idS = s.substring(blanco+1,len);
178
s = s.substring(0,blanco);
179
s = compact(s);
180
}
181
182
int blank = s.indexOf(' ');
183
if(blank!=-1 && s.substring(blank+1,s.length()).equals("current"))
s = s.substring(0,blank);
184
185
Point look4 = null;
186
PVector freeWPV = mob.getFreeWaypoints();
187
188
int k=-2;
189
for(int i=0; i<freeWPV.size(); i++){
190
Point wp = (Point) freeWPV.elementAt(i);
191
if(s.equals(wp.getName())){
192
k=i;
193
look4 = (Point) freeWPV.elementAt(k);
194
i=1000;
195
}
196
}
197
198
if(k==-2){
199
Point cP = mob.getCurrentPosition();
200
if(s.equals(cP.getName())) {
201
look4=cP;
202
k=-3;
203
}
204
}
205
if(k==-2){
cxlix

Zarko Acimovic

206
Point dP = mob.getDestinationPosition();
207
if(s.equals(dP.getName())) {
208
look4=dP;
209
k=-4;
210
}
211
}
212
213
if(k==-2){
214
Vector routes = mob.getRoutes();
215
for(int i=0; i<routes.size(); i++){
216
PVector rt = (PVector) routes.elementAt(i);
217
for(int j=0; j<rt.size(); j++){
218
Point wp = (Point)rt.elementAt(j);
219
System.out.println(wp);
220
if(wp.getName().equals(s)){
221
k=j;
222
look4=(Point)rt.elementAt(j);
223
i=1000;
224
j=1000;
225
}
226
}
227
}
228
}
229
230
this.selP = new Point(look4,false);
231
232
mb.setBackground(look4);
233
234
mob.setDrawablePoints();
235
selP.setXY(mb.getNewEdge(),mb.getPixLon(), mb.getPixLat());
236
237
if (!selP.getImage().equals("blanco") && big==false) setBig();
238
if (selP.getImage().equals("blanco") && big==true) resetBig();
239
240
this.setColor();
241
}
242
243
/** Deletes selected Point
244
* Returns -4 if current Point is deleted
245
* Returns -3 if destination Point is deleted
246
* Returns -2 if free Point deleted
247
* Returns -1 if more then one Point is selected
248
* Returns 0 if none Point is selected
249
* Returns n if n-th Point in route deleted
250
*/
251
public int deleteWP(){
252
int ret = 0;
253
254
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
255
cl

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


256
Vector temp1 = new Vector();
257
PVector fWP = mob.getFreeWaypoints();
258
for (int i=0; i<fWP.size(); i++){
259
Point fwp = (Point)fWP.elementAt(i);
260
if( Math.abs(selP.getX()-fwp.getX())<5 &&
Math.abs(selP.getY()-fwp.getY())<5 ){
261
temp1.addElement(new Integer(i));
262
}
263
}
264
265
Vector temp2 = new Vector();
266
Vector Routes = mob.getRoutes();
267
for (int j=0; j<Routes.size(); j++){
268
PVector vR = (PVector) Routes.elementAt(j);
269
for (int k=0; k<vR.size(); k++){
270
Point wpR = (Point)vR.elementAt(k);
271
if( Math.abs(selP.getX()-wpR.getX())<5 &&
Math.abs(selP.getY()-wpR.getY())<5 ) {
272
temp2.addElement(new
DelRoute(k,wpR.getTypeID()));
273
}
274
}
275
}
276
277
DelRoute drt = null;
278
if(temp2.size()>0){
279
drt = (DelRoute) temp2.elementAt(0);
280
}
281
282
if ( (temp1.size()+temp2.size())> 1 ) ret=-1;
283
if ( (temp1.size()+temp2.size())==0 ) ret=0;
284
if ( temp1.size()==1 ) {
285
Integer k = (Integer) temp1.elementAt(0);
286
int d = k.intValue();
287
fWP.removeElementAt(d);
288
ret=-2;
289
}
290
if( temp2.size()==1 ){
291
DelRoute dr = (DelRoute) temp2.elementAt(0);
292
PVector vR = (PVector) Routes.elementAt(dr.getRouteID()-1);
293
vR.removeElementAt(dr.getIndex());
294
ret=dr.getIndex();
295
}
296
297
Point cp = mob.getCurrentPosition();
298
if( Math.abs(selP.getX()-cp.getX())<5 &&
299
Math.abs(selP.getY()-cp.getY())<5 ) {
300
mob.resetCurrentPosition();
301
ret= -4;
302
}
303
cli

Zarko Acimovic

304
Point dp = mob.getDestinationPosition();
305
306
if( Math.abs(selP.getX()-dp.getX())<5 &&
307
Math.abs(selP.getY()-dp.getY())<5 ) {
308
mob.resetDestinationPosition();
309
ret= -3;
310
}
311
312
resetColor();
313
314
return ret;
315
}
316
317
318
/** Action that must be taken with Selector when Zoom In/Out
319
*/
320
public void Zoom(){
321
this.setSelectorWorld(mb.getPreviousEdge(),
mb.getPreviousPixLon(),mb.getPreviousPixLat());
322
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
323
while (selP.getX()>mb.getCanvasWidth()) {
324
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
325
mb.setMap('r');
326
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
327
}
328
while (selP.getY()>mb.getCanvasHeight()) {
329
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
330
mb.setMap('d');
331
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
332
}
333
while (selP.getX()<0){
334
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
335
mb.setMap('l');
336
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
337
}
338
while (selP.getY()<0) {
339
this.setSelectorWorld(mb.getNewEdge(),
mb.getPixLon(),mb.getPixLat());
340
mb.setMap('u');
341
selP.setXY(mb.getNewEdge(),mb.getPixLon(),mb.getPixLat());
342
}
343
}
344
345
346
/** Draws selector point
347
*
348
public void drawSelPOld(Graphics g){
349
long zl = mb.getZoomLevel()+1;
clii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


350
Long zzl = new Long(zl);
351
int zoomL = Integer.parseInt(zzl.toString());
352
g.setColor(0,0,0);
353
g.drawRect(selP.getXX()-6,selP.getYY()-3,12,6);
354
g.setColor(m,n,s);
355
g.fillRect(selP.getXX()-3,selP.getYY()-6,6,12);
356
g.setColor(0,0,0);
357
}
358
359
/** Draws selector point
360
*
361
public void drawSelPOld1(Graphics g){
362
long zl = mb.getZoomLevel()+1;
363
Long zzl = new Long(zl);
364
int zoomL = Integer.parseInt(zzl.toString());
365
g.setColor(m,n,s);
366
g.fillRect(selP.getXX()-8,selP.getYY()-4,16,8);
367
g.fillRect(selP.getXX()-4,selP.getYY()-8,8,16);
368
g.setColor(0,0,0);
369
g.drawRect(selP.getXX()-8,selP.getYY()-4,16,8);
370
g.drawRect(selP.getXX()-4,selP.getYY()-8,8,16);
371
g.setColor(m,n,s);
372
g.fillRect(selP.getXX()-7,selP.getYY()-3,15,7);
373
g.fillRect(selP.getXX()-3,selP.getYY()-7,7,15);
374
375
g.setColor(0,0,0);
376
377
378
}
379
380
/** Draws selector point
381
*
382
public void drawSelPobsolete(Graphics g){
383
//long zl = mb.getZoomLevel()+1;
384
//Long zzl = new Long(zl);
385
//int zoomL = Integer.parseInt(zzl.toString());
386
if(big==false){
387
g.setColor(m,n,s);
388
g.fillRect(selP.getXX()-8,selP.getYY()-4,15,7);
389
g.fillRect(selP.getXX()-4,selP.getYY()-8,7,5);
390
g.setColor(0,0,0);
391
g.drawRect(selP.getXX()-8,selP.getYY()-4,15,7);
392
g.drawRect(selP.getXX()-4,selP.getYY()-8,7,15);
393
g.setColor(m,n,s);
394
g.fillRect(selP.getXX()-7,selP.getYY()-3,14,6);
395
g.fillRect(selP.getXX()-3,selP.getYY()-7,6,14);
396
} else {
397
g.setColor(m,n,s);
398
g.fillRect(selP.getXX()-13,selP.getYY()-5,33,16);
399
g.fillRect(selP.getXX()-5,selP.getYY()-13,16,22);///umesto
16,32 sad je 16,25
cliii

Zarko Acimovic

400
g.setColor(0,0,0);
401
g.drawRect(selP.getXX()-13,selP.getYY()-5,33,16);
402
g.drawRect(selP.getXX()-5,selP.getYY()-13,16,22);///umesto
16,32 sad je 16,25
403
g.setColor(m,n,s);
404
g.fillRect(selP.getXX()-12,selP.getYY()-4,32,15);
405
g.fillRect(selP.getXX()-4,selP.getYY()-12,15,22);
406
407
//g.drawString(selP.getName(),selP.getXX()-15,selP.getYY()
+11,0);
408
}
409
g.setColor(0,0,0);
410
if (!this.getSelectedWP().getName().equals("selector"))
g.drawString(this.getSelectedWP().getName(),this.getSelectedWP().getXX()15,this.getSelectedWP().getYY()+11,0);
411
}*/
412
413
public void drawSelP(Graphics g){
414
int length=0;
415
416
//g.setColor(m,n,s);
417
g.setColor(255,180,0);
418
g.fillRect(selP.getXX()-8,selP.getYY()-4,15,7);
419
g.fillRect(selP.getXX()-4,selP.getYY()-8,7,5);
420
g.setColor(0,0,0);
421
g.drawRect(selP.getXX()-8,selP.getYY()-4,15,7);
422
g.drawRect(selP.getXX()-4,selP.getYY()-8,7,15);
423
//g.setColor(m,n,s);
424
g.setColor(255,180,0);
425
g.fillRect(selP.getXX()-7,selP.getYY()-3,14,6);
426
g.fillRect(selP.getXX()-3,selP.getYY()-7,6,14);
427
/**
428
if(big==true){
429
g.setColor(m,n,s);
430
//g.drawRect(selP.getXX()-4,selP.getYY()-4,15,15);
431
//g.drawRect(selP.getXX()-5,selP.getYY()-5,17,17);
432
//g.drawRect(selP.getXX()-6,selP.getYY()-6,19,19);
433
String name = this.getSelectedWP().getName();
434
length = name.length();
435
g.fillRect(selP.getXX()-4*length-2,selP.getYY()
+12,8*length+2,14);
436
}
437
g.setColor(0,0,0);
438
if (!this.getSelectedWP().getName().equals("selector"))
g.drawString(this.getSelectedWP().getName(),selP.getXX()-4*length,selP.getYY()
+13,0);
439
*/
440
}
441
442
public void drawCaption(Graphics g){
443
int length=0;
cliv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


444
if(big==true){
445
g.setColor(m,n,s);
446
//g.drawRect(selP.getXX()-4,selP.getYY()-4,15,15);
447
//g.drawRect(selP.getXX()-5,selP.getYY()-5,17,17);
448
//g.drawRect(selP.getXX()-6,selP.getYY()-6,19,19);
449
String name = this.getSelectedWP().getName();
450
length = name.length();
451
g.fillRect(selP.getXX()-4*length-2,selP.getYY()
+12,8*length+2,14);
452
//if (!this.getSelectedWP().getName().equals("selector"))
g.drawString(this.getSelectedWP().getName(),selP.getXX()-4*length,selP.getYY()
+13,0);
453
g.setColor(0,0,0);
454
if (!this.getSelectedWP().getName().equals("selector"))
g.drawString(this.getSelectedWP().getName(),selP.getXX()-4*length,selP.getYY()
+13,0);
455
}
456
457
}
458
459
460
461
/** Sets current position
462
*/
463
public void setCurrent(MapObjects mob){
464
Point wp = this.getSelectedWP();
465
mob.setCurrentPosition(wp);
466
}
467
468
/** Sets destination position
469
*/
470
public void setDest(MapObjects mob){
471
Point wp = this.getSelectedWP();
472
mob.setDestinationPosition(wp);
473
}
474
475
public void setColorOld(){
476
s = 0;
477
colorSet=true;
478
}
479
480
public void setColor(){
481
m=255;
482
n=255;
483
s=0;
484
colorSet=true;
485
}
486
487
public void resetColorOld(){
488
s = 255;
489
colorSet=false;
clv

Zarko Acimovic

490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527

}
public void resetColor(){
m=255;
n=180;
s=0;
colorSet=false;
}
public void setBig(){
big=true;
}
public void resetBig(){
big=false;
}
/**
*
*
*
*/

Blanco characters are possible to occur in names of pictures;


Integer representations of blanko characters are 9 and 32
Also, characters with integer representation between 0 and 33
can not be printed out in WSDD console, so I excluded them too
public String compact(String s){
int k = s.length();
char[] d = s.toCharArray();
String ret = "";
for(int i=0; i<d.length; i++){
int temp = (int)d[i];
if(temp>32) ret+=d[i];
}
int kk = ret.length();
if (kk!=k) System.out.println("Bugger is: "+s);
return ret;
}

clvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)

clvii

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Efferent Coupling (Ce)


Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

SimpleTextForm has problem with Locality of Data. Locality of Data Description


The Locality of Data metric relates the amount of data being local the class to the total amount of data used by the
class. This relates to the quality of abstraction embodied by the class and allows conclusions on the reuse potential
of the class and testability. http://www.arisa.se/compendium/node112.html

SimpleTextForm.java

1
2
3
4
5
6
7
8
9
10
11

/**
* Simple text form
*/

import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;

//import java.io.*;

clviii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62

//import java.util.*;

public class SimpleTextForm extends Form{


/** Name of waypoint
*/
TextField nameWP;
/** Type of waypoint
*/
TextField typeWP;
String[] str = new String[2];
ChoiceGroup chgr;

/** Creates new form


*/
SimpleTextForm(boolean createChgr){
super("Data Input");
nameWP = new TextField("Name","",8,0);
typeWP = new TextField("Type","",8,0);
this.append(nameWP);
this.append(typeWP);
if(createChgr==true){
str[0] = "Sysnchronized Following";
str[1] = "Out of Sync";
chgr = new ChoiceGroup("",1,str,null);
this.append(chgr);
}
}
/** Returns the name of waypoint
* @return String
*/
public String getName(){
return nameWP.getString();
}
/** Returns the type of waypoint
* @return String
*/
public String getType(){
return typeWP.getString();
}
/** Sets the name of waypoint
*/
clix

Zarko Acimovic

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

public void setName(String s){


nameWP.setString(s);
}
public void setLabel(String s){
nameWP.setLabel(s);
}
public void setLabel2(String s){
typeWP.setLabel(s);
}
/** Sets the type of waypoint
*/
public void setType(String s){
typeWP.setString(s);
}
public int getSelected(){
return chgr.getSelectedIndex();
}
}

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)

clx

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation

clxi

Zarko Acimovic

Lack Of Documentation (LOD)


Code Conventions

Locality of Data. Description


The Locality of Data metric relates the amount of data being local the class to the total amount of data used by the
class. This relates to the quality of abstraction embodied by the class and allows conclusions on the reuse potential
of the class and testability. http://www.arisa.se/compendium/node112.html
Tight Class Cohesion Description
The Tight Class Cohesion metric measures the cohesion between the public methods of a class. That is the
relative number of directly connected public methods in the class. Classes having a low cohesion indicate errors
in the design. http://www.arisa.se/compendium/node118.html
TextForm.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33

/**
* Text form
*/

import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;

//import java.io.*;
//import java.util.*;

public class TextForm extends Form{


/** Name of waypoint
*/
TextField nameWP;
/** Type of waypoint
*/
TextField typeWP;
/** ChoiceGroup of categories
*/
ChoiceGroup chgr;
TextField lat;
TextField lon;

/** Creates new form

clxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

*/
TextForm(String[] s, boolean first){
super("Data Input");
nameWP = new TextField("Name","",50,0);
typeWP = new TextField("Type","",50,0);
this.append(nameWP);
if(first = false){
//this.append(typeWP);
this.append("");
chgr = new ChoiceGroup("Category",1,s,null);
this.append(chgr);
lat = new TextField("Latitude","",50,0);
lon = new TextField("Longitude","",50,0);
this.append(lat);
this.append(lon);
}else{
lat = new TextField("Latitude","",50,0);
lon = new TextField("Longitude","",50,0);
this.append(lat);
this.append(lon);
this.append("");
chgr = new ChoiceGroup("Category:",1,s,null);
this.append(chgr);
}
}
/** Returns the name of waypoint
* @return String
*/
public String getName(){
return nameWP.getString();
}
/** Returns the type of waypoint
* @return String
*/
public String getType(){
return typeWP.getString();
}
/** Sets the name of waypoint
*/
public void setName(String s){
nameWP.setString(s);
}
/** Sets the type of waypoint
clxiii

Zarko Acimovic

85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117

*/
public void setType(String s){
typeWP.setString(s);
}
public int getSelected(){
return chgr.getSelectedIndex();
}
public void setLat(long s){
lat.setString(MathFP.toString(s));
}
public void setLon(long s){
lon.setString(MathFP.toString(s));
}
public void setLat(String s){
lat.setString(s);
}
public void setLon(String s){
lon.setString(s);
}
public String getLat(){
return lat.getString();
}
public String getLon(){
return lon.getString();
}
}

clxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
clxv

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Zarko Acimovic

Efferent Coupling (Ce)


Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

Tight Class Cohesion Description


The Tight Class Cohesion metric measures the cohesion between the public methods of a class. That is the
relative number of directly connected public methods in the class. Classes having a low cohesion indicate errors
in the design. http://www.arisa.se/compendium/node118.html
Locality of Data. Description
The Locality of Data metric relates the amount of data being local the class to the total amount of data used by the
class. This relates to the quality of abstraction embodied by the class and allows conclusions on the reuse potential
of the class and testability. http://www.arisa.se/compendium/node112.html
TextFromFriend.java
1
2
3
4
5
6
7
8

/**
* Text form
*/

import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;

clxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59

//import java.io.*;
//import java.util.*;

public class TextFormFriend extends Form{


/** Name of waypoint
*/
TextField nameWP;
/** Type of waypoint
*/
TextField typeWP;

/** Creates new form


*/
TextFormFriend(){
super("Data Input");
nameWP = new TextField("Name","",8,0);
typeWP = new TextField("Type","",8,0);
this.append(nameWP);
this.append(typeWP);
}
/** Returns the name of waypoint
* @return String
*/
public String getName(){
return nameWP.getString();
}
/** Returns the type of waypoint
* @return String
*/
public String getType(){
return typeWP.getString();
}
/** Sets the name of waypoint
*/
public void setName(String s){
nameWP.setString(s);
}
public void setLabel(String s){
nameWP.setLabel(s);
}
clxvii

Zarko Acimovic

60
61
62
63
64
65
66

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

/** Sets the type of waypoint


*/
public void setType(String s){
typeWP.setString(s);
}
}

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity

clxviii

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions

clxix

Zarko Acimovic

Documentation
Lack Of Documentation (LOD)
Code Conventions

Tight Class Cohesion Description


The Tight Class Cohesion metric measures the cohesion between the public methods of a class. That is the
relative number of directly connected public methods in the class. Classes having a low cohesion indicate errors
in the design. http://www.arisa.se/compendium/node118.html
Locality of Data. Description
The Locality of Data metric relates the amount of data being local the class to the total amount of data used by the
class. This relates to the quality of abstraction embodied by the class and allows conclusions on the reuse potential
of the class and testability. http://www.arisa.se/compendium/node112.html
TextFormImage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32

/**
* Text form for ChoicGroup with images
*/

import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;

//import java.io.*;
//import java.util.*;

public class TextFormImage extends Form{


/** Name of waypoint
*/
TextField nameWP;
/** Category of waypoit
*/
// TextField catWP;
/** Type of waypoint
*/
TextField typeWP;
/** ChoiceGroup of categories
*/
// TextField lat;

clxx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83

// TextField lon;
ChoiceGroup chgr;

/** Creates new form


*/
TextFormImage(String nameChg, String[] s, Image[] img){
super("Data Input");
nameWP = new TextField("Name","",50,0);
this.append(nameWP);
this.append("");
chgr = new ChoiceGroup(nameChg,1,s,img);
this.append(chgr);
}
/** Returns the name of waypoint
* @return String
*/
public String getName(){
return nameWP.getString();
}
/** Returns the type of waypoint
* @return String
*/
public String getType(){
return typeWP.getString();
}
/** Sets the name of waypoint
*/
public void setName(String s){
nameWP.setString(s);
}
/** Sets the type of waypoint
*/
public void setType(String s){
typeWP.setString(s);
}
public int getSelected(){
return chgr.getSelectedIndex();
}
public void setNameCHGR(String s){
chgr.setLabel(s);
}
public void setLat(long s){
//lat.setString(MathFP.toString(s));
clxxi

Zarko Acimovic

84
85
86
87
88
89

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

}
public void setLon(long s){
//lon.setString(MathFP.toString(s));
}
}

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)

clxxii

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
Efferent Coupling (Ce)
Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

Tight Class Cohesion Description


The Tight Class Cohesion metric measures the cohesion between the public methods of a class. That is the
relative number of directly connected public methods in the class. Classes having a low cohesion indicate errors
in the design. http://www.arisa.se/compendium/node118.html
Locality of Data. Description
The Locality of Data metric relates the amount of data being local the class to the total amount of data used by the
class. This relates to the quality of abstraction embodied by the class and allows conclusions on the reuse potential
of the class and testability. http://www.arisa.se/compendium/node112.html
Improvement of LCOM Description
The Improvement of LCOM (cf. Lack of Cohesion in Methods 3.2.3) metric is a measure for the number of
clxxiii

Zarko Acimovic

connected components in a class. A component are methods of a class sharing (being connected by) instance
variables of the class. The less separate components there are the higher is the cohesion of the methods in the
class.
http://www.arisa.se/compendium/node117.html
TextFormWP.java

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

/**
* Text form for insertion of waypoint
*/

import javax.microedition.lcdui.*;
//import javax.microedition.midlet.*;

//import java.io.*;
//import java.util.*;

public class TextFormWP extends Form{


/** Name of waypoint
*/
TextField nameWP;
/** Type of waypoint
*/
TextField typeWP;
/** Degrees of latitude
*/
TextField degLat;
/** Minutes of latitude
*/
TextField minLat;
/** Seconds of latitude
*/
TextField secLat;
/** Side NORTH / SOUTH
*/
TextField sideNS;

clxxiv

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92

/** Degrees of longitude


*/
TextField degLon;
/** Minutes of longitude
*/
TextField minLon;
/** Seconds of longitude
*/
TextField secLon;
/** Side WEST / EAST
*/
TextField sideWE;
/** ChoiceGroup of categories
*/
ChoiceGroup chgr;

/** Creates new form


*/
TextFormWP(String[] s){
super("Data Input");
nameWP = new TextField("Name","",12,0);
this.append(nameWP);
typeWP = new TextField("Type","",12,0);
this.append(typeWP);

degLat = new TextField("Degrees of Latitude","",8,0);


this.append(degLat);
minLat = new TextField("Minutes of Latitude","",8,0);
this.append(minLat);
secLat = new TextField("Seconds of Latitude","",8,0);
this.append(secLat);
sideNS = new TextField("Side, North or South?","",8,0);
this.append(sideNS);

degLon = new TextField("Degrees of Longitude","",8,0);


this.append(degLon);
minLon = new TextField("Minutes of Longitude","",8,0);
this.append(minLon);

clxxv

Zarko Acimovic

93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143

secLon = new TextField("Seconds of Longitude","",8,0);


this.append(secLon);
sideWE = new TextField("Side, West or East?","",8,0);
this.append(sideWE);
chgr = new ChoiceGroup("Categories",1,s,null);
this.append(chgr);
}
/** Returns the name of waypoint
* @return String
*/
public String getName(){
return nameWP.getString();
}
/** Returns the type of waypoint
* @return String
*/
public String getType(){
return typeWP.getString();
}
/** Sets the name of waypoint
*/
public void setName(String s){
nameWP.setString(s);
}
/** Sets the type of waypoint
*/
public void setType(String s){
typeWP.setString(s);
}
/** Returns degrees of latitude
*/
public int getDegLat(){
int r = Integer.parseInt(degLat.getString());
return r;
}
/** Returns minutes of latitude
*/
public int getMinLat(){
int r = Integer.parseInt(minLat.getString());
return r;
}

clxxvi

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189

/** Returns seconds of latitude


*/
public int getSecLat(){
int r = Integer.parseInt(secLat.getString());
return r;
}
/** Returns side, North or South
*/
public char getSideNS(){
String s = sideNS.getString();
char[] c = s.toCharArray();
char k = c[0];
return k;
}
/** Returns degrees of longitude
*/
public int getDegLon(){
int r = Integer.parseInt(degLon.getString());
return r;
}
/** Returns minutes of longitude
*/
public int getMinLon(){
int r = Integer.parseInt(minLon.getString());
return r;
}
/** Returns seconds of longitude
*/
public int getSecLon(){
int r = Integer.parseInt(secLon.getString());
return r;
}
/** Returns side, West or East
*/
public char getSideWE(){
String s = sideWE.getString();
char[] c = s.toCharArray();
char k = c[0];
return k;
}
}

clxxvii

Zarko Acimovic

Class Name
MapsMIDlet
MapBackground
Outlook
DelRoute
MapObjects
CompassCanvas
PVector
Point
MathFP
ImageCanvas3
TextFormFriend
TextFormWP
TextForm
Thread4Friend
MapsMIDlet
SelectorPoint
Friend
SimpleTextForm
MapBackgroundFactory
HeapSorter
TextFormImage
Coordinates
CommaHyphenString

Maintainability
0.4696
0
0.0490881667
0.068318936
0
0.0490881667
0.068318936
0.2540449746
0.0981763335
0.0490881667
0.068318936
0.2049568079
0.1366378719
0.1174071027
0.4696284108
0
0.0490881667
0.068318936
0.2049568079
0.1857260387
0.1366378719
0.1366378719
0.1366378719

CBO
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

CYC_Classes
1

1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

DAC
15
2
5
0
5
3
3
2
0
1
0
0
1
5
15
6
1
0
1
0
0
1
0

DIT ILCOM LCOM


0
2
75
0
4
480
0
1
3
0
1
0
0
1
311
0
1
0
0
3
255
0
10
1164
0
1
732
0
1
0
0
2
0
0
10
112
0
5
67
0
3
37
0
2
75
0
1
70
0
3
20
0
3
11
0
1
0
0
0
169
0
3
40
0
4
68
0
0
25

Complexity
Size
Lines of Code (LOC)
Interface Complexity
Number of Attributes and Methods (SIZE2)
Number Of local Methods (NOM)
Structural Complexity
McCabe Cyclomatic Complexity (CC)
Weighted Method Count (WMC)
Response For a Class (RFC)

Architecture and Structure


Inheritance
Depth of Inheritance Tree (DIT)
Number Of Children (NOC)
Coupling
Afferent Coupling (Ca)
Coupling Between Objects (CBO)
Change Dependency Between Classes (CDBC)
Change Dependency Of Classes (CDOC)
clxxviii

LD
0.9909
1.923
0.9
1
1
0.864
1
1.3
0.875
1
0
0
0
1
0.991
1
1
0
0
0
0
0.285
0

LEN
10
13
7
8
10
13
7
5
6
12
14
10
8
13
10
13
6
14
20
10
13
11
17

LOC
1356
616
103
23
370
291
313
699
440
52
52
175
103
173
1356
520
50
70
32
125
75
266
80

LOD_Class MPC
0.667
152
0.29
27
0.917
19
0.75
0
0.4
54
1
78
0.334
25
0.18
33
0.86
0
1
5
0.33
0
0.077
0
0.67
2
0.875
5
0.67
152
0.381
90
0.889
1
0.5
0
0.5
1
0.929
0
0.556
0
0
31
0.167
0

NAM
134
77
21
5
41
26
21
60
46
3
7
23
16
16
134
28
12
11
2
13
11
21
6

NOC
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0

NOM
11
30
11
3
29
3
17
38
34
2
5
12
11
7
11
20
8
7
1
13
8
10
5

RFC
95
40
27
3
53
14
32
45
34
6
5
12
12
11
95
63
9
7
1
13
8
20
5

TCC
0.1429
0.207
0.436
0
0.29
1
0.037
0.074
0.16
1
0.4
0.03
0.145
0.048
0.143
0.36
0.25
0.29
0
0
0.107
0.083
0

WMC
142
59
20
3
70
13
40
51
95
6
5
12
11
18
142
71
9
7
1
27
8
16
13

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin

Efferent Coupling (Ce)


Coupling Factor (CF)
Data Abstraction Coupling (DAC)
Instability (I)
Locality of Data (LD)
Message Passing Coupling (MPC)
Package Data Abstraction Coupling (PDAC)
Cohesion
Lack of Cohesion in Methods (LCOM)
Improvement of LCOM (ILCOM)
Tight Class Cohesion (TCC)

Design Guidelines and Code Conventions


Documentation
Lack Of Documentation (LOD)
Code Conventions

Lack Of Documentation Description. How many comments are lacking in a class, considering one class comment
and a comment per method as optimum. Structure and content of the comments are ignored.
http://www.arisa.se/compendium/node121.html
Tight Class Cohesion Description
The Tight Class Cohesion metric measures the cohesion between the public methods of a class. That is the
relative number of directly connected public methods in the class. Classes having a low cohesion indicate errors
in the design. http://www.arisa.se/compendium/node118.html
Thread4Friend.java

1
2
3
4
5
6

/**
*
* Thread4Friend controls apperance of friend's position on screen
*/
//import javax.microedition.lcdui.*;

clxxix

Zarko Acimovic

7 //import javax.microedition.midlet.*;
8
9 import java.util.*;
10 import java.io.*;
11
12
13 public class Thread4Friend implements Runnable{
14
Thread t;
15
Vector whiteList;
16
String resource;
17
MapObjects mob;
18
ImageCanvas3 ic;
19
MapBackground mb;
20
Outlook oul;
21
int hashID;
22
boolean first = false;
23
24
Thread4Friend(Vector whiteList, String resource, MapObjects mob,
ImageCanvas3 ic, MapBackground mb, Outlook oul){
25
this.oul = oul;
26
this.mob = mob;
27
this.mb = mb;
28
this.ic = ic;
29
this.resource = resource;
30
this.whiteList = whiteList;
31
t = new Thread(this);
32
//t.start();
33
hashID = t.hashCode();
34
}
35
36
public void start(){
37
38
t.start();
39
}
40
41
public int getID(){
42
return hashID;
43
}
44
45
public void run(){
46
47
Thread current = Thread.currentThread();
48
//System.out.println*
49
Integer friendID = new Integer(current.hashCode());
50
while(whiteList.contains(friendID)){
51
current = Thread.currentThread();
52
friendID = new Integer(current.hashCode());
53
String s = this.getResourceAsString(resource);
54
int nextIndex = 6;
55
int index = s.indexOf('\n');
56
clxxx

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


57
nextIndex = s.indexOf('\n',index+1);
58
59
int lastIndex = s.lastIndexOf('\n');
60
61
int begin = -2;
62
int end = index;
63
64
String c1 = "";
65
String c2 = "";
66
String timeStamp = "";
67
long currentTS = 0;
68
69
while(index<lastIndex &&
whiteList.contains(friendID)){
70
current = Thread.currentThread();
71
friendID = new Integer(current.hashCode());
72
Point wp = null;
73
String temp = s.substring(begin+2,end);
74
temp = compact(temp);
75
if(temp.equals("")){ //na kraju ce temp da
bude prazno
76
index = lastIndex+1;
77
} else {
78
temp = compact(temp);
79
int comma = temp.indexOf(',');
80
c1 = temp.substring(0,comma);
81
int nextComma =
temp.indexOf(',',comma+1);
82
c2 =
temp.substring(comma+1,nextComma);
83
timeStamp =
temp.substring(nextComma+1,temp.length());
84
currentTS =
Long.parseLong(timeStamp);
85
begin = index-1;
86
end = nextIndex;
87
index = nextIndex;
88
nextIndex =
s.indexOf('\n',nextIndex+1);
89
90
wp = null;
91
if(!c1.equals("")){
92
wp = new
Point(c2,c1,resource,"","",true);
93
wp.setImage("blanco");
94
}
95
}
96
try{
97
Thread.sleep(1000);
98
}catch(Exception e){}

clxxxi

Zarko Acimovic

99
if(wp!=null &&
whiteList.contains(friendID)){
100
mob.setDrawablePoints();
101
mob.updateFriend(friendID,wp);
102
if(first==false) {
103
mb.setBackground(wp);
104
first=true;
105
}
106
ic.repaint();
107
}
108
}
109
}
110
}
111
112
113
114
/** Blanco characters are possible to occur in names of pictures;
115
* Integer representations of blanko characters are 9 and 32
116
* Also, characters with integer representation between 0 and 33
117
* can not be printed out in WSDD console, so I excluded them too
118
*/
119
public String compact(String s){
120
int k = s.length();
121
//System.out.println("Length of s is "+s.length());
122
char[] d = s.toCharArray();
123
String ret = "";
124
for(int i=0; i<d.length; i++){
125
int temp = (int)d[i];
126
if(temp>32) ret+=d[i];
127
}
128
//System.out.println("Length of ret is "+ret.length());
129
int kk = ret.length();
130
//if (kk!=k) System.out.println("Bugger is: "+s);
131
return ret;
132
}
133
134
public String compactFine(String s){
135
int k = s.length();
136
//System.out.println("Length of s is "+s.length());
137
char[] d = s.toCharArray();
138
String ret = "";
139
for(int i=0; i<d.length; i++){
140
int temp = (int)d[i];
141
if(temp!=32 && temp!=9) ret+=d[i];
142
}
143
//System.out.println("Length of ret is "+ret.length());
144
int kk = ret.length();
145
//if (kk!=k) System.out.println("Bugger is: "+s);
146
return ret;
147
}
148
clxxxii

Example Java Project Tested by VizzMaintenance Metrics Eclipse Plugin


149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

public String getResourceAsString(String resource){


InputStream is = null;
try{
is = this.getClass().getResourceAsStream(resource);
}catch(Exception e) {
//a.setString("There is no such resource");
//d.setCurrent(a);
}
//conversion of resource into string
String s = "";
char m =' ';
try{
m = (char)is.read();
}catch(Exception e){}
while(m!=65535){
s+=m;
try{
m = (char)is.read();
}catch(Exception e){}
}
try{
is.close();
}catch(Exception e){}

s=compactFine(s);
return s;
}
public void setFirst(){
first = false;
}
}

ABOUT THE AUTHOR

clxxxiii

Zarko Acimovic

Follow me on
https://www.facebook.com/AutomatedTesting

clxxxiv

Вам также может понравиться