com.unister.semweb.drums.storable
Class AbstractKVStorable

java.lang.Object
  extended by com.unister.semweb.drums.storable.AbstractKVStorable
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
GeneralStorable

public abstract class AbstractKVStorable
extends java.lang.Object
implements java.io.Serializable, java.lang.Cloneable

Abstract implementation of interface AbstractKVStorable. Extend this class to build your own storable objects.

Author:
Martin Nettling
See Also:
Serialized Form

Constructor Summary
AbstractKVStorable()
           
 
Method Summary
abstract  AbstractKVStorable clone()
           
 boolean equals(java.lang.Object obj)
           
abstract
<Data extends AbstractKVStorable>
Data
fromByteBuffer(java.nio.ByteBuffer bb)
          Generates a new Object from the given ByteBuffer.
 byte[] getKey()
           
 int getSize()
          Returns the number of bytes needed to store key and value.
 byte[] getValue()
           
abstract  void initFromByteBuffer(java.nio.ByteBuffer bb)
          Initializes the object from the given ByteBuffer
 boolean isMarkedAsDeleted()
          This method returns false by default.
abstract
<Data extends AbstractKVStorable>
Data
merge(Data element)
          Merges the given AbstractKVStorable with this one by your implementation.
static
<Data extends AbstractKVStorable>
Data[]
merge(Data[] toAdd)
          This method merges all AbstractKVStorables in the given array with same keys.
 void setKey(byte[] key)
          Sets the key of this object.
 void setValue(byte[] value)
          Sets the value of this object.
abstract  java.nio.ByteBuffer toByteBuffer()
          Converts the object to a ByteBuffer
abstract
<Data extends AbstractKVStorable>
void
update(Data element)
          Updates the given AbstractKVStorable with values from this one.
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractKVStorable

public AbstractKVStorable()
Method Detail

setValue

public void setValue(byte[] value)
Sets the value of this object. The given array is not copied, only a pointer will be set

Parameters:
value -

getValue

public byte[] getValue()
Returns:
a pointer to the underlying array, which contains all value-parts

setKey

public void setKey(byte[] key)
Sets the key of this object. Be careful by overwriting the old key. The given array is not copied, only a pointer will be set.

Parameters:
key -

getKey

public byte[] getKey()
Returns:
a pointer to the underlying array, which contains all key-parts

clone

public abstract AbstractKVStorable clone()
Overrides:
clone in class java.lang.Object

getSize

public int getSize()
Returns the number of bytes needed to store key and value.

Returns:
key.length + value.length

toByteBuffer

public abstract java.nio.ByteBuffer toByteBuffer()
Converts the object to a ByteBuffer

Returns:
the object as ByteBuffer

initFromByteBuffer

public abstract void initFromByteBuffer(java.nio.ByteBuffer bb)
Initializes the object from the given ByteBuffer

Parameters:
bb -

fromByteBuffer

public abstract <Data extends AbstractKVStorable> Data fromByteBuffer(java.nio.ByteBuffer bb)
Generates a new Object from the given ByteBuffer.

Parameters:
bb -
Returns:
a new instances of this Class

merge

public abstract <Data extends AbstractKVStorable> Data merge(Data element)
Merges the given AbstractKVStorable with this one by your implementation.

Parameters:
element -
Returns:
a pointer to an AbstractKVStorable.

update

public abstract <Data extends AbstractKVStorable> void update(Data element)
Updates the given AbstractKVStorable with values from this one.

Parameters:
element -

isMarkedAsDeleted

public boolean isMarkedAsDeleted()
This method returns false by default. This method must be overwritten in the concrete class,

Returns:
true, if this element is marked as deleted

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

merge

public static <Data extends AbstractKVStorable> Data[] merge(Data[] toAdd)
This method merges all AbstractKVStorables in the given array with same keys. The array must been sorted.

Parameters:
toAdd - this array might contain duplicate entries concerning the key, which must be merged.
Returns:
a new array containing unique AbstractKVStorables. The array is sorted.