@Test public void filterValue2(){ final int maxQueueSize = 10; QuickChangeFilter filter = new QuickChangeFilter(10,maxQueueSize); double[] zeroSet = {0,0,0,0,0,0,0,0,0,0}; for(double d: zeroSet){ double filteredValue = filter.filterValue(d); } double[] giantSet = {20,20,20,20,20,20,20,20,20,20}; for (int i = 0; i < maxQueueSize/2 +1; i++){ double filteredValue = filter.filterValue(giantSet[i]); assertTrue(filteredValue == 0); } for (int i = 0; i < maxQueueSize/2 -1; i++){ double filteredValue = filter.filterValue(giantSet[i]); assertTrue(filteredValue == 20); } }
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);  }