Skip to content

Commit

Permalink
Merge pull request #1 from DevFactory/release/multiple-code-improveme…
Browse files Browse the repository at this point in the history
…nts-fix-1

Multiple code improvements - squid:S1118, squid:S1149, squid:S1213, squid:S1066, squid:S134
  • Loading branch information
onlylemi committed May 14, 2016
2 parents 2cbc71f + ce851a0 commit bc7e8fb
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 44 deletions.
2 changes: 2 additions & 0 deletions demo/src/main/java/com/onlylemi/mapview/TestData.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
*/
public final class TestData {

private TestData() {}

public static List<PointF> getNodesList() {
List<PointF> nodes = new ArrayList<>();
nodes.add(new PointF(222, 34));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,26 @@ private void initLayer() {

@Override
public void onTouch(MotionEvent event) {
if (marks != null) {
if (marks.size() != 0) {
float[] goal = mapView.convertMapXYToScreenXY(event.getX(), event.getY());
for (int i = 0; i < marks.size(); i++) {
if (MapMath.getDistanceBetweenTwoPoints(goal[0], goal[1],
marks.get(i).x - bmpMark.getWidth() / 2, marks.get(i).y - bmpMark
.getHeight() / 2) <= 50) {
num = i;
isClickMark = true;
break;
}

if (i == marks.size() - 1) {
isClickMark = false;
}
if (marks != null && marks.size() != 0) {
float[] goal = mapView.convertMapXYToScreenXY(event.getX(), event.getY());
for (int i = 0; i < marks.size(); i++) {
if (MapMath.getDistanceBetweenTwoPoints(goal[0], goal[1],
marks.get(i).x - bmpMark.getWidth() / 2, marks.get(i).y - bmpMark
.getHeight() / 2) <= 50) {
num = i;
isClickMark = true;
break;
}

if (listener != null && isClickMark) {
listener.markIsClick(num);
mapView.refresh();
if (i == marks.size() - 1) {
isClickMark = false;
}
}

if (listener != null && isClickMark) {
listener.markIsClick(num);
mapView.refresh();
}
}
}

Expand All @@ -98,11 +96,10 @@ public void draw(Canvas canvas, Matrix currentMatrix, float currentZoom, float
paint.setColor(Color.BLACK);
paint.setTextSize(radiusMark);
//mark name
if (mapView.getCurrentZoom() > 1.0 && marksName != null) {
if (marksName.size() == marks.size()) {
canvas.drawText(marksName.get(i), goal[0] - radiusMark, goal[1] -
radiusMark / 2, paint);
}
if (mapView.getCurrentZoom() > 1.0 && marksName != null
&& marksName.size() == marks.size()) {
canvas.drawText(marksName.get(i), goal[0] - radiusMark, goal[1] -
radiusMark / 2, paint);
}
//mark ico
canvas.drawBitmap(bmpMark, goal[0] - bmpMark.getWidth() / 2,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
*/
public final class MapMath {

private MapMath() {}

/**
* the distance between two points
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public final class MapUtils {
private static int nodesSize;
private static int nodesContactSize;

private MapUtils() {}

public static void init(int nodessize, int nodescontactsize) {
nodesSize = nodessize;
nodesContactSize = nodescontactsize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,35 @@ public class GeneticAlgorithm {
private static final float DEFAULT_CROSSOVER_PROBABILITY = 0.9f; // 默认交叉概率
private static final float DEFAULT_MUTATION_PROBABILITY = 0.01f; // 默认突变概率
private static final int DEFAULT_POPULATION_SIZE = 30; // 默认种群数量
private static final int PREVIOUS = 0;
private static final int NEXT = 1;

private float crossoverProbability = DEFAULT_CROSSOVER_PROBABILITY; // 交叉概率
private float mutationProbability = DEFAULT_MUTATION_PROBABILITY; // 突变概率
private int populationSize = DEFAULT_POPULATION_SIZE; // 种群数量

private int populationSize = DEFAULT_POPULATION_SIZE; // 种群数量
private int mutationTimes = 0; // 变异次数
private int currentGeneration = 0; // 当前的一代
private int maxGeneration = 1000; // 最大代数

private int maxGeneration = 1000; // 最大代数
private int pointNum;
private int[][] population; // 种群集
private float[][] dist; // 点集间的邻接矩阵

private float[][] dist; // 点集间的邻接矩阵
private int[] bestIndivial; // 最短的结果集
private float bestDist; // 最短的距离
private int currentBestPosition; // 当前最好个体的位置
private float currentBestDist; // 当前最好个体的距离

private float currentBestDist; // 当前最好个体的距离
private float[] values; // 种群中每个个体的dist
private float[] fitnessValues; // 适应度集

private float[] roulette;

private boolean isAutoNextGeneration = false;

private static Random rd;

public static GeneticAlgorithm getInstance() {
return GeneticAlgorithmHolder.instance;
}
Expand Down Expand Up @@ -234,9 +239,6 @@ private void crossover() {
}
}

private static final int PREVIOUS = 0;
private static final int NEXT = 1;

private void doCrossover(int x, int y) {
population[x] = getChild(x, y, PREVIOUS);
population[y] = getChild(x, y, NEXT);
Expand Down Expand Up @@ -375,8 +377,6 @@ private int[] shuffle(int[] a) {
return a;
}

private static Random rd;

private int random(int n) {
Random ran = rd;
if (ran == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.onlylemi.mapview.library.utils.math;

import java.net.FileNameMap;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;
import java.util.Stack;

Expand All @@ -10,20 +12,20 @@ public class TSPNearestNeighbour {
private static final float INF = Float.MAX_VALUE;

private int numberOfNodes;
private Stack<Integer> stack;
private Deque<Integer> stack;
private List<Integer> list;

public TSPNearestNeighbour() {
stack = new ArrayDeque<>();
list = new ArrayList<>();
}

public static TSPNearestNeighbour getInstance() {
return TSPNearestNeighbourHolder.instance;
}

private static class TSPNearestNeighbourHolder {
private static TSPNearestNeighbour instance = new TSPNearestNeighbour();
}

public TSPNearestNeighbour() {
stack = new Stack<>();
list = new ArrayList<>();
}

public List<Integer> tsp(float matrix[][]) {
Expand All @@ -42,12 +44,10 @@ public List<Integer> tsp(float matrix[][]) {
i = 0;
min = INF;
while (i < numberOfNodes) {
if (matrix[element][i] < INF && visited[i] == 0) {
if (min > matrix[element][i]) {
min = matrix[element][i];
dst = i;
minFlag = true;
}
if (matrix[element][i] < INF && visited[i] == 0 && min > matrix[element][i]) {
min = matrix[element][i];
dst = i;
minFlag = true;
}
i++;
}
Expand Down

0 comments on commit bc7e8fb

Please sign in to comment.