@Test public void filterValue1() { final int maxQueueSize = 10; QuickChangeFilter filter = new QuickChangeFilter(10,maxQueueSize); double[] dataSet = {1,2,3,50,5,6,-50,8,9,10}; for (int i = 0; i < maxQueueSize; i++) { assertTrue(dataSet[i] == filter.filterValue(dataSet[i])); } for (double d: dataSet) { double filteredValue = filter.filterValue(d); assertTrue(filteredValue<=10 && filteredValue>=1); } }
public double filterValue(double unfilteredValue){ double averageInput = calculateAverageInput(); if (previousInput.size() < maxQueueSize){ previousInput.addFirst(unfilteredValue); lastReturn = unfilteredValue; return unfilteredValue; } previousInput.addFirst(unfilteredValue); previousInput.removeLast(); if (isAcceptableChange(unfilteredValue, lastReturn)){ lastReturn = unfilteredValue; return unfilteredValue; } if (isAcceptableChange(unfilteredValue, averageInput)){ lastReturn = unfilteredValue; return unfilteredValue; } return lastReturn; }
QuickChangeFilter implements Filter { public double filterValue(double unfilteredValue){ double averageInput = calculateAverageInput(); if (previousInput.size() < maxQueueSize){ previousInput.addFirst(unfilteredValue); lastReturn = unfilteredValue; return unfilteredValue; } previousInput.addFirst(unfilteredValue); previousInput.removeLast(); if (isAcceptableChange(unfilteredValue, lastReturn)){ lastReturn = unfilteredValue; return unfilteredValue; } if (isAcceptableChange(unfilteredValue, averageInput)){ lastReturn = unfilteredValue; return unfilteredValue; } return lastReturn; } }
QuickChangeFilter implements Filter { public double filterValue(double unfilteredValue){ double averageInput = calculateAverageInput(); if (previousInput.size() < maxQueueSize){ previousInput.addFirst(unfilteredValue); lastReturn = unfilteredValue; return unfilteredValue; } previousInput.addFirst(unfilteredValue); previousInput.removeLast(); if (isAcceptableChange(unfilteredValue, lastReturn)){ lastReturn = unfilteredValue; return unfilteredValue; } if (isAcceptableChange(unfilteredValue, averageInput)){ lastReturn = unfilteredValue; return unfilteredValue; } return lastReturn; } QuickChangeFilter(double acceptedChange, int maxQueueSize); }
QuickChangeFilter implements Filter { public double filterValue(double unfilteredValue){ double averageInput = calculateAverageInput(); if (previousInput.size() < maxQueueSize){ previousInput.addFirst(unfilteredValue); lastReturn = unfilteredValue; return unfilteredValue; } previousInput.addFirst(unfilteredValue); previousInput.removeLast(); if (isAcceptableChange(unfilteredValue, lastReturn)){ lastReturn = unfilteredValue; return unfilteredValue; } if (isAcceptableChange(unfilteredValue, averageInput)){ lastReturn = unfilteredValue; return unfilteredValue; } return lastReturn; } QuickChangeFilter(double acceptedChange, int maxQueueSize); double filterValue(double unfilteredValue); }
QuickChangeFilter implements Filter { public double filterValue(double unfilteredValue){ double averageInput = calculateAverageInput(); if (previousInput.size() < maxQueueSize){ previousInput.addFirst(unfilteredValue); lastReturn = unfilteredValue; return unfilteredValue; } previousInput.addFirst(unfilteredValue); previousInput.removeLast(); if (isAcceptableChange(unfilteredValue, lastReturn)){ lastReturn = unfilteredValue; return unfilteredValue; } if (isAcceptableChange(unfilteredValue, averageInput)){ lastReturn = unfilteredValue; return unfilteredValue; } return lastReturn; } QuickChangeFilter(double acceptedChange, int maxQueueSize); double filterValue(double unfilteredValue);  }