-
Notifications
You must be signed in to change notification settings - Fork 982
/
ListPointAccepter.java
56 lines (47 loc) · 1.31 KB
/
ListPointAccepter.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package org.osmdroid.util;
import java.util.ArrayList;
import java.util.List;
/**
* A {@link PointAccepter} that builds a {@link List} of {@link PointL} as a list of long, long
*
* @author Fabrice Fontaine
* @since 6.2.0
*/
public class ListPointAccepter implements PointAccepter {
private final List<Long> mList = new ArrayList<>();
private final PointL mLatestPoint = new PointL();
private final boolean mRemoveConsecutiveDuplicates;
private boolean mFirst;
public ListPointAccepter(final boolean pRemoveConsecutiveDuplicates) {
mRemoveConsecutiveDuplicates = pRemoveConsecutiveDuplicates;
}
public List<Long> getList() {
return mList;
}
@Override
public void init() {
mList.clear();
mFirst = true;
}
@Override
public void add(long pX, long pY) {
if (!mRemoveConsecutiveDuplicates) {
mList.add(pX);
mList.add(pY);
return;
}
if (mFirst) {
mFirst = false;
mList.add(pX);
mList.add(pY);
mLatestPoint.set(pX, pY);
} else if (mLatestPoint.x != pX || mLatestPoint.y != pY) {
mList.add(pX);
mList.add(pY);
mLatestPoint.set(pX, pY);
}
}
@Override
public void end() {
}
}