aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbyss777 <abyss@fox5.ru>2017-08-29 08:44:12 +0500
committerAbyss777 <abyss@fox5.ru>2017-08-29 08:44:12 +0500
commit57d2621cdf5e318a236b036a9435358121a4adf5 (patch)
treeb59d83660c9f20a63dce35518d6b380f0a6d7ed6
parent8d489fd4290bd93b394f0066983611f25e2e103b (diff)
downloadtrackermap-server-57d2621cdf5e318a236b036a9435358121a4adf5.tar.gz
trackermap-server-57d2621cdf5e318a236b036a9435358121a4adf5.tar.bz2
trackermap-server-57d2621cdf5e318a236b036a9435358121a4adf5.zip
- Rename parameter
- Move Limit to the begining
-rw-r--r--src/org/traccar/FilterHandler.java30
-rw-r--r--test/org/traccar/FilterHandlerTest.java2
2 files changed, 15 insertions, 17 deletions
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index ff53c9e25..91fbac68f 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -30,7 +30,7 @@ public class FilterHandler extends BaseDataHandler {
private int filterDistance;
private int filterMaxSpeed;
private long filterLimit;
- private boolean allowAlarms;
+ private boolean keepAlarms;
public void setFilterInvalid(boolean filterInvalid) {
this.filterInvalid = filterInvalid;
@@ -68,8 +68,8 @@ public class FilterHandler extends BaseDataHandler {
this.filterLimit = filterLimit;
}
- public void setAllowAlarms(boolean allowAlarms) {
- this.allowAlarms = allowAlarms;
+ public void setKeepAlarms(boolean keepAlarms) {
+ this.keepAlarms = keepAlarms;
}
public FilterHandler() {
@@ -84,7 +84,7 @@ public class FilterHandler extends BaseDataHandler {
filterDistance = config.getInteger("filter.distance");
filterMaxSpeed = config.getInteger("filter.maxSpeed");
filterLimit = config.getLong("filter.limit") * 1000;
- allowAlarms = config.getBoolean("filter.allowAlarms");
+ keepAlarms = config.getBoolean("filter.keepAlarms");
}
}
@@ -132,27 +132,22 @@ public class FilterHandler extends BaseDataHandler {
private boolean filterMaxSpeed(Position position, Position last) {
if (filterMaxSpeed != 0 && last != null) {
double distance = position.getDouble(Position.KEY_DISTANCE);
- long time = position.getFixTime().getTime() - last.getFixTime().getTime();
- return UnitsConverter.knotsFromMps(distance / (time / 1000.0)) > filterMaxSpeed;
+ double time = position.getFixTime().getTime() - last.getFixTime().getTime();
+ return UnitsConverter.knotsFromMps(distance / (time / 1000)) > filterMaxSpeed;
}
return false;
}
private boolean filterLimit(Position position, Position last) {
- if (filterLimit != 0) {
- if (last != null) {
- return (position.getFixTime().getTime() - last.getFixTime().getTime()) > filterLimit;
- } else {
- return false;
- }
- } else {
- return false;
+ if (filterLimit != 0 && last != null) {
+ return (position.getFixTime().getTime() - last.getFixTime().getTime()) > filterLimit;
}
+ return false;
}
private boolean filter(Position position) {
- if (allowAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) {
+ if (keepAlarms && position.getAttributes().containsKey(Position.KEY_ALARM)) {
return false;
}
@@ -163,6 +158,9 @@ public class FilterHandler extends BaseDataHandler {
last = Context.getIdentityManager().getLastPosition(position.getDeviceId());
}
+ if (filterLimit(position, last)) {
+ filterType.append("Limit ");
+ }
if (filterInvalid(position)) {
filterType.append("Invalid ");
}
@@ -188,7 +186,7 @@ public class FilterHandler extends BaseDataHandler {
filterType.append("MaxSpeed ");
}
- if (filterType.length() > 0 && !filterLimit(position, last)) {
+ if (filterType.length() > 0) {
StringBuilder message = new StringBuilder();
message.append("Position filtered by ");
diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java
index 86b84f91f..a2019f81f 100644
--- a/test/org/traccar/FilterHandlerTest.java
+++ b/test/org/traccar/FilterHandlerTest.java
@@ -77,7 +77,7 @@ public class FilterHandlerTest extends BaseTest {
assertNotNull(passingHandler.decode(null, null, position));
position.set(Position.KEY_ALARM, Position.ALARM_GENERAL);
- filtingHandler.setAllowAlarms(true);
+ filtingHandler.setKeepAlarms(true);
assertNotNull(filtingHandler.decode(null, null, position));
}