Class
caplin.core

SlidingWindow

Constructor Summary

Attributes Name and Description
caplin.core.SlidingWindow( nSize)

Creates a SlidingWindow, which allows a maximum number of items to be stored.

Method Summary

Attributes Name and Description
void clear()

Clears all items from this SlidingWindow and resets it.

void forEach(Function func)

Iterates over each of the items in this window from oldest to newest.

void get( n)

void getSize()

void newest()

void oldest()

void push(Object oObject)

Adds an item into the end of this sliding window, possibly pushing an item out of the window in the process.

void setSize(Number nNewSize)

Changes the size of a SlidingWindow.

String toString()

Constructor Detail

caplin.core.SlidingWindow( nSize)

Creates a SlidingWindow, which allows a maximum number of items to be stored.

Parameters
nSize {Number} The maximum size of this window. This must be an integer larger than 0.

Method Detail

void clear()

Clears all items from this SlidingWindow and resets it.

void forEach(Function func)

Iterates over each of the items in this window from oldest to newest.

Parameters
Function func a function that will be called with each item.

void get( n)

Parameters
n {Number} the index of the item to be returned.
Returns
the nth oldest item that is stored or undefined if the index is larger than the number of items stored.

void getSize()

Returns
the number of items in this window.

void newest()

Returns
the item most recently added into this SlidingWindow, or null if no items have been added.

void oldest()

Returns
the oldest item that is still in this SlidingWindow or null if no items have been added.

void push(Object oObject)

Adds an item into the end of this sliding window, possibly pushing an item out of the window in the process.

Parameters
Object oObject an item to add into this window.
Returns
the item that was pushed out of the window or null if the window is not full.

void setSize(Number nNewSize)

Changes the size of a SlidingWindow. This operation should not be expected to be performant; do not do it often. If the new size is smaller than the number of items in this window, this operation may cause some objects to be pushed out of the window.

Parameters
Number nNewSize the new size the window should take up. Must be a positive integer.

String toString()

Returns
{String} Returns a string representation of this SlidingWindow. This is intended to be human readable for debugging and may change.