Package games.stendhal.server.util
Class IntRingBuffer
java.lang.Object
games.stendhal.server.util.IntRingBuffer
a ring buffer for ints.
Note: This class is optimized for performance and memory usage.
That's why it is used in stead of a linked list with throw-away
Integer objects.
- Author:
- hendrik
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
add(int item)
adds an item to the bufferboolean
isEmpty()
Is the buffer empty?boolean
isFull()
Is the buffer full?boolean
removes the oldest items from the buffervoid
removeSmaller(int value)
removes all values smaller than the specified one from the trail.
-
Constructor Details
-
IntRingBuffer
public IntRingBuffer(int size)creates a new IntRingBuffer- Parameters:
size
- size of the buffer.
-
-
Method Details
-
isEmpty
public boolean isEmpty()Is the buffer empty?- Returns:
- true, if the buffer is empty, false otherwise
-
isFull
public boolean isFull()Is the buffer full?- Returns:
- true, if the buffer cannot accept more items, false otherwise
-
add
public boolean add(int item)adds an item to the buffer- Parameters:
item
- item- Returns:
- true, if the item was added succesfully; false, if the buffer is full
-
removeOldest
public boolean removeOldest()removes the oldest items from the buffer- Returns:
- true, if the item was removed succesfully; false, if the buffer was empty
-
removeSmaller
public void removeSmaller(int value)removes all values smaller than the specified one from the trail.- Parameters:
value
- value
-