Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e8fb944

Browse files
committed
Merge pull request taimos#1 from juzt3/speedlistener-function
Speedlistener function
2 parents 66894e1 + 1f123bb commit e8fb944

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package de.taimos.gpsd4java.api;
2+
3+
/*
4+
* #%L
5+
* GPSd4Java
6+
* %%
7+
* Copyright (C) 2011 - 2012 Taimos GmbH
8+
* %%
9+
* Licensed under the Apache License, Version 2.0 (the "License");
10+
* you may not use this file except in compliance with the License.
11+
* You may obtain a copy of the License at
12+
*
13+
* http://www.apache.org/licenses/LICENSE-2.0
14+
*
15+
* Unless required by applicable law or agreed to in writing, software
16+
* distributed under the License is distributed on an "AS IS" BASIS,
17+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18+
* See the License for the specific language governing permissions and
19+
* limitations under the License.
20+
* #L%
21+
*/
22+
23+
import de.taimos.gpsd4java.types.TPVObject;
24+
25+
/**
26+
* Derive this class to implement a listener for speed updates which reacts to changes smaller a given threshold
27+
*
28+
* @author juzt3
29+
*/
30+
public abstract class SpeedListener extends ObjectListener {
31+
32+
private TPVObject lastPosition;
33+
34+
private final double threshold;
35+
36+
37+
/**
38+
* @param threshold
39+
* the threshold to fire in kilometers per hour
40+
*/
41+
public SpeedListener(final double threshold) {
42+
this.threshold = threshold;
43+
}
44+
45+
@Override
46+
public void handleTPV(final TPVObject tpv) {
47+
if ((this.lastPosition == null) || (tpv.getSpeed() < this.threshold)) {
48+
this.lastPosition = tpv;
49+
this.handleLocation(tpv);
50+
}
51+
}
52+
53+
protected abstract void handleLocation(TPVObject tpv);
54+
55+
}

0 commit comments

Comments
 (0)