List of usage examples for org.apache.commons.collections15.buffer CircularFifoBuffer CircularFifoBuffer
public CircularFifoBuffer(Collection<E> coll)
From source file:eu.crisis_economics.abm.household.plugins.UnemploymentBasedWageAskAlgorithm.java
public UnemploymentBasedWageAskAlgorithm(double initialLabourWage, double wageAdaptationRate, double minimumWage, EmploymentProportionCallback employmentProportionCallback) { super(initGuard(initialLabourWage)); if (employmentProportionCallback == null) throw new NullArgumentException(); this.wagePerturbation = wageAdaptationRate * initialLabourWage; this.dice = new Random(Simulation.getSimState().random.nextLong()); this.employmentPropCallback = employmentProportionCallback; this.wageConfidence = new CircularFifoBuffer<Double>(5); this.minimumWage = minimumWage; wageConfidence.add(0.0);/*from ww w .j a va 2 s . c om*/ }
From source file:eu.crisis_economics.utilities.EmpiricalDistribution.java
public EmpiricalDistribution(int memoryLength) { m_dataStream = new CircularFifoBuffer<Double>(memoryLength); m_sortedData = new TreeSet<EmpiricalDistribution.SortedDatum>(); lastValueInserted = Double.NaN; }
From source file:eu.crisis_economics.abm.algorithms.portfolio.returns.MedianOverHistoryStockReturnExpectationFunction.java
@Override public double computeExpectedReturn(final String stockName) { if (!memory.containsKey(stockName)) memory.put(stockName, new CircularFifoBuffer<Double>(sizeOfMemory)); final double returnEstimate = expectationFunction.computeExpectedReturn(stockName); memory.get(stockName).add(returnEstimate); return medianOfSeries(ArrayUtils.asDouble(memory.get(stockName).toArray(new Double[0]))); }
From source file:io.s4.core.WindowingPE.java
/** * Add an object to the sliding window. Use it when the window is not * periodic. For periodic slots use {@link #addPeriodicSlot()} instead. * // w w w. j a v a 2 s .co m * @param slot */ protected void addSlot(T slot) { if (timer != null) { logger.error("Calling method addSlot() in a periodic window is not allowed."); return; } if (circularBuffer == null) { circularBuffer = new CircularFifoBuffer<T>(numSlots); } circularBuffer.add(slot); }
From source file:ch.algotrader.esper.aggregation.GenericTALibFunction.java
public GenericTALibFunction(CoreAnnotated core, Method function, int inputParamCount, int lookbackPeriod, List<Object> optInputParams, Map<String, Object> outputParams, Class<?> outputClass) { super();// www. java 2 s .co m this.core = core; this.function = function; this.outputClass = outputClass; this.optInputParams = optInputParams; this.outputParams = outputParams; this.inputParams = new ArrayList<>(); for (int i = 0; i < inputParamCount; i++) { this.inputParams.add(new CircularFifoBuffer<>(lookbackPeriod)); } }
From source file:edu.brown.profilers.ProfileMeasurement.java
public void enableHistoryTracking() { if (this.history == null) { synchronized (this) { if (this.history == null) { this.history = new CircularFifoBuffer<Long>(10000); }//w ww . ja v a2s. c o m } // SYNCH if (debug.val) LOG.debug("Enabled history tracking in " + this); } }
From source file:ch.algotrader.esper.aggregation.GenericTALibFunctionFactory.java
@Override public void validate(AggregationValidationContext validationContext) { this.core = new CoreAnnotated(); Class<?>[] paramTypes = validationContext.getParameterTypes(); // get the functionname String talibFunctionName = (String) getConstant(validationContext, 0, String.class); // get the method by iterating over all core-methods // we have to do it this way, since we don't have the exact parameters for (Method method : this.core.getClass().getDeclaredMethods()) { if (method.getName().equals(talibFunctionName)) { this.function = method; break; }/*from w w w. jav a 2 s . com*/ } // check that we have a function now if (this.function == null) { throw new IllegalArgumentException("function " + talibFunctionName + " was not found"); } // get the parameters int paramCounter = 1; Map<String, Class<?>> outputParamTypes = new HashMap<>(); for (Annotation[] annotations : this.function.getParameterAnnotations()) { for (Annotation annotation : annotations) { // got through all inputParameters and count them if (annotation instanceof InputParameterInfo) { InputParameterInfo inputParameterInfo = (InputParameterInfo) annotation; if (inputParameterInfo.type().equals(InputParameterType.TA_Input_Real)) { if (paramTypes[paramCounter].equals(double.class) || paramTypes[paramCounter].equals(Double.class)) { this.inputParamCount++; paramCounter++; } else { throw new IllegalArgumentException( "param number " + paramCounter + " must be of type double"); } } else if (inputParameterInfo.type().equals(InputParameterType.TA_Input_Integer)) { if (paramTypes[paramCounter].equals(int.class) || paramTypes[paramCounter].equals(Integer.class)) { this.inputParamCount++; paramCounter++; } else { throw new IllegalArgumentException( "param number " + paramCounter + " must be of type int"); } } else if (inputParameterInfo.type().equals(InputParameterType.TA_Input_Price)) { // the flags define the number of parameters in use by a bitwise or int priceParamSize = numberOfSetBits(inputParameterInfo.flags()); for (int i = 0; i < priceParamSize; i++) { if (paramTypes[paramCounter].equals(double.class) || paramTypes[paramCounter].equals(Double.class)) { this.inputParamCount++; paramCounter++; } else { throw new IllegalArgumentException( "param number " + paramCounter + " must be of type double"); } } } // got through all optInputParameters and store them for later } else if (annotation instanceof OptInputParameterInfo) { OptInputParameterInfo optInputParameterInfo = (OptInputParameterInfo) annotation; if (optInputParameterInfo.type().equals(OptInputParameterType.TA_OptInput_IntegerRange)) { this.optInputParams.add(getConstant(validationContext, paramCounter, Integer.class)); } else if (optInputParameterInfo.type().equals(OptInputParameterType.TA_OptInput_RealRange)) { this.optInputParams.add(getConstant(validationContext, paramCounter, Double.class)); } else if (optInputParameterInfo.type().equals(OptInputParameterType.TA_OptInput_IntegerList)) { String value = (String) getConstant(validationContext, paramCounter, String.class); MAType type = MAType.valueOf(value); this.optInputParams.add(type); } paramCounter++; // to through all outputParameters and store them } else if (annotation instanceof OutputParameterInfo) { OutputParameterInfo outputParameterInfo = (OutputParameterInfo) annotation; String paramName = outputParameterInfo.paramName(); if (outputParameterInfo.type().equals(OutputParameterType.TA_Output_Real)) { this.outputParams.put(paramName, new double[1]); outputParamTypes.put(paramName.toLowerCase().substring(3), double.class); } else if (outputParameterInfo.type().equals(OutputParameterType.TA_Output_Integer)) { this.outputParams.put(outputParameterInfo.paramName(), new int[1]); outputParamTypes.put(paramName.toLowerCase().substring(3), int.class); } } } } // get unstable period int unstablePeriod = 0; if (paramTypes.length == paramCounter + 1) { unstablePeriod = (int) getConstant(validationContext, paramCounter, Integer.class); paramCounter++; } if (paramTypes.length > paramCounter) { throw new IllegalArgumentException("too many params, expected " + paramCounter + " or " + (paramCounter + 1) + " found " + paramTypes.length); } try { // get the dynamically created output class if (this.outputParams.size() > 1) { String className = StringUtils.capitalize(talibFunctionName); this.outputClass = getReturnClass(className, outputParamTypes); } // get the lookback size Object[] args = new Object[this.optInputParams.size()]; Class<?>[] argTypes = new Class[this.optInputParams.size()]; // supply all optInputParams int argCount = 0; for (Object object : this.optInputParams) { args[argCount] = object; Class<?> clazz = object.getClass(); Class<?> primitiveClass = ClassUtils.wrapperToPrimitive(clazz); if (primitiveClass != null) { argTypes[argCount] = primitiveClass; } else { argTypes[argCount] = clazz; } argCount++; } // set unstable period if (unstablePeriod > 0) { for (FuncUnstId value : FuncUnstId.values()) { this.core.SetUnstablePeriod(value, 50); } } // get and invoke the lookback method Method lookback = this.core.getClass().getMethod(talibFunctionName + "Lookback", argTypes); this.lookbackPeriod = (Integer) lookback.invoke(this.core, args) + 1; // create the fixed size Buffers for (int i = 0; i < this.inputParamCount; i++) { this.inputParams.add(new CircularFifoBuffer<>(this.lookbackPeriod)); } } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.apache.s4.core.TestCircularFifoBuffer.java
public void test1() { System.out.println("Buffer size is 10.\n"); CircularFifoBuffer<Integer> circularBuffer = new CircularFifoBuffer<Integer>(10); System.out.println("Add ints 100-114."); for (int i = 0; i < 15; i++) { circularBuffer.add(i + 100);/* w w w.j a v a 2 s . c o m*/ } System.out.println("Iterate."); int j = 5; for (Integer num : circularBuffer) { System.out.print(num + " "); Assert.assertEquals(j + 100, num.intValue()); j++; } System.out.println("\nLeast recent value: " + circularBuffer.get()); Assert.assertEquals(105, circularBuffer.get().intValue()); System.out.println("\n"); circularBuffer.clear(); /* Less than max size. */ System.out.println("Clear and add ints 200-204."); for (int i = 0; i < 5; i++) { circularBuffer.add(i + 200); } System.out.println("Iterate."); int z = 0; for (Integer num : circularBuffer) { System.out.print(num + " "); Assert.assertEquals(z + 200, num.intValue()); z++; } System.out.println("\n"); }
From source file:org.apache.s4.core.window.AbstractSlidingWindowPE.java
@Override protected void onCreate() { eventCount = 0;/*from www. j a v a 2s .c o m*/ circularBuffer = new CircularFifoBuffer<T>(numSlots); if (slotDurationInMilliseconds > 0) { openSlot = slotFactory.createSlot(); circularBuffer.add(openSlot); } }