-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathTransTool.java
More file actions
68 lines (62 loc) · 1.61 KB
/
Copy pathTransTool.java
File metadata and controls
68 lines (62 loc) · 1.61 KB
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
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
package segment;
import java.util.ArrayList;
public class TransTool {
public int inSegment(String src,String des)
{
String[] tempSrc = src.split("/");
String[] tempDes = des.split("/");
double src1 = Double.parseDouble(tempSrc[0]);
double src2 = Double.parseDouble(tempSrc[1]);
double des1 = Double.parseDouble(tempDes[0]);
double des2 = Double.parseDouble(tempDes[1]);
if(src1>=des1&&src2<=des2){
return 0;
}else if(src1<des1&&src2>des2){
return 1;
}else if(src1<des1&&src2<des2){
return 2;
}else if(src1>des1&&src2>des2){
return 3;
}
return -1;
}
public ArrayList<String> mergeResult(ArrayList<String> resList)
{
ArrayList<String> res = new ArrayList<String>();
int size = resList.size();
String[] preStr;
String[] nextStr;
double preStrStart;
double preStrEnd;
double nextStrStart;
double nextStrEnd;
res.add(resList.get(0));
for(int i = 1;i<size;i++)
{
preStr = res.get(res.size()-1).split("/");
nextStr = resList.get(i).split("/");
preStrStart = Double.parseDouble(preStr[0]);
preStrEnd = Double.parseDouble(preStr[1]);
nextStrStart = Double.parseDouble(nextStr[0]);
nextStrEnd = Double.parseDouble(nextStr[1]);
if(preStrEnd == nextStrStart)
{
res.remove(res.size()-1);
res.add(preStrStart + "/" + nextStrEnd);
}else{
res.add(resList.get(i));
}
}
return res;
}
public void printRes(ArrayList<String> res)
{
System.out.println("------------------------------------\n得到结果:");
String[] temp;
for(String obj:res)
{
temp = obj.split("/");
System.out.print("(" + temp[0] + "," + temp[1] + ") ");
}
}
}