Example usage for org.apache.commons.collections.buffer CircularFifoBuffer CircularFifoBuffer

List of usage examples for org.apache.commons.collections.buffer CircularFifoBuffer CircularFifoBuffer

Introduction

In this page you can find the example usage for org.apache.commons.collections.buffer CircularFifoBuffer CircularFifoBuffer.

Prototype

public CircularFifoBuffer(Collection coll) 

Source Link

Document

Constructor that creates a buffer from the specified collection.

Usage

From source file:org.sipfoundry.sipxconfig.job.JobContextImpl.java

public void init() {
    m_jobs = new CircularFifoBuffer(m_maxJobs);
}

From source file:sintef.android.controller.sensor.SensorEventBuffer.java

private SensorEventBuffer() {
    /*/*from  w  w w.  j av  a2  s .co  m*/
    The buffer needs to hold at least two seconds worth of sensor events.
    The frequency is set to around 25Hz as we were not able to set it any higher.
    Therefor the size of the buffer is set to 3 * 25
     */
    fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(3 * 25));
}

From source file:sintef.android.controller.sensor.SensorEventBuffer.java

private SensorEventBuffer(int frequency) {
    /*//from   ww w  .  j a  v a2  s .co m
    Planned for the future: Get the actual maximum frequency of sensor events and
    use this value to instantiated the buffer.
     */
    fifo = BufferUtils.synchronizedBuffer(new CircularFifoBuffer(3 * frequency));
}

From source file:tools.descartes.wcf.management.timeSeries.TimeSeries.java

/**
 * //from  w  w  w  . j a  v a2 s .c  om
 * @param startTime:    The timestamp (absolute time in [ms]) 
 *                   of the first arrival rate value added to the time series is equal 
 *                   to the start time of the time series
 * @param deltaTime:   The constant time difference between two time series values is the Delta Time
 * @param deltaTimeUnit: This parameter defines the time unit of the DeltaTime parameter
 * @param frequency:   The Frequency is the number of time series points that add up either 
 *                   to the next bigger time unit and/or to the estimated length of 
 *                   seasonal patterns in focus. The value should not be too small 
 *                   (still able to approximate the shape of the seasonal pattern) 
 *                   and not to high (to limit the computational effort of 
 *                   complex forecast strategies)
 * @param maxPeriods   The amount of Frequency time series points form a period. 
 *                   This parameter defines the maximum number of periods that 
 *                   fit into the time series. As in a `fifo queue the oldest values fall 
 *                   off when more recent values are added. The value of this setting should 
 *                   be at least 3 to enable reliable pattern detection by complex forecast 
 *                   strategies and multiplied the by Frequency value not be higher than 
 *                   200 if the computational effort of more complex forecast strategies 
 *                   should stay below one minute. 
 * @param skippedValues: The number of time series points that have fallen 
 *                   of the time series due to capacity constraints by max_periods
 */
public TimeSeries(final Date startTime, final long deltaTime, final TimeUnit deltaTimeUnit, final int frequency,
        final int maxPeriods, long skippedValues) {
    this.startTime = startTime;
    this.deltaTime = deltaTime;
    this.deltaTimeUnit = deltaTimeUnit;
    this.frequency = frequency;
    this.maxPeriods = maxPeriods;
    this.capacity = frequency * maxPeriods;
    this.skippedValues = skippedValues;
    this.oneStepMillis = TimeUnit.MILLISECONDS.convert(this.deltaTime, this.deltaTimeUnit);

    this.points = new CircularFifoBuffer(this.capacity);

    this.nextTime = (Date) startTime.clone();
    this.setNextTime();
}

From source file:uk.ac.ebi.jmzml.xml.io.MzMLUnmarshaller.java

/**
 * Calcultes the check sum./* www.  ja  v a2  s.  c  o  m*/
 *
 * @return the check sum as hexidecimal
 */
private String calculateChecksum() {
    // we have to create the checksum for the mzML file (from its beginning to the
    // end of the fileChecksum start tag).
    // Since this stop location is very near the end of the file, we skip everything
    // until we come within a certain limit of the end of the file
    long limit = mzMLFile.length() - 200L;
    logger.debug("Looking for fileChecksum tag between byte " + limit + " and byte " + mzMLFile.length()
            + " (the end) of the mzML file.");

    // initialize the hash algorithm
    MessageDigest hash;
    try {
        hash = MessageDigest.getInstance("SHA-1");
    } catch (NoSuchAlgorithmException e) {
        throw new IllegalStateException("SHA-1 not recognized as Secure Hash Algorithm.", e);
    }

    // create the input stream that will calculate the checksum
    FileInputStream fis;
    try {
        fis = new FileInputStream(mzMLFile);
    } catch (FileNotFoundException e) {
        throw new IllegalStateException("File " + mzMLFile.getAbsoluteFile() + " could not be found!", e);
    }
    BufferedInputStream bis = new BufferedInputStream(fis);
    DigestInputStream dis = new DigestInputStream(bis, hash);

    // prepare for input stream processing
    // we read through the file until we reach a specified limit before the end of the file
    // from there we populate a buffer with the read bytes (characters) and check if we have
    // already reached the position up to where we have to calculate the hash.
    CircularFifoBuffer bBuf = new CircularFifoBuffer(15);
    long cnt = 0; // counter to keep track of our position
    byte[] b = new byte[1]; // we only read one byte at a time
    try {
        while (dis.read(b) >= 0) {
            bBuf.add(b[0]);
            cnt++;
            // check if we have already reached the last bit of the file, where we have
            // to find the right position to stop (after the 'fileChecksum' start tag)
            if (cnt > limit) {
                // we should have reached the start of the <fileChecksum> tag,
                // now we have to find the end
                String readBuffer = convert2String(bBuf);
                if (readBuffer.endsWith("<fileChecksum>")) {
                    // we have found the end of the fileChecksum start tag, we have to stop the hash
                    if (b[0] != '>') { // check that we are really at the last character of the tag
                        throw new IllegalStateException("We are not at the end of <fileChecksum> tag!");
                    }
                    break;
                }
            } // else if not yet near the end of the file, just keep on going
        }
        dis.close();
    } catch (IOException e) {
        throw new IllegalStateException(
                "Could not read from file '" + mzMLFile.getAbsolutePath() + "' while trying ot calculate hash.",
                e);
    }
    logger.debug("Read over " + cnt + " bytes while calculating the file hash.");

    byte[] bytesDigest = dis.getMessageDigest().digest();

    return asHex(bytesDigest);
}

From source file:VQVAD.VQVADTrainer.java

/**
 * Create a trainer with default values. Should work fine for most cases.
 *///from   ww  w .  jav  a 2s  . co  m
public VQVADTrainer() {
    trainingFrameBuffer = new CircularFifoBuffer(DEFAULT_FRAME_BUFFER_SIZE);
    clusterer = new KMeansPlusPlusClusterer<DoublePoint>(vqSize, DEFAULT_KMEANS_MAX_ITER);
}

From source file:VQVAD.VQVADTrainer.java

/**
 * See the class documentation for a full explanation of the parameters.
 *
 * @param trainingBufferSize//from   w  w w  .j  av  a2  s .  c  o m
 * @param energyMinLevel
 * @param energyFraction
 * @param vqSize
 * @param maxKMeansIter
 */
public VQVADTrainer(int trainingBufferSize, int minFrameCount, double energyMinLevel, double energyFraction,
        int vqSize, int maxKMeansIter) {
    this.minFrameCount = minFrameCount;
    this.energyMinLevel = energyMinLevel;
    this.energyFraction = energyFraction;
    this.vqSize = vqSize;

    trainingFrameBuffer = new CircularFifoBuffer(trainingBufferSize);
    clusterer = new KMeansPlusPlusClusterer<DoublePoint>(vqSize, maxKMeansIter);
}