org.helidb.lang.serializer
Class IntegerNullSerializer

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

public class IntegerNullSerializer
extends IntegerSerializer

A Serializer for Integer values that may be null. Integer values are serialized to a four bytes long, big-endian byte array. A special, configurable value is used to represent null.

The singleton instance INSTANCE uses Integer.MIN_VALUE to represent null values. It may be used instead of instantiating this class.

Author:
Karl Gustafsson
See Also:
IntegerSerializer, ConfigurableLengthIntegerNullSerializer, Integer
In_jar:
helidb-core

Field Summary
static IntegerNullSerializer INSTANCE
          The singleton instance.
 
Fields inherited from class org.helidb.lang.serializer.IntegerSerializer
DATA_SIZE
 
Constructor Summary
IntegerNullSerializer(int nullValue)
          Instantiate this class.
 
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 value)
          Serialize the supplied object into a new byte array.
 int serialize(Integer value, byte[] barr, int offset)
          Serialize the supplied object into the byte array.
 
Methods inherited from class org.helidb.lang.serializer.IntegerSerializer
encodeInteger, getInteger, getSerializedSize, read, read, readInteger, readInteger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

INSTANCE

public static final IntegerNullSerializer INSTANCE
The singleton instance. May be used instead of instantiating this class. It uses Integer.MIN_VALUE to represent null values. That null value has the most significant bit of the most significant byte set, which may be important to know when working with Hasher:s.

Constructor Detail

IntegerNullSerializer

public IntegerNullSerializer(int nullValue)
Instantiate this class.

Parameters:
nullValue - The value used to represent null Integer :s.
Method Detail

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 IntegerSerializer
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 IntegerSerializer
Parameters:
barr - The byte array containing the data.
Returns:
The interpreted object.
See Also:
Serializer.interpret(byte[], int, int)

serialize

public int serialize(Integer value,
                     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 IntegerSerializer
Parameters:
value - 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 value)
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 IntegerSerializer
Parameters:
value - The object to serialize.
Returns:
The object serialized into a byte array.

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 IntegerSerializer
Returns:
true, always.