1 /*- 2 * See the file LICENSE for redistribution information. 3 * 4 * Copyright (c) 2000, 2010 Oracle and/or its affiliates. All rights reserved. 5 * 6 */ 7 8 package com.sleepycat.bind.tuple; 9 10 import com.sleepycat.je.DatabaseEntry; 11 12 /** 13 * A concrete <code>TupleBinding</code> for a sorted <code>Float</code> 14 * primitive wrapper or sorted a <code>float</code> primitive. 15 * 16 * <p>There are two ways to use this class:</p> 17 * <ol> 18 * <li>When using the {@link com.sleepycat.je} package directly, the static 19 * methods in this class can be used to convert between primitive values and 20 * {@link DatabaseEntry} objects.</li> 21 * <li>When using the {@link com.sleepycat.collections} package, an instance of 22 * this class can be used with any stored collection.</li> 23 * </ol> 24 * 25 * @see <a href="package-summary.html#floatFormats">Floating Point Formats</a> 26 */ 27 public class SortedFloatBinding extends TupleBinding<Float> { 28 29 /* javadoc is inherited */ entryToObject(TupleInput input)30 public Float entryToObject(TupleInput input) { 31 32 return input.readSortedFloat(); 33 } 34 35 /* javadoc is inherited */ objectToEntry(Float object, TupleOutput output)36 public void objectToEntry(Float object, TupleOutput output) { 37 38 output.writeSortedFloat(object); 39 } 40 41 /* javadoc is inherited */ getTupleOutput(Float object)42 protected TupleOutput getTupleOutput(Float object) { 43 44 return FloatBinding.sizedOutput(); 45 } 46 47 /** 48 * Converts an entry buffer into a simple <code>float</code> value. 49 * 50 * @param entry is the source entry buffer. 51 * 52 * @return the resulting value. 53 */ entryToFloat(DatabaseEntry entry)54 public static float entryToFloat(DatabaseEntry entry) { 55 56 return entryToInput(entry).readSortedFloat(); 57 } 58 59 /** 60 * Converts a simple <code>float</code> value into an entry buffer. 61 * 62 * @param val is the source value. 63 * 64 * @param entry is the destination entry buffer. 65 */ floatToEntry(float val, DatabaseEntry entry)66 public static void floatToEntry(float val, DatabaseEntry entry) { 67 68 outputToEntry(FloatBinding.sizedOutput().writeSortedFloat(val), entry); 69 } 70 } 71