Class DataPool<T>
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanStore an element with a random expiration number between 0 and 99, that will be compared to the set expiration number.booleanStores a data element if the max size of the pool is not yet reached.voidclear()Clear the contentGet a data row exclusively, return null otherwise.intintgetMax()Returns the current maximum permitted pool size.intgetSize()Returns the current size of the data pool.voidsetExpireRate(int rate) Set a new expiration rate.voidsetMax(int max) Sets the new max, will shrink the data pool if needed.
-
Constructor Details
-
DataPool
public DataPool(int max, int expirationRate) Constructor- Parameters:
max- amount of data to store, will be set to 1 if argument is equal to or less than zeroexpirationRate- 0 means nothing will expire, 100 means all will expire, rest is a rate in percent
-
DataPool
public DataPool()Constructor.
-
-
Method Details
-
getDataElement
Get a data row exclusively, return null otherwise. The element will be removed from the data storage and cannot be accessed by others. To reuse, it has to be added again.
The first element of the data pool will be returned.
- Returns:
- a data row or null, if none available
-
add
Stores a data element if the max size of the pool is not yet reached. If the max size is reached, an expiration limit determines, whether or not the data is kept or added.
If the pool expiration rate is 100, elements will never be added. If the pool expiration rate is 0, elements will always be added. If the provided expiration rate is bigger than the expiration rate of the pool, the element will be added, otherwise it will not.
So if the set expiration rate of the pool is 60 (like 60%) and the provided rate is 61, the data will be added, if the rate is 60 or below that, the data will not be added.
If the data pool is full, the first element is removed before new data is added.
- Parameters:
element- the data to storerate- the rate to use (will be compared to the set expiration rate)- Returns:
- true if data was stored, false otherwise
-
add
Store an element with a random expiration number between 0 and 99, that will be compared to the set expiration number.- Parameters:
element- a data element to store- Returns:
- true if element was stored, false otherwise
-
getExpireRate
public int getExpireRate()- Returns:
- Returns the expireRate.
-
setExpireRate
public void setExpireRate(int rate) Set a new expiration rate. The current content is not affected.- Parameters:
rate- the new rate to use
-
getMax
public int getMax()Returns the current maximum permitted pool size.- Returns:
- the max number of elements to be stored.
-
getSize
public int getSize()Returns the current size of the data pool.- Returns:
- the current size of the data pool
-
setMax
public void setMax(int max) Sets the new max, will shrink the data pool if needed. The elements will be removed according to FIFO.- Parameters:
max- the new maximum size of the pool, will be set to 1 if argument is equal to or less than zero
-
clear
public void clear()Clear the content
-