@Test public void testThresholdCrossedDescendingWithStep() throws Exception { BoundedThresholdManager thresholdManager = new BoundedThresholdManager("foo"); ThresholdValues thresholdValues = new ThresholdValues(30, 50, 2); thresholdManager.setThresholdValues(thresholdValues); MyThresholdListener listener = new MyThresholdListener(); thresholdManager.addThresholdListener(listener); List<Calculable> calculables = makeCalculables(50); Collections.reverse(calculables); for(Calculable calculable : calculables) { thresholdManager.checkThreshold(calculable); } for(Map.Entry<Integer, Calculable> entry : listener.breached.entrySet()) { System.out.println(entry.getValue().getValue()); } Assert.assertEquals(15, listener.breached.size()); }
public void checkThreshold(Calculable calculable) { ThresholdValues thresholdValues = getThresholdValues(); double value = calculable.getValue(); if(thresholdCrossed) { if(direction == BREACHED_UPPER) { if(value < thresholdValues.getHighThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkLowThresholdBreach(calculable); } else { checkHighThresholdBreach(calculable); } } else if(direction == BREACHED_LOWER) { if(value > thresholdValues.getLowThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkHighThresholdBreach(calculable); } else { checkLowThresholdBreach(calculable); } } } else { checkHighThresholdBreach(calculable); checkLowThresholdBreach(calculable); } }
BoundedThresholdManager extends ThresholdManager { public void checkThreshold(Calculable calculable) { ThresholdValues thresholdValues = getThresholdValues(); double value = calculable.getValue(); if(thresholdCrossed) { if(direction == BREACHED_UPPER) { if(value < thresholdValues.getHighThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkLowThresholdBreach(calculable); } else { checkHighThresholdBreach(calculable); } } else if(direction == BREACHED_LOWER) { if(value > thresholdValues.getLowThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkHighThresholdBreach(calculable); } else { checkLowThresholdBreach(calculable); } } } else { checkHighThresholdBreach(calculable); checkLowThresholdBreach(calculable); } } }
BoundedThresholdManager extends ThresholdManager { public void checkThreshold(Calculable calculable) { ThresholdValues thresholdValues = getThresholdValues(); double value = calculable.getValue(); if(thresholdCrossed) { if(direction == BREACHED_UPPER) { if(value < thresholdValues.getHighThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkLowThresholdBreach(calculable); } else { checkHighThresholdBreach(calculable); } } else if(direction == BREACHED_LOWER) { if(value > thresholdValues.getLowThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkHighThresholdBreach(calculable); } else { checkLowThresholdBreach(calculable); } } } else { checkHighThresholdBreach(calculable); checkLowThresholdBreach(calculable); } } BoundedThresholdManager(String id); }
BoundedThresholdManager extends ThresholdManager { public void checkThreshold(Calculable calculable) { ThresholdValues thresholdValues = getThresholdValues(); double value = calculable.getValue(); if(thresholdCrossed) { if(direction == BREACHED_UPPER) { if(value < thresholdValues.getHighThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkLowThresholdBreach(calculable); } else { checkHighThresholdBreach(calculable); } } else if(direction == BREACHED_LOWER) { if(value > thresholdValues.getLowThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkHighThresholdBreach(calculable); } else { checkLowThresholdBreach(calculable); } } } else { checkHighThresholdBreach(calculable); checkLowThresholdBreach(calculable); } } BoundedThresholdManager(String id); boolean getThresholdCrossed(); void checkThreshold(Calculable calculable); }
BoundedThresholdManager extends ThresholdManager { public void checkThreshold(Calculable calculable) { ThresholdValues thresholdValues = getThresholdValues(); double value = calculable.getValue(); if(thresholdCrossed) { if(direction == BREACHED_UPPER) { if(value < thresholdValues.getHighThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkLowThresholdBreach(calculable); } else { checkHighThresholdBreach(calculable); } } else if(direction == BREACHED_LOWER) { if(value > thresholdValues.getLowThreshold()) { thresholdCrossed = false; direction = CLEARED; thresholdValues.incThresholdClearedCount(); notifyListeners(calculable, ThresholdType.CLEARED); checkHighThresholdBreach(calculable); } else { checkLowThresholdBreach(calculable); } } } else { checkHighThresholdBreach(calculable); checkLowThresholdBreach(calculable); } } BoundedThresholdManager(String id); boolean getThresholdCrossed(); void checkThreshold(Calculable calculable);  }