Skip to content

Commit 8658f7e

Browse files
author
David Baum
committed
remove some warnings in rd2rd classes
1 parent 3f93440 commit 8658f7e

5 files changed

Lines changed: 48 additions & 118 deletions

File tree

generator2/org.getaviz.generator/src/main/java/org/getaviz/generator/rd/m2m/Calculator.java

Lines changed: 6 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,13 @@
44
import java.util.Collections;
55
import java.util.List;
66

7-
import org.getaviz.generator.rd.m2m.Circle;
8-
import org.getaviz.generator.rd.m2m.CircleWithInnerCircles;
9-
10-
public class Calculator {
11-
12-
public static final int SILENT = 0;
13-
public static final int DEBUG = 1;
14-
15-
private static int VERBOSE_MODE = SILENT;
16-
17-
public static void setVerboseMode(int mode) {
18-
switch (mode) {
19-
case SILENT:
20-
VERBOSE_MODE = SILENT;
21-
break;
22-
case DEBUG:
23-
VERBOSE_MODE = DEBUG;
24-
break;
25-
default:
26-
VERBOSE_MODE = SILENT;
27-
break;
28-
}
29-
}
30-
31-
public static void printCircle(Circle c, int number) {
32-
if (VERBOSE_MODE != DEBUG)
33-
return;
34-
System.out.println("Circle numer " + number);
35-
System.out.println("----------------------");
36-
System.out.println("Radius: " + c.getRadius());
37-
System.out.println("Centre: " + c.getCentre().x + "|" + c.getCentre().y);
38-
System.out.println("");
39-
}
7+
class Calculator {
408

41-
public static List<CircleWithInnerCircles> calculate(final List<CircleWithInnerCircles> circleList) {
9+
static void calculate(final List<CircleWithInnerCircles> circleList) {
4210

4311
if (circleList == null || circleList.size() == 0) {
4412
// TODO throw exception
45-
return null;
13+
return;
4614
}
4715

4816
Collections.sort(circleList);
@@ -57,19 +25,15 @@ public static List<CircleWithInnerCircles> calculate(final List<CircleWithInnerC
5725
Circle first = circleList.get(0);
5826
first.setCentre(new Point2D.Double(0, 0));
5927

60-
printCircle(first, 0);
61-
6228
if (circleList.size() < 2) {
63-
return circleList;
29+
return;
6430
}
6531

6632
// Instantiate the second circle
6733
Circle second = circleList.get(1);
6834

6935
second.setCentre(Util.calculateCentre(first, second, angle));
7036

71-
printCircle(second, 1);
72-
7337
// start from the third circle, because the first and the second are fix
7438

7539
for (int n = 2; n < circleList.size(); n++) {
@@ -87,7 +51,7 @@ public static List<CircleWithInnerCircles> calculate(final List<CircleWithInnerC
8751
// (m,n,n-1)
8852
// so angle + triangle_angle will be the angle of the new circle
8953
// at this point angle ist the angle between m and n-1
90-
double triangle_angle = 0;
54+
double triangle_angle;
9155
double a = n_circle.getRadius() + n_minus1_circle.getRadius();
9256
double b = m_circle.getRadius() + n_circle.getRadius();
9357
double c = m_circle.getRadius() + n_minus1_circle.getRadius();
@@ -110,7 +74,7 @@ public static List<CircleWithInnerCircles> calculate(final List<CircleWithInnerC
11074
// all circles that are are at the same side in the range of m
11175
// to n-1
11276
Circle m_plus1_cirle = circleList.get(m + 1);
113-
double angle2 = 0;
77+
double angle2;
11478
a = n_circle.getRadius() + n_minus1_circle.getRadius();
11579
b = Util.distance(circleList.get(m + 1), circleList.get(n - 1));
11680
c = m_plus1_cirle.getRadius() + n_circle.getRadius();
@@ -168,10 +132,7 @@ public static List<CircleWithInnerCircles> calculate(final List<CircleWithInnerC
168132

169133
// angle is now the angle between m and n
170134
}
171-
172-
printCircle(n_circle, n);
173135
}
174136
// return the result
175-
return circleList;
176137
}
177138
}

generator2/org.getaviz.generator/src/main/java/org/getaviz/generator/rd/m2m/Circle.java

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,15 @@
55
abstract class Circle implements Comparable<Circle> {
66

77
protected double radius = 0;
8-
protected Double centre = new Double(0, 0);
9-
protected double minArea = 0;
10-
protected double netArea;
11-
protected double grossArea;
12-
protected String serial = "";
13-
protected double ringWidth;
8+
Double centre = new Double(0, 0);
9+
double minArea = 0;
10+
double netArea;
11+
double grossArea;
12+
String serial = "";
13+
double ringWidth;
1414

1515
public int compareTo(Circle circle) {
16-
if (netArea < circle.getNetArea()) {
17-
return 1;
18-
} else if (netArea > circle.getNetArea()) {
19-
return -1;
20-
} else {
21-
return 0;
22-
}
16+
return java.lang.Double.compare(circle.getNetArea(), netArea);
2317
}
2418

2519
public double getRadius() {
@@ -30,35 +24,35 @@ public void setRadius(double radius) {
3024
this.radius = radius;
3125
}
3226

33-
public Double getCentre() {
27+
Double getCentre() {
3428
return centre;
3529
}
3630

37-
public void setCentre(Double centre) {
31+
void setCentre(Double centre) {
3832
this.centre = centre;
3933
}
4034

41-
public double getMinArea() {
35+
double getMinArea() {
4236
return minArea;
4337
}
4438

45-
public double getNetArea() {
39+
double getNetArea() {
4640
return netArea;
4741
}
4842

49-
public void setNetArea(double netArea) {
43+
void setNetArea(double netArea) {
5044
this.netArea = netArea;
5145
}
5246

53-
public double getGrossArea() {
47+
double getGrossArea() {
5448
return grossArea;
5549
}
5650

57-
public void setGrossArea(double grossArea) {
51+
void setGrossArea(double grossArea) {
5852
this.grossArea = grossArea;
5953
}
6054

61-
public double getRingWidth() {
55+
double getRingWidth() {
6256
return ringWidth;
6357
}
6458
}

generator2/org.getaviz.generator/src/main/java/org/getaviz/generator/rd/m2m/CircleWithInnerCircles.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CircleWithInnerCircles extends Circle {
1818
diskNode = disk;
1919
Iterable<Node> data = () -> RDUtils.getData(disk.id());
2020
Iterable<Node> methods = () -> RDUtils.getMethods(disk.id());
21-
if (nesting == true) {
21+
if (nesting) {
2222
minArea = RDUtils.sum(methods) + RDUtils.sum(data);
2323
} else {
2424
minArea = disk.get("netArea").asDouble();
@@ -29,16 +29,14 @@ class CircleWithInnerCircles extends Circle {
2929
log.debug("set netArea to " + netArea + "for disk " + diskNode.id());
3030
radius = disk.get("radius").asDouble(0.0);
3131
grossArea = disk.get("grossArea").asDouble(0.0);
32-
RDUtils.getSubDisks(disk.id()).forEachRemaining((subDisk) -> {
33-
innerCircles.add(new CircleWithInnerCircles(subDisk.get("d").asNode(), true));
34-
});
32+
RDUtils.getSubDisks(disk.id()).forEachRemaining((subDisk) -> innerCircles.add(new CircleWithInnerCircles(subDisk.get("d").asNode(), true)));
3533
}
3634

3735
/**
3836
* write calculated positions into extended disk
3937
*
4038
*/
41-
public void updateDiskNode() {
39+
void updateDiskNode() {
4240
String updateNode = String.format(
4341
"MATCH (n) WHERE ID(n) = %d SET n.radius = %f, n.netArea = %f, n.grossArea = %f ", diskNode.id(),
4442
radius, netArea, grossArea);
@@ -59,7 +57,7 @@ public void updateDiskNode() {
5957
}
6058
}
6159

62-
public ArrayList<CircleWithInnerCircles> getInnerCircles() {
60+
ArrayList<CircleWithInnerCircles> getInnerCircles() {
6361
return innerCircles;
6462
}
6563
}

generator2/org.getaviz.generator/src/main/java/org/getaviz/generator/rd/m2m/RDLayout.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@
1111
import com.vividsolutions.jts.util.GeometricShapeFactory;
1212
import java.util.ArrayList;
1313

14-
public class RDLayout {
14+
class RDLayout {
1515

16-
public static void nestedLayout(ArrayList<CircleWithInnerCircles> circleList) {
16+
static void nestedLayout(ArrayList<CircleWithInnerCircles> circleList) {
1717
layout(circleList);
1818
transformPositions(circleList);
1919
}
2020

2121
private static void layout(List<CircleWithInnerCircles> circleList) {
2222
for (CircleWithInnerCircles circle : circleList) {
23-
if (((CircleWithInnerCircles) circle).getInnerCircles().size() > 0) {
24-
List<CircleWithInnerCircles> innerCircles = ((CircleWithInnerCircles) circle).getInnerCircles();
23+
if (circle.getInnerCircles().size() > 0) {
24+
List<CircleWithInnerCircles> innerCircles = circle.getInnerCircles();
2525
layout(innerCircles);
2626
calculateRadiusForOuterCircles(circle,innerCircles);
2727
}
@@ -42,10 +42,10 @@ private static void transformPositions(List<CircleWithInnerCircles> circleList)
4242
private static void updateArea(List<CircleWithInnerCircles> circleList) {
4343
for (CircleWithInnerCircles circle : circleList) {
4444
circle.setGrossArea(circle.getRadius() * circle.getRadius() * Math.PI);
45-
if (((CircleWithInnerCircles) circle).getInnerCircles().size() < 1) {
45+
if (circle.getInnerCircles().size() < 1) {
4646
circle.setNetArea(circle.getGrossArea());
4747
} else {
48-
List<CircleWithInnerCircles> innerCircles = ((CircleWithInnerCircles) circle).getInnerCircles();
48+
List<CircleWithInnerCircles> innerCircles = circle.getInnerCircles();
4949
circle.setNetArea(circle.getNetArea() + (2 * circle.getRadius() - circle.getRingWidth()) * circle.getRingWidth() * Math.PI);
5050

5151
for (CircleWithInnerCircles c : innerCircles) {
@@ -81,7 +81,7 @@ private static void calculateRadiusForOuterCircles(CircleWithInnerCircles outerC
8181
// outerCircle.setCentre(centre);
8282
// outerCircle.setRadius(RING_WIDTH + radius + calculateB(calculateD(outerCircle.getMinArea(), radius), radius));
8383
// normalizePositionOfInnerCircles(outerCircle, innerCircles);
84-
final double radius = mbc.getRadius();
84+
final double radius = mbc.getRadius();
8585
final Point2D.Double centre = new Point2D.Double(mbc.getCentre().x, mbc.getCentre().y);
8686

8787
outerCircle.setCentre(centre);

generator2/org.getaviz.generator/src/main/java/org/getaviz/generator/rd/m2m/Util.java

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,58 @@
22

33
import java.awt.geom.Point2D;
44

5-
import org.getaviz.generator.rd.m2m.Circle;
6-
7-
public class Util {
8-
public static double correctAngle(double angle) {
5+
class Util {
6+
static double correctAngle(double angle) {
97
return angle % 360;
108
}
119

12-
public static double correctAngleWithin90(double angle) {
13-
14-
double result = Double.valueOf(angle);
15-
while (result > 90) {
16-
result -= 90;
17-
}
18-
return result;
19-
}
20-
21-
public static double distance(Circle firstPoint, Circle secondPoint) {
10+
static double distance(Circle firstPoint, Circle secondPoint) {
2211
double a = Math.abs(firstPoint.getCentre().y - secondPoint.getCentre().y);
2312
double b = Math.abs(firstPoint.getCentre().x - secondPoint.getCentre().x);
2413

2514
return Math.sqrt(a * a + b * b);
2615
}
2716

28-
public static double angleBetweenPoints_XasKatethe(Circle firstPoint, Circle secondPoint) {
17+
static double angleBetweenPoints_XasKatethe(Circle firstPoint, Circle secondPoint) {
2918
double a = Math.abs(firstPoint.getCentre().y - secondPoint.getCentre().y);
3019
double b = Math.abs(firstPoint.getCentre().x - secondPoint.getCentre().x);
3120
double c = Math.sqrt(a * a + b * b);
3221
return Math.abs(Math.toDegrees(Math.asin(b / c)));
3322

3423
}
3524

36-
public static double angleBetweenPoints_YasKatethe(Circle firstPoint, Circle secondPoint) {
25+
static double angleBetweenPoints_YasKatethe(Circle firstPoint, Circle secondPoint) {
3726
double a = Math.abs(firstPoint.getCentre().y - secondPoint.getCentre().y);
3827
double b = Math.abs(firstPoint.getCentre().x - secondPoint.getCentre().x);
3928
double c = Math.sqrt(a * a + b * b);
4029
return Math.abs(Math.toDegrees(Math.asin(a / c)));
4130

4231
}
4332

44-
public static boolean intersect(Circle firstPoint, Circle secondPoint) {
33+
static boolean intersect(Circle firstPoint, Circle secondPoint) {
4534
double a = Math.abs(firstPoint.getCentre().y - secondPoint.getCentre().y);
4635
double b = Math.abs(firstPoint.getCentre().x - secondPoint.getCentre().x);
4736
// there must be a little tolerance!
48-
return (Math.sqrt(a * a + b * b) <= firstPoint.getRadius() + secondPoint.getRadius() - 0.001) ? true : false;
37+
return (Math.sqrt(a * a + b * b) <= firstPoint.getRadius() + secondPoint.getRadius() - 0.001);
4938
}
5039

51-
public static boolean isLeftOf(Circle firstPoint, Circle secondPoint) {
52-
return firstPoint.getCentre().x < secondPoint.getCentre().x ? true : false;
40+
static boolean isLeftOf(Circle firstPoint, Circle secondPoint) {
41+
return firstPoint.getCentre().x < secondPoint.getCentre().x;
5342
}
5443

55-
public static boolean isRightOf(Circle firstPoint, Circle secondPoint) {
56-
return firstPoint.getCentre().x > secondPoint.getCentre().x ? true : false;
44+
static boolean isRightOf(Circle firstPoint, Circle secondPoint) {
45+
return firstPoint.getCentre().x > secondPoint.getCentre().x;
5746
}
5847

59-
public static boolean isAboveOf(Circle firstPoint, Circle secondPoint) {
60-
return firstPoint.getCentre().y > secondPoint.getCentre().y ? true : false;
48+
static boolean isAboveOf(Circle firstPoint, Circle secondPoint) {
49+
return firstPoint.getCentre().y > secondPoint.getCentre().y;
6150
}
6251

63-
public static boolean isBelowOf(Circle firstPoint, Circle secondPoint) {
64-
return firstPoint.getCentre().y < secondPoint.getCentre().y ? true : false;
52+
static boolean isBelowOf(Circle firstPoint, Circle secondPoint) {
53+
return firstPoint.getCentre().y < secondPoint.getCentre().y ;
6554
}
6655

67-
public static Point2D.Double calculateCentre(Circle m, Circle n, double angle) {
56+
static Point2D.Double calculateCentre(Circle m, Circle n, double angle) {
6857
angle = Util.correctAngle(angle);
6958
if (angle == 0 || angle == 360) {
7059
return new Point2D.Double(m.getCentre().x, m.getCentre().y + n.getRadius() + m.getRadius());
@@ -100,16 +89,4 @@ public static Point2D.Double calculateCentre(Circle m, Circle n, double angle) {
10089
}
10190
return null;
10291
}
103-
104-
public static double calculateAngle(Circle m, Circle n, Circle n_minus_1, double alpha_m_n_minus_1) {
105-
106-
double rm = m.getRadius();
107-
double rn = n.getRadius();
108-
double rn_minus_1 = n_minus_1.getRadius();
109-
110-
return alpha_m_n_minus_1
111-
+ Math.toDegrees(Math.acos((rm * rm + rm * rn_minus_1 + rm * rn - rn_minus_1 * rn)
112-
/ (rm * rm + rm * rn_minus_1 + rm * rn + rn_minus_1 * rn)));
113-
}
114-
11592
}

0 commit comments

Comments
 (0)