// Path: orderly-core/src/main/java/orderly/DoubleRowKey.java
// public class DoubleRowKey extends DoubleWritableRowKey 
// {
//   private DoubleWritable dw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return Double.class; }
// 
//   protected Object toDoubleWritable(Object o) {
//     if (o == null || o instanceof DoubleWritable)
//       return o;
//     if (dw == null)
//       dw = new DoubleWritable();
//     dw.set((Double)o);
//     return dw;
//   }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     return super.getSerializedLength(toDoubleWritable(o));
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) throws IOException {
//     super.serialize(toDoubleWritable(o), w);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     DoubleWritable dw = (DoubleWritable) super.deserialize(w);
//     if (dw == null)
//       return dw;
// 
//     return Double.valueOf(dw.get());
//   }
// }
// 
// Path: orderly-core/src/main/java/orderly/DoubleWritableRowKey.java
// public class DoubleWritableRowKey extends RowKey 
// {
//   private static final long NULL = 0;
//   private DoubleWritable dw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return DoubleWritable.class; }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     if (o == null && !terminate())
//       return 0;
//     return Bytes.SIZEOF_LONG;
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) 
//     throws IOException
//   {
//     byte[] b = w.get();
//     int offset = w.getOffset();
//     long l;
// 
//     if (o == null) {
//       if (!terminate())
//         return;
//       l = NULL;
//     } else {
//       l = Double.doubleToLongBits(((DoubleWritable)o).get());
//       l = (l ^ ((l >> Long.SIZE - 1) | Long.MIN_VALUE)) + 1; 
//     }
//    
//     Bytes.putLong(b, offset, l ^ order.mask()); 
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public void skip(ImmutableBytesWritable w) throws IOException {
//     if (w.getLength() <= 0)
//       return;
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     byte[] s = w.get();
//     int offset = w.getOffset();
//     if (w.getLength() <= 0)
//       return null;
// 
//     try {
//       long l = Bytes.toLong(s, offset) ^ order.mask();
//       if (l == NULL)
//         return null;
// 
//       if (dw == null)
//         dw = new DoubleWritable();
// 
//       l--;
//       l ^= (~l >> Long.SIZE - 1) | Long.MIN_VALUE;
//       dw.set(Double.longBitsToDouble(l));
//       return dw;
//     } finally {
//       RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//     }
//   }
// }
// 
// Path: orderly-core/src/main/java/orderly/Order.java
// public enum Order
// { 
//   ASCENDING((byte)0), 
//   DESCENDING((byte)0xff);
// 
//   private final byte mask;
// 
//   Order(byte mask) { this.mask = mask; }
// 
//   /** Gets the byte mask associated with the sort order. When a 
//    * serialized byte is XOR'd with the mask, the result is the same byte 
//    * but sorted in the direction specified by the Order object. 
//    * @see RowKey#serialize
//    */
//   byte mask() { return mask; }
// 
// }


import orderly.DoubleRowKey;
import orderly.DoubleWritableRowKey;
import orderly.Order;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
/*  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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 orderly.example;




public class DoubleExample
{
  /* Simple examples showing serialization lengths with Double Row Key */
  public void lengthExamples() throws Exception {
    DoubleRowKey d = new DoubleRowKey();

    System.out.println("serialize(null) length - " + d.serialize(null).length);
    System.out.println("serialize(57.190235) length - " + 
        d.serialize(57.923924).length);
    System.out.println("serialize(1000000.999) length - " + 
        d.serialize(1000000.99).length);

// Path: orderly-core/src/main/java/orderly/DoubleRowKey.java
// public class DoubleRowKey extends DoubleWritableRowKey 
// {
//   private DoubleWritable dw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return Double.class; }
// 
//   protected Object toDoubleWritable(Object o) {
//     if (o == null || o instanceof DoubleWritable)
//       return o;
//     if (dw == null)
//       dw = new DoubleWritable();
//     dw.set((Double)o);
//     return dw;
//   }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     return super.getSerializedLength(toDoubleWritable(o));
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) throws IOException {
//     super.serialize(toDoubleWritable(o), w);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     DoubleWritable dw = (DoubleWritable) super.deserialize(w);
//     if (dw == null)
//       return dw;
// 
//     return Double.valueOf(dw.get());
//   }
// }
// 
// Path: orderly-core/src/main/java/orderly/DoubleWritableRowKey.java
// public class DoubleWritableRowKey extends RowKey 
// {
//   private static final long NULL = 0;
//   private DoubleWritable dw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return DoubleWritable.class; }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     if (o == null && !terminate())
//       return 0;
//     return Bytes.SIZEOF_LONG;
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) 
//     throws IOException
//   {
//     byte[] b = w.get();
//     int offset = w.getOffset();
//     long l;
// 
//     if (o == null) {
//       if (!terminate())
//         return;
//       l = NULL;
//     } else {
//       l = Double.doubleToLongBits(((DoubleWritable)o).get());
//       l = (l ^ ((l >> Long.SIZE - 1) | Long.MIN_VALUE)) + 1; 
//     }
//    
//     Bytes.putLong(b, offset, l ^ order.mask()); 
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public void skip(ImmutableBytesWritable w) throws IOException {
//     if (w.getLength() <= 0)
//       return;
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     byte[] s = w.get();
//     int offset = w.getOffset();
//     if (w.getLength() <= 0)
//       return null;
// 
//     try {
//       long l = Bytes.toLong(s, offset) ^ order.mask();
//       if (l == NULL)
//         return null;
// 
//       if (dw == null)
//         dw = new DoubleWritable();
// 
//       l--;
//       l ^= (~l >> Long.SIZE - 1) | Long.MIN_VALUE;
//       dw.set(Double.longBitsToDouble(l));
//       return dw;
//     } finally {
//       RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//     }
//   }
// }
// 
// Path: orderly-core/src/main/java/orderly/Order.java
// public enum Order
// { 
//   ASCENDING((byte)0), 
//   DESCENDING((byte)0xff);
// 
//   private final byte mask;
// 
//   Order(byte mask) { this.mask = mask; }
// 
//   /** Gets the byte mask associated with the sort order. When a 
//    * serialized byte is XOR'd with the mask, the result is the same byte 
//    * but sorted in the direction specified by the Order object. 
//    * @see RowKey#serialize
//    */
//   byte mask() { return mask; }
// 
// }


// Path: orderly-examples/src/main/java/orderly/example/DoubleExample.java
import orderly.DoubleRowKey;
import orderly.DoubleWritableRowKey;
import orderly.Order;
import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.hbase.io.ImmutableBytesWritable;

/*  Licensed to the Apache Software Foundation (ASF) under one
 *  or more contributor license agreements.  See the NOTICE file
 *  distributed with this work for additional information
 *  regarding copyright ownership.  The ASF licenses this file
 *  to you 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 orderly.example;




public class DoubleExample
{
  /* Simple examples showing serialization lengths with Double Row Key */
  public void lengthExamples() throws Exception {
    DoubleRowKey d = new DoubleRowKey();

    System.out.println("serialize(null) length - " + d.serialize(null).length);
    System.out.println("serialize(57.190235) length - " + 
        d.serialize(57.923924).length);
    System.out.println("serialize(1000000.999) length - " + 
        d.serialize(1000000.99).length);

    d.setOrder(Order.DESCENDING);