aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/org/traccar/FilterHandler.java65
-rw-r--r--test/org/traccar/FilterHandlerTest.java12
2 files changed, 52 insertions, 25 deletions
diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java
index b6917cbfb..1ce9e2460 100644
--- a/src/org/traccar/FilterHandler.java
+++ b/src/org/traccar/FilterHandler.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2014 Anton Tananaev (anton.tananaev@gmail.com)
+ * Copyright 2014 - 2016 Anton Tananaev (anton.tananaev@gmail.com)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -23,40 +23,59 @@ public class FilterHandler extends BaseDataHandler {
private static final long FILTER_FUTURE_LIMIT = 5 * 60 * 1000;
- private final boolean filterInvalid;
- private final boolean filterZero;
- private final boolean filterDuplicate;
- private final boolean filterFuture;
- private final boolean filterApproximate;
- private final boolean filterStatic;
- private final int filterDistance;
- private final long filterLimit;
-
- public FilterHandler(
- boolean filterInvalid, boolean filterZero, boolean filterDuplicate, boolean filterFuture,
- boolean filterApproximate, boolean filterStatic, int filterDistance, long filterLimit) {
+ private boolean filterInvalid;
+ private boolean filterZero;
+ private boolean filterDuplicate;
+ private boolean filterFuture;
+ private boolean filterApproximate;
+ private boolean filterStatic;
+ private int filterDistance;
+ private long filterLimit;
+ public void setFilterInvalid(boolean filterInvalid) {
this.filterInvalid = filterInvalid;
+ }
+
+ public void setFilterZero(boolean filterZero) {
this.filterZero = filterZero;
+ }
+
+ public void setFilterDuplicate(boolean filterDuplicate) {
this.filterDuplicate = filterDuplicate;
- this.filterDistance = filterDistance;
+ }
+
+ public void setFilterFuture(boolean filterFuture) {
this.filterFuture = filterFuture;
+ }
+
+ public void setFilterApproximate(boolean filterApproximate) {
this.filterApproximate = filterApproximate;
+ }
+
+ public void setFilterStatic(boolean filterStatic) {
this.filterStatic = filterStatic;
+ }
+
+ public void setFilterDistance(int filterDistance) {
+ this.filterDistance = filterDistance;
+ }
+
+ public void setFilterLimit(long filterLimit) {
this.filterLimit = filterLimit;
}
public FilterHandler() {
Config config = Context.getConfig();
-
- filterInvalid = config.getBoolean("filter.invalid");
- filterZero = config.getBoolean("filter.zero");
- filterDuplicate = config.getBoolean("filter.duplicate");
- filterFuture = config.getBoolean("filter.future");
- filterApproximate = config.getBoolean("filter.approximate");
- filterStatic = config.getBoolean("filter.static");
- filterDistance = config.getInteger("filter.distance");
- filterLimit = config.getLong("filter.limit") * 1000;
+ if (config != null) {
+ filterInvalid = config.getBoolean("filter.invalid");
+ filterZero = config.getBoolean("filter.zero");
+ filterDuplicate = config.getBoolean("filter.duplicate");
+ filterFuture = config.getBoolean("filter.future");
+ filterApproximate = config.getBoolean("filter.approximate");
+ filterStatic = config.getBoolean("filter.static");
+ filterDistance = config.getInteger("filter.distance");
+ filterLimit = config.getLong("filter.limit") * 1000;
+ }
}
private Position getLastPosition(long deviceId) {
diff --git a/test/org/traccar/FilterHandlerTest.java b/test/org/traccar/FilterHandlerTest.java
index b1e4fcb16..bb7e69dc0 100644
--- a/test/org/traccar/FilterHandlerTest.java
+++ b/test/org/traccar/FilterHandlerTest.java
@@ -15,8 +15,16 @@ public class FilterHandlerTest {
@Before
public void setUp() {
- filtingHandler = new FilterHandler(true, true, true, true, true, 10, 10);
- passingHandler = new FilterHandler(false, false, false, false, false, 0, 0);
+ passingHandler = new FilterHandler();
+ filtingHandler = new FilterHandler();
+ filtingHandler.setFilterInvalid(true);
+ filtingHandler.setFilterZero(true);
+ filtingHandler.setFilterDuplicate(true);
+ filtingHandler.setFilterFuture(true);
+ filtingHandler.setFilterApproximate(true);
+ filtingHandler.setFilterStatic(true);
+ filtingHandler.setFilterDistance(10);
+ filtingHandler.setFilterLimit(10);
}
@After