@Test public void recursiveCachedIndicatorOnMovingTimeSeriesShouldNotCauseStackOverflow() { series = new MockTimeSeries(); series.setMaximumTickCount(5); assertEquals(5, series.getTickCount()); ZLEMAIndicator zlema = new ZLEMAIndicator(new ClosePriceIndicator(series), 1); try { assertDecimalEquals(zlema.getValue(8), "9"); } catch (Throwable t) { fail(t.getMessage()); } }
@Override public T getValue(int index) { TimeSeries series = getTimeSeries(); if (series == null) { return calculate(index); } final int removedTicksCount = series.getRemovedTicksCount(); final int maximumResultCount = series.getMaximumTickCount(); T result; if (index < removedTicksCount) { log.trace("{}: result from tick {} already removed from cache, use {}-th instead", getClass().getSimpleName(), index, removedTicksCount); increaseLengthTo(removedTicksCount, maximumResultCount); highestResultIndex = removedTicksCount; result = results.get(0); if (result == null) { result = calculate(0); results.set(0, result); } } else { increaseLengthTo(index, maximumResultCount); if (index > highestResultIndex) { highestResultIndex = index; result = calculate(index); results.set(results.size()-1, result); } else { int resultInnerIndex = results.size() - 1 - (highestResultIndex - index); result = results.get(resultInnerIndex); if (result == null) { result = calculate(index); } results.set(resultInnerIndex, result); } } return result; }
CachedIndicator extends AbstractIndicator<T> { @Override public T getValue(int index) { TimeSeries series = getTimeSeries(); if (series == null) { return calculate(index); } final int removedTicksCount = series.getRemovedTicksCount(); final int maximumResultCount = series.getMaximumTickCount(); T result; if (index < removedTicksCount) { log.trace("{}: result from tick {} already removed from cache, use {}-th instead", getClass().getSimpleName(), index, removedTicksCount); increaseLengthTo(removedTicksCount, maximumResultCount); highestResultIndex = removedTicksCount; result = results.get(0); if (result == null) { result = calculate(0); results.set(0, result); } } else { increaseLengthTo(index, maximumResultCount); if (index > highestResultIndex) { highestResultIndex = index; result = calculate(index); results.set(results.size()-1, result); } else { int resultInnerIndex = results.size() - 1 - (highestResultIndex - index); result = results.get(resultInnerIndex); if (result == null) { result = calculate(index); } results.set(resultInnerIndex, result); } } return result; } }
CachedIndicator extends AbstractIndicator<T> { @Override public T getValue(int index) { TimeSeries series = getTimeSeries(); if (series == null) { return calculate(index); } final int removedTicksCount = series.getRemovedTicksCount(); final int maximumResultCount = series.getMaximumTickCount(); T result; if (index < removedTicksCount) { log.trace("{}: result from tick {} already removed from cache, use {}-th instead", getClass().getSimpleName(), index, removedTicksCount); increaseLengthTo(removedTicksCount, maximumResultCount); highestResultIndex = removedTicksCount; result = results.get(0); if (result == null) { result = calculate(0); results.set(0, result); } } else { increaseLengthTo(index, maximumResultCount); if (index > highestResultIndex) { highestResultIndex = index; result = calculate(index); results.set(results.size()-1, result); } else { int resultInnerIndex = results.size() - 1 - (highestResultIndex - index); result = results.get(resultInnerIndex); if (result == null) { result = calculate(index); } results.set(resultInnerIndex, result); } } return result; } CachedIndicator(TimeSeries series);  CachedIndicator(Indicator indicator); }
CachedIndicator extends AbstractIndicator<T> { @Override public T getValue(int index) { TimeSeries series = getTimeSeries(); if (series == null) { return calculate(index); } final int removedTicksCount = series.getRemovedTicksCount(); final int maximumResultCount = series.getMaximumTickCount(); T result; if (index < removedTicksCount) { log.trace("{}: result from tick {} already removed from cache, use {}-th instead", getClass().getSimpleName(), index, removedTicksCount); increaseLengthTo(removedTicksCount, maximumResultCount); highestResultIndex = removedTicksCount; result = results.get(0); if (result == null) { result = calculate(0); results.set(0, result); } } else { increaseLengthTo(index, maximumResultCount); if (index > highestResultIndex) { highestResultIndex = index; result = calculate(index); results.set(results.size()-1, result); } else { int resultInnerIndex = results.size() - 1 - (highestResultIndex - index); result = results.get(resultInnerIndex); if (result == null) { result = calculate(index); } results.set(resultInnerIndex, result); } } return result; } CachedIndicator(TimeSeries series);  CachedIndicator(Indicator indicator); @Override T getValue(int index); }
CachedIndicator extends AbstractIndicator<T> { @Override public T getValue(int index) { TimeSeries series = getTimeSeries(); if (series == null) { return calculate(index); } final int removedTicksCount = series.getRemovedTicksCount(); final int maximumResultCount = series.getMaximumTickCount(); T result; if (index < removedTicksCount) { log.trace("{}: result from tick {} already removed from cache, use {}-th instead", getClass().getSimpleName(), index, removedTicksCount); increaseLengthTo(removedTicksCount, maximumResultCount); highestResultIndex = removedTicksCount; result = results.get(0); if (result == null) { result = calculate(0); results.set(0, result); } } else { increaseLengthTo(index, maximumResultCount); if (index > highestResultIndex) { highestResultIndex = index; result = calculate(index); results.set(results.size()-1, result); } else { int resultInnerIndex = results.size() - 1 - (highestResultIndex - index); result = results.get(resultInnerIndex); if (result == null) { result = calculate(index); } results.set(resultInnerIndex, result); } } return result; } CachedIndicator(TimeSeries series);  CachedIndicator(Indicator indicator); @Override T getValue(int index);  }