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 voidclear()Removes all of the mappings from this map.intgetCapacity()booleanisEmpty()Returnstrueif this map contains no key-value mappingsbooleanisFull()Indicates whether the map is full.booleanoffer(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.Vpeek(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.Vpoll(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.intsize()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:
trueif successful, orfalseif 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
nullif 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()
Returnstrueif this map contains no key-value mappings- Returns:
trueif 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.
-
-