@Test public void testThresholdCrossedAscending() throws Exception { BoundedThresholdManager thresholdManager = new BoundedThresholdManager("foo"); ThresholdValues thresholdValues = new ThresholdValues(0, 5); thresholdManager.setThresholdValues(thresholdValues); MyThresholdListener listener = new MyThresholdListener(); thresholdManager.addThresholdListener(listener); for(Calculable calculable : makeCalculables(20)) { thresholdManager.checkThreshold(calculable); } Assert.assertEquals(14, 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);  }