Class BoundedBufferMap<K,V>
- java.lang.Object
-
- com.tagtraum.beatunes.analysisqueue.BoundedBufferMap<K,V>
-
public class BoundedBufferMap<K,V> extends Object
Bounded Buffer Map.- Author:
- Hendrik Schreiber
-
-
Constructor Summary
Constructors Constructor Description BoundedBufferMap()
BoundedBufferMap(int capacity)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Removes all of the mappings from this map.int
getCapacity()
boolean
isEmpty()
Returnstrue
if this map contains no key-value mappingsboolean
isFull()
Indicates whether the map is full.boolean
offer(K key, V value, long timeOut, TimeUnit timeUnit)
Inserts the specified key value pair into the map, waiting up to the specified wait time for space to become available if the map is full.V
peek(K key)
Retrieves the value, but does not remove, the key value pair of this map, or returns null if the value cannot be found.V
poll(K key, long timeOut, TimeUnit timeUnit)
Retrieves and removes a value from this map, waiting up to the specified wait time if necessary for the key to become available.int
size()
Returns the number of key-value mappings in this map.
-
-
-
Method Detail
-
getCapacity
public int getCapacity()
-
offer
public boolean offer(K key, V value, long timeOut, TimeUnit timeUnit) throws InterruptedException
Inserts the specified key value pair into the map, waiting up to the specified wait time for space to become available if the map is full.- Parameters:
key
- keyvalue
- valuetimeOut
- time outtimeUnit
- unit- Returns:
true
if successful, orfalse
if the specified waiting time elapses before space is available- Throws:
InterruptedException
- if interrupted while waiting
-
poll
public V poll(K key, long timeOut, TimeUnit timeUnit) throws InterruptedException
Retrieves and removes a value from this map, waiting up to the specified wait time if necessary for the key to become available.- Parameters:
key
- keytimeOut
- time outtimeUnit
- unit- Returns:
- the value for the given key if successful, or
null
if the specified waiting time elapses before the corresponding value was added - Throws:
InterruptedException
- if interrupted while waiting
-
peek
public V peek(K key)
Retrieves the value, but does not remove, the key value pair of this map, or returns null if the value cannot be found.- Parameters:
key
- key- Returns:
- value or null
-
isEmpty
public boolean isEmpty()
Returnstrue
if this map contains no key-value mappings- Returns:
true
if this map contains no key-value mappings
-
isFull
public boolean isFull()
Indicates whether the map is full.- Returns:
- true or false.
-
size
public int size()
Returns the number of key-value mappings in this map.- Returns:
- the number of key-value mappings in this map
-
clear
public void clear()
Removes all of the mappings from this map. The map will be empty after this call returns.
-
-