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.

Author(s):
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(Character.class.new CharacterBinding());
         addPrimitive(Boolean.class.new BooleanBinding());
         addPrimitive(Byte.class.new ByteBinding());
         addPrimitive(Short.class.new ShortBinding());
         addPrimitive(Integer.class.new IntegerBinding());
         addPrimitive(Long.class.new LongBinding());
         addPrimitive(Float.class.new FloatBinding());
         addPrimitive(Double.class.new DoubleBinding());
     }
 
     private static void addPrimitive(Class cls1Class cls2,
                                      TupleBinding binding) {
         .put(cls1binding);
         .put(cls2binding);
     }

    
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);
         objectToEntry(objectoutput);
         outputToEntry(outputentry);
     }

    
Constructs a key or data object from a TupleInput entry.

Parameters:
input is the tuple key or data entry.
Returns:
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.

Parameters:
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.

Parameters:
cls is the primitive Java class.
Returns:
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