com.unister.semweb.drums.bucket
Class Bucket<Data extends AbstractKVStorable>

java.lang.Object
  extended by com.unister.semweb.drums.bucket.Bucket<Data>
Type Parameters:
Data - an implementation of AbstractKVStorable, e.g. GeneralStorable

public class Bucket<Data extends AbstractKVStorable>
extends java.lang.Object

An instance of this class is a container of AbstractKVStorables.

Author:
Martin Nettling, Nils Thieme

Field Summary
 int elementsInBucket
          the number of elements in this bucket.
 
Constructor Summary
Bucket(int bucketId, DRUMSParameterSet<Data> gp)
          Constructor.
 
Method Summary
 boolean add(AbstractKVStorable toAdd)
          Adds one AbstractKVStorable-object.
 boolean contains(Data element)
           
 int freeMemory()
          This method frees the allocated memory.
 Data[] getBackend()
          Returns the in backend stored AbstractKVStorables.
 int getBucketId()
           
 long getCreationTime()
           
 java.nio.ByteBuffer getElementAt(int index)
           
 Bucket<Data> getEmptyBucketWithSameProperties()
          returns a new empty Bucket with the same properties of this bucket
 int size()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

elementsInBucket

public int elementsInBucket
the number of elements in this bucket. For faster access, should be public

Constructor Detail

Bucket

public Bucket(int bucketId,
              DRUMSParameterSet<Data> gp)
Constructor. Needs to know the id of the Bucket and the maximum size of the Bucket.

Parameters:
bucketId - the identification number of this bucket. Used in BucketContainer and other classes
gp - a pointer to the DRUMSParameterSet
Method Detail

getEmptyBucketWithSameProperties

public Bucket<Data> getEmptyBucketWithSameProperties()
                                                                         throws FileLockException,
                                                                                java.io.IOException
returns a new empty Bucket with the same properties of this bucket

Returns:
a new Bucket with the same bucketId
Throws:
java.io.IOException
FileLockException

getBucketId

public int getBucketId()
Returns:
the id of the bucket. The id is value between 0 and numberOfBuckets (see BucketContainer)

add

public boolean add(AbstractKVStorable toAdd)
Adds one AbstractKVStorable-object. This method have to be synchronized, because it is possible to access the backend in the same moment with the function getBackend().

Parameters:
toAdd - the Data to add
Returns:
true, if adding the element to the buffer was successful

contains

public boolean contains(Data element)
Parameters:
element - the element to look for
Returns:
true, if this bucket, contains the given element

getElementAt

public java.nio.ByteBuffer getElementAt(int index)
Parameters:
index - the index of the element in the bucket
Returns:
a ByteBuffer containing the requested element. The returned ByteBuffer is in read-only mode.

getBackend

public Data[] getBackend()
Returns the in backend stored AbstractKVStorables. First it rebuilds all objects from their byte-arrays and then sorts them.

Returns:
AbstractKVStorable[] all AbstractKVStorables ascending sorted

size

public int size()
Returns:
the number of elements, actually stored

freeMemory

public int freeMemory()
This method frees the allocated memory.

Returns:
the number of bytes which are available now

getCreationTime

public long getCreationTime()
Returns:
the creation time of this bucket.