Class BoundedBuffer
- java.lang.Object
-
- org.apache.commons.collections.collection.SynchronizedCollection
-
- org.apache.commons.collections.buffer.SynchronizedBuffer
-
- org.apache.commons.collections.buffer.BoundedBuffer
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Iterable
,java.util.Collection
,BoundedCollection
,Buffer
@Deprecated(since="2021-04-30") public class BoundedBuffer extends SynchronizedBuffer implements BoundedCollection
Deprecated.Commons Collections 3 is in maintenance mode. Commons Collections 4 should be used instead.Decorates anotherBuffer
to ensure a fixed maximum size.Note: This class should only be used if you need to add bounded behaviour to another buffer. If you just want a bounded buffer then you should use
BoundedFifoBuffer
orCircularFifoBuffer
.The decoration methods allow you to specify a timeout value. This alters the behaviour of the add methods when the buffer is full. Normally, when the buffer is full, the add method will throw an exception. With a timeout, the add methods will wait for up to the timeout period to try and add the elements.
- Since:
- Commons Collections 3.2
- See Also:
- Serialized Form
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description boolean
add(java.lang.Object o)
Deprecated.boolean
addAll(java.util.Collection c)
Deprecated.static BoundedBuffer
decorate(Buffer buffer, int maximumSize)
Deprecated.Factory method to create a bounded buffer.static BoundedBuffer
decorate(Buffer buffer, int maximumSize, long timeout)
Deprecated.Factory method to create a bounded buffer that blocks for a maximum amount of time.boolean
isFull()
Deprecated.Returns true if this collection is full and no new elements can be added.java.util.Iterator
iterator()
Deprecated.Iterators must be manually synchronized.int
maxSize()
Deprecated.Gets the maximum size of the collection (the bound).java.lang.Object
remove()
Deprecated.Gets and removes the next object from the buffer.-
Methods inherited from class org.apache.commons.collections.buffer.SynchronizedBuffer
decorate, get
-
Methods inherited from class org.apache.commons.collections.collection.SynchronizedCollection
clear, contains, containsAll, decorate, equals, hashCode, isEmpty, remove, removeAll, retainAll, size, toArray, toArray, toString
-
-
-
-
Method Detail
-
decorate
public static BoundedBuffer decorate(Buffer buffer, int maximumSize)
Deprecated.Factory method to create a bounded buffer.When the buffer is full, it will immediately throw a
BufferOverflowException
on callingadd()
.- Parameters:
buffer
- the buffer to decorate, must not be nullmaximumSize
- the maximum size, must be size one or greater- Returns:
- a new bounded buffer
- Throws:
java.lang.IllegalArgumentException
- if the buffer is nulljava.lang.IllegalArgumentException
- if the maximum size is zero or less
-
decorate
public static BoundedBuffer decorate(Buffer buffer, int maximumSize, long timeout)
Deprecated.Factory method to create a bounded buffer that blocks for a maximum amount of time.- Parameters:
buffer
- the buffer to decorate, must not be nullmaximumSize
- the maximum size, must be size one or greatertimeout
- the maximum amount of time to wait in milliseconds- Returns:
- a new bounded buffer
- Throws:
java.lang.IllegalArgumentException
- if the buffer is nulljava.lang.IllegalArgumentException
- if the maximum size is zero or less
-
remove
public java.lang.Object remove()
Deprecated.Description copied from interface:Buffer
Gets and removes the next object from the buffer.- Specified by:
remove
in interfaceBuffer
- Overrides:
remove
in classSynchronizedBuffer
- Returns:
- the next object in the buffer, which is also removed
-
add
public boolean add(java.lang.Object o)
Deprecated.- Specified by:
add
in interfacejava.util.Collection
- Overrides:
add
in classSynchronizedCollection
-
addAll
public boolean addAll(java.util.Collection c)
Deprecated.- Specified by:
addAll
in interfacejava.util.Collection
- Overrides:
addAll
in classSynchronizedCollection
-
iterator
public java.util.Iterator iterator()
Deprecated.Description copied from class:SynchronizedCollection
Iterators must be manually synchronized.synchronized (coll) { Iterator it = coll.iterator(); // do stuff with iterator }
- Specified by:
iterator
in interfacejava.util.Collection
- Specified by:
iterator
in interfacejava.lang.Iterable
- Overrides:
iterator
in classSynchronizedCollection
- Returns:
- an iterator that must be manually synchronized on the collection
-
isFull
public boolean isFull()
Deprecated.Description copied from interface:BoundedCollection
Returns true if this collection is full and no new elements can be added.- Specified by:
isFull
in interfaceBoundedCollection
- Returns:
true
if the collection is full
-
maxSize
public int maxSize()
Deprecated.Description copied from interface:BoundedCollection
Gets the maximum size of the collection (the bound).- Specified by:
maxSize
in interfaceBoundedCollection
- Returns:
- the maximum number of elements the collection can hold
-
-