Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * See the file LICENSE for redistribution information.
   * Copyright (c) 2000, 2010 Oracle and/or its affiliates.  All rights reserved.
  package com.sleepycat.bind.tuple;
 import java.util.Map;
An abstract EntryBinding that treats a key or data entry as a tuple; it includes predefined bindings for Java primitive types.

This class takes care of converting the entries to/from TupleInput and TupleOutput objects. Its two abstract methods must be implemented by a concrete subclass to convert between tuples and key or data objects.

Mark Hayes
See also:
Tuple Formats
 public abstract class TupleBinding<E>
     extends TupleBase<E>
     implements EntryBinding<E> {
     private static final Map<Class,TupleBindingprimitives =
         new HashMap<Class,TupleBinding>();
     static {
         addPrimitive(String.classString.classnew StringBinding());
         addPrimitive( CharacterBinding());
         addPrimitive( BooleanBinding());
         addPrimitive( ByteBinding());
         addPrimitive( ShortBinding());
         addPrimitive( IntegerBinding());
         addPrimitive( LongBinding());
         addPrimitive( FloatBinding());
         addPrimitive( DoubleBinding());
     private static void addPrimitive(Class cls1Class cls2,
                                      TupleBinding binding) {

Creates a tuple binding.
     public TupleBinding() {
     // javadoc is inherited
     public E entryToObject(DatabaseEntry entry) {
         return entryToObject(entryToInput(entry));
     // javadoc is inherited
     public void objectToEntry(E objectDatabaseEntry entry) {
         TupleOutput output = getTupleOutput(object);

Constructs a key or data object from a TupleInput entry.

input is the tuple key or data entry.
the key or data object constructed from the entry.
     public abstract E entryToObject(TupleInput input);

Converts a key or data object to a tuple entry.

object is the key or data object.
output is the tuple entry to which the key or data should be written.
     public abstract void objectToEntry(E objectTupleOutput output);

Creates a tuple binding for a primitive Java class. The following Java classes are supported.
  • String
  • Character
  • Boolean
  • Byte
  • Short
  • Integer
  • Long
  • Float
  • Double

Note: getPrimitiveBinding(java.lang.Class) returns bindings that do not sort negative floating point numbers correctly by default. See SortedFloatBinding and SortedDoubleBinding for details.

cls is the primitive Java class.
a new binding for the primitive class or null if the cls parameter is not one of the supported classes.
    public static <T> TupleBinding<T> getPrimitiveBinding(Class<T> cls) {
        return .get(cls);
New to GrepCode? Check out our FAQ X