org.helidb.lang.serializer
Class ConfigurableLengthIntegerNullSerializer

java.lang.Object
  extended by org.helidb.lang.serializer.ConfigurableLengthIntegerSerializer
      extended by org.helidb.lang.serializer.ConfigurableLengthIntegerNullSerializer
All Implemented Interfaces:
Serializer<Integer>

public class ConfigurableLengthIntegerNullSerializer
extends ConfigurableLengthIntegerSerializer

This Serializer serializes Integer values to a big-endian byte array of configurable size. The length of the byte array determines how big the serialized Integer:s can be. For a byte array length of n bytes, the maximum Integer value is 2^(n*8), except if n has its maximum value of 4, then the maximum value is Integer.MAX_VALUE. Negative values are only supported if n == 4.

This serializer uses a special, configurable value to represent null Integer:s.

Since:
1.0
Author:
Karl Gustafsson
See Also:
IntegerNullSerializer, ConfigurableLengthIntegerSerializer, ConfigurableLengthLongNullSerializer, Integer
In_jar:
helidb-core

Constructor Summary
ConfigurableLengthIntegerNullSerializer(int valueSize)
          Create a Serializer that uses the default value to represent null.
ConfigurableLengthIntegerNullSerializer(int valueSize, int nullValue)
          Create a Serializer with a custom value to represent null .
 
Method Summary
 Integer interpret(byte[] barr)
          Interpret the data in the byte array to an object of the type handled by the Serializer implementation.
 Integer interpret(byte[] barr, int offset, int length)
          Interpret the data in the byte array to an object of the type handled by the Serializer implementation.
 boolean isNullValuesPermitted()
          Does this serializer permit null values?
 byte[] serialize(Integer val)
          Serialize the supplied object into a new byte array.
 int serialize(Integer val, byte[] barr, int offset)
          Serialize the supplied object into the byte array.
 
Methods inherited from class org.helidb.lang.serializer.ConfigurableLengthIntegerSerializer
getSerializedSize, read, read, readInteger, readInteger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ConfigurableLengthIntegerNullSerializer

public ConfigurableLengthIntegerNullSerializer(int valueSize)
                                        throws IllegalArgumentException
Create a Serializer that uses the default value to represent null. The default value is the maximum allowed value for the specified value size (or Integer.MIN_VALUE if the value size is four bytes). The null value has the most significant bit of the most significant byte set, which may be important to know when working with Hasher:s.

Parameters:
valueSize - The number of bytes used to represent the value.
Throws:
IllegalArgumentException - If valueSize is not in the range 1 <= valueSize <= 8.

ConfigurableLengthIntegerNullSerializer

public ConfigurableLengthIntegerNullSerializer(int valueSize,
                                               int nullValue)
                                        throws IllegalArgumentException
Create a Serializer with a custom value to represent null .

Parameters:
valueSize - The number of bytes used to represent the value.
nullValue - The value used to represent null integers
Throws:
IllegalArgumentException - If nullValue is out of range and cannot be represented using valueSize bytes, or if valueSize is not in the range 1 <= valueSize <= 4.
Method Detail

isNullValuesPermitted

public boolean isNullValuesPermitted()
Description copied from interface: Serializer
Does this serializer permit null values?

Specified by:
isNullValuesPermitted in interface Serializer<Integer>
Overrides:
isNullValuesPermitted in class ConfigurableLengthIntegerSerializer
Returns:
true, always.

interpret

public Integer interpret(byte[] barr,
                         int offset,
                         int length)
Description copied from interface: Serializer
Interpret the data in the byte array to an object of the type handled by the Serializer implementation.

Specified by:
interpret in interface Serializer<Integer>
Overrides:
interpret in class ConfigurableLengthIntegerSerializer
Parameters:
barr - The byte array containing the data.
offset - The start position of the data.
length - The length of the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[])

interpret

public Integer interpret(byte[] barr)
Description copied from interface: Serializer
Interpret the data in the byte array to an object of the type handled by the Serializer implementation.

Specified by:
interpret in interface Serializer<Integer>
Overrides:
interpret in class ConfigurableLengthIntegerSerializer
Parameters:
barr - The byte array containing the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[], int, int)

serialize

public int serialize(Integer val,
                     byte[] barr,
                     int offset)
Description copied from interface: Serializer
Serialize the supplied object into the byte array.

Specified by:
serialize in interface Serializer<Integer>
Overrides:
serialize in class ConfigurableLengthIntegerSerializer
Parameters:
val - The object to serialize.
barr - The byte array to serialize it to.
offset - The start position to write data at in the byte array.
Returns:
The number of bytes written to the array.

serialize

public byte[] serialize(Integer val)
Description copied from interface: Serializer
Serialize the supplied object into a new byte array.

Specified by:
serialize in interface Serializer<Integer>
Overrides:
serialize in class ConfigurableLengthIntegerSerializer
Parameters:
val - The object to serialize.
Returns:
The object serialized into a byte array.