org.mapdb.Serializer Maven / Gradle / Ivy
Show all versions of mapdb Show documentation
/*
* Copyright (c) 2012 Jan Kotek
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.mapdb;
import org.jetbrains.annotations.NotNull;
import org.mapdb.serializer.*;
import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
/**
* This interface specifies how Java Objects are serialized and de-serialized
* and also how objects are compared, hashed and tested for equality for use
* with MapDB.
*
* Implementing classes do not have to be thread safe.
*
* @param the type of object that the Serializer handles.
*
* @author Jan Kotek
*/
public interface Serializer*/> extends Comparator {
/**
* A predefined {@link Serializer} that handles non-null
* {@link Character Characters}.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*/
GroupSerializer CHAR = new SerializerChar();
/**
* A predefined {@link Serializer} that handles non-null
* {@link String Strings} whereby Strings are serialized to a UTF-8 encoded
* format. The Serializer also stores the String's size, allowing it to be
* used as a GroupSerializer in BTreeMaps.
*
* This Serializer hashes Strings using the original hash code method as
* opposed to the {@link Serializer#STRING} Serializer.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* @see Serializer#STRING
*/
GroupSerializer STRING_ORIGHASH = new SerializerStringOrigHash();
/**
* A predefined {@link Serializer} that handles non-null
* {@link String Strings} whereby Strings are serialized to a UTF-8 encoded
* format. The Serializer also stores the String's size, allowing it to be
* used as a GroupSerializer in BTreeMaps.
*
* This Serializer hashes Strings using a specially tailored hash code
* method as opposed to the {@link Serializer#STRING_ORIGHASH} Serializer.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* @see Serializer#STRING_ORIGHASH
*/
GroupSerializer STRING = new SerializerString();
/**
* A predefined {@link Serializer} that handles non-null
* {@link String Strings} whereby Strings are serialized to a UTF-8 encoded
* format. The Serializer also stores the String's size, allowing it to be
* used as a GroupSerializer in BTreeMaps. Neighboring strings may be delta
* encoded for increased storage efficency.
*
* This Serializer hashes Strings using a specially tailored hash code
* method as opposed to the {@link Serializer#STRING_ORIGHASH} Serializer.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* @see Serializer#STRING
*/
GroupSerializer STRING_DELTA = new SerializerStringDelta();
/**
* A predefined {@link Serializer} that handles non-null
* {@link String Strings} whereby Strings are serialized to a UTF-8 encoded
* format. The Serializer also stores the String's size, allowing it to be
* used as a GroupSerializer in BTreeMaps. Neighboring strings may be delta
* encoded for increased storage efficency.
*
* This Serializer hashes Strings using a specially tailored hash code
* method as opposed to the {@link Serializer#STRING_ORIGHASH} Serializer.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* @see Serializer#STRING
*/
GroupSerializer STRING_DELTA2 = new SerializerStringDelta2();
/**
* A predefined {@link Serializer} that handles non-null
* {@link String Strings} whereby Strings are serialized to a UTF-8 encoded
* format. The Serializer also stores the String's size, allowing it to be
* used as a GroupSerializer in BTreeMaps. Neighboring strings may be delta
* encoded for increased storage efficency.
*
* Deserialized strings are automatically interned {@link String#intern()}
* allowing a more heap space efficient storage for repeated strings.
*
* This Serializer hashes Strings using a specially tailored hash code
* method as opposed to the {@link Serializer#STRING_ORIGHASH} Serializer.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* @see Serializer#STRING
*/
GroupSerializer STRING_INTERN = new SerializerStringIntern();
/**
* A predefined {@link Serializer} that handles non-null
* {@link String Strings} whereby Strings are serialized to a ASCII encoded
* format (8 bit character) which is faster than using a UTF-8 format. The
* Serializer also stores the String's size, allowing it to be used as a
* GroupSerializer in BTreeMaps.
*
* This Serializer hashes Strings using a specially tailored hash code
* method as opposed to the {@link Serializer#STRING_ORIGHASH} Serializer.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* @see Serializer#STRING_ORIGHASH
*/
GroupSerializer STRING_ASCII = new SerializerStringAscii();
/**
* A predefined {@link Serializer} that handles non-null
* {@link String Strings} whereby Strings are serialized to a UTF-8 encoded
* format. The Serializer does not store the String's size, thereby
* preventing it from being used as a GroupSerializer.
*
* This Serializer hashes Strings using the original hash code method as
* opposed to the {@link Serializer#STRING} Serializer.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* @see Serializer#STRING_ORIGHASH
*/
Serializer STRING_NOSIZE = new SerializerStringNoSize();
/**
* A predefined {@link Serializer} that handles non-null {@link Long Longs}
* whereby Longs are serialized to an 8 byte format. The Serializer also
* stores the Longs's size, allowing it to be used as a GroupSerializer in
* BTreeMaps.
*
* This Serializer hashes Longs using the original {@link Long#hashCode()}
* method.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer LONG = new SerializerLong();
/**
* A predefined {@link Serializer} that handles non-null {@link Long Longs}
* whereby Longs are serialized to a compressed byte format. The Serializer
* also stores the Longs's size, allowing it to be used as a GroupSerializer
* in BTreeMaps.
*
* Smaller positive values occupy less than 8 bytes. Large and negative
* values could occupy 8 or 9 bytes.
*
* This Serializer hashes Longs using the original {@link Long#hashCode()}
* method.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer LONG_PACKED = new SerializerLongPacked();
/**
* A predefined {@link Serializer} that handles non-null {@link Long Longs}
* whereby Longs are serialized to a compressed byte format and neighboring
* Longs are delta encoded in BTreeMaps. Neighbors with a small delta can be
* encoded using a single byte.
*
* Smaller positive values occupy less than 8 bytes. Large and negative
* values could occupy 8 or 9 bytes.
*
* This Serializer hashes Longs using the original {@link Long#hashCode()}
* method.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer LONG_DELTA = new SerializerLongDelta();
/**
* A predefined {@link Serializer} that handles non-null
* {@link Integer Integers} whereby Integers are serialized to a 4 byte
* format.
*
* This Serializer hashes Integers using the original
* {@link Integer#hashCode()} method.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer INTEGER = new SerializerInteger();
/**
* A predefined {@link Serializer} that handles non-null
* {@link Integer Integers} whereby Integers are serialized to a compressed
* byte format.The Serializer also stores the Longs's size, allowing it to
* be used as a GroupSerializer in BTreeMaps.
*
* Smaller positive values occupy less than 4 bytes. Large and negative
* values could occupy 4 or 5 bytes.
*
* This Serializer hashes Integers using the original
* {@link Integer#hashCode()} method.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer INTEGER_PACKED = new SerializerIntegerPacked();
/**
* A predefined {@link Serializer} that handles non-null
* {@link Integer Integers} whereby Integers are serialized to a compressed
* byte format and neighboring Integers are delta encoded in BTreeMaps.
* Neighbors with a small delta can be encoded using a single byte.
*
* Smaller positive values occupy less than 4 bytes. Large and negative
* values could occupy 4 or 5 bytes.
*
* This Serializer hashes Integers using the original
* {@link Integer#hashCode()} method.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer INTEGER_DELTA = new SerializerIntegerDelta();
/**
* A predefined {@link Serializer} that handles non-null
* {@link Boolean Booleans} whereby Booleans are serialized to a one byte
* format.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer BOOLEAN = new SerializerBoolean();
/**
* A predefined {@link Serializer} that handles non-null {@link Long Longs}
* used as a recid whereby recids are serialized to an eight byte format
* including a checksum.
*
* If a {@code null} value is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
*/
GroupSerializer RECID = new SerializerRecid();
/**
* A predefined {@link Serializer} that handles non-null arrays of longs
* used as a recids whereby recids are serialized to an eight byte format
* including a checksum.
*
* If a {@code null} array is passed to the Serializer, a
* {@link NullPointerException} will be thrown.
*
* If an array that contains a {@code null} value is passed to the
* Serializer, a {@link NullPointerException} will be thrown.
*
*/
GroupSerializer RECID_ARRAY = new SerializerRecidArray();
/**
* A predefined {@link Serializer} that always throws an
* {@link IllegalAccessError} when invoked.
*
* This serializer can be used for testing and assertions.
*/
GroupSerializer