// Path: orderly-core/src/main/java/orderly/FixedLongWritableRowKey.java
// public class FixedLongWritableRowKey extends RowKey 
// {
//   private LongWritable lw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return LongWritable.class; }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     return Bytes.SIZEOF_LONG;
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) 
//     throws IOException
//   {
//     byte[] b = w.get();
//     int offset = w.getOffset();
// 
//     long l = ((LongWritable)o).get();
//     Bytes.putLong(b, offset, l ^ Long.MIN_VALUE ^ order.mask());
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public void skip(ImmutableBytesWritable w) throws IOException {
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     int offset = w.getOffset();
//     byte[] s = w.get();
// 
//     long l = Bytes.toLong(s, offset) ^ Long.MIN_VALUE ^ order.mask();
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
// 
//     if (lw == null)
//       lw = new LongWritable();
//     lw.set(l);
//     return lw;
//   }
// }
// 
// Path: orderly-core/src/main/java/orderly/FixedUnsignedLongRowKey.java
// public class FixedUnsignedLongRowKey extends FixedUnsignedLongWritableRowKey 
// {
//   private LongWritable lw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return Long.class; }
// 
//   protected Object toLongWritable(Object o) {
//     if (o == null || o instanceof LongWritable)
//       return o;
//     if (lw == null)
//       lw = new LongWritable();
//     lw.set((Long)o);
//     return lw;
//   }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     return super.getSerializedLength(toLongWritable(o));
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) throws IOException {
//     super.serialize(toLongWritable(o), w);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     LongWritable lw = (LongWritable) super.deserialize(w);
//     if (lw == null)
//       return lw;
// 
//     return Long.valueOf(lw.get());
//   }
// }
// 
// 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.FixedLongWritableRowKey;
import orderly.FixedUnsignedLongRowKey;
import orderly.Order;
import org.apache.hadoop.io.LongWritable;
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 FixedLongExample
{
  /* Simple examples showing serialization lengths with 
   * FixedUnsignedLongRow Key 
   */
  public void lengthExamples() throws Exception {
    FixedUnsignedLongRowKey i = new FixedUnsignedLongRowKey();

    System.out.println("serialize(2^63) length - " + 
        i.serialize(Long.MIN_VALUE).length);
    System.out.println("serialize(57) length - " + i.serialize(57l).length);
    System.out.println("serialize(293) length - " + i.serialize(293l).length);

    i.setOrder(Order.DESCENDING);
    System.out.println("descending serialize (57) - length " + 
        i.serialize(57l).length);
    System.out.println("descending serialize (2^32) - length " + 
        i.serialize(1l << 32).length);
  }

  /* Simple examples showing serialization tests with FixedLongWritable */
  public void serializationExamples() throws Exception {
    FixedLongWritableRowKey l = new FixedLongWritableRowKey(); 
    LongWritable w = new LongWritable();
    ImmutableBytesWritable buffer = new ImmutableBytesWritable();
    byte[] b;

    /* Serialize and deserialize into an immutablebyteswritable */
    w.set(-93214);
    b = new byte[l.getSerializedLength(w)];
    buffer.set(b);
    l.serialize(w, buffer);
    buffer.set(b, 0, b.length);
    System.out.println("deserialize(serialize(-93214)) = " + 
        ((LongWritable)l.deserialize(buffer)).get());

    /* Serialize and deserialize into a byte array (descending sort).  */
// Path: orderly-core/src/main/java/orderly/FixedLongWritableRowKey.java
// public class FixedLongWritableRowKey extends RowKey 
// {
//   private LongWritable lw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return LongWritable.class; }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     return Bytes.SIZEOF_LONG;
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) 
//     throws IOException
//   {
//     byte[] b = w.get();
//     int offset = w.getOffset();
// 
//     long l = ((LongWritable)o).get();
//     Bytes.putLong(b, offset, l ^ Long.MIN_VALUE ^ order.mask());
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public void skip(ImmutableBytesWritable w) throws IOException {
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     int offset = w.getOffset();
//     byte[] s = w.get();
// 
//     long l = Bytes.toLong(s, offset) ^ Long.MIN_VALUE ^ order.mask();
//     RowKeyUtils.seek(w, Bytes.SIZEOF_LONG);
// 
//     if (lw == null)
//       lw = new LongWritable();
//     lw.set(l);
//     return lw;
//   }
// }
// 
// Path: orderly-core/src/main/java/orderly/FixedUnsignedLongRowKey.java
// public class FixedUnsignedLongRowKey extends FixedUnsignedLongWritableRowKey 
// {
//   private LongWritable lw;
// 
//   @Override
//   public Class<?> getSerializedClass() { return Long.class; }
// 
//   protected Object toLongWritable(Object o) {
//     if (o == null || o instanceof LongWritable)
//       return o;
//     if (lw == null)
//       lw = new LongWritable();
//     lw.set((Long)o);
//     return lw;
//   }
// 
//   @Override
//   public int getSerializedLength(Object o) throws IOException {
//     return super.getSerializedLength(toLongWritable(o));
//   }
// 
//   @Override
//   public void serialize(Object o, ImmutableBytesWritable w) throws IOException {
//     super.serialize(toLongWritable(o), w);
//   }
// 
//   @Override
//   public Object deserialize(ImmutableBytesWritable w) throws IOException {
//     LongWritable lw = (LongWritable) super.deserialize(w);
//     if (lw == null)
//       return lw;
// 
//     return Long.valueOf(lw.get());
//   }
// }
// 
// 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/FixedLongExample.java
import orderly.FixedLongWritableRowKey;
import orderly.FixedUnsignedLongRowKey;
import orderly.Order;
import org.apache.hadoop.io.LongWritable;
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 FixedLongExample
{
  /* Simple examples showing serialization lengths with 
   * FixedUnsignedLongRow Key 
   */
  public void lengthExamples() throws Exception {
    FixedUnsignedLongRowKey i = new FixedUnsignedLongRowKey();

    System.out.println("serialize(2^63) length - " + 
        i.serialize(Long.MIN_VALUE).length);
    System.out.println("serialize(57) length - " + i.serialize(57l).length);
    System.out.println("serialize(293) length - " + i.serialize(293l).length);

    i.setOrder(Order.DESCENDING);
    System.out.println("descending serialize (57) - length " + 
        i.serialize(57l).length);
    System.out.println("descending serialize (2^32) - length " + 
        i.serialize(1l << 32).length);
  }

  /* Simple examples showing serialization tests with FixedLongWritable */
  public void serializationExamples() throws Exception {
    FixedLongWritableRowKey l = new FixedLongWritableRowKey(); 
    LongWritable w = new LongWritable();
    ImmutableBytesWritable buffer = new ImmutableBytesWritable();
    byte[] b;

    /* Serialize and deserialize into an immutablebyteswritable */
    w.set(-93214);
    b = new byte[l.getSerializedLength(w)];
    buffer.set(b);
    l.serialize(w, buffer);
    buffer.set(b, 0, b.length);
    System.out.println("deserialize(serialize(-93214)) = " + 
        ((LongWritable)l.deserialize(buffer)).get());

    /* Serialize and deserialize into a byte array (descending sort).  */
    l.setOrder(Order.DESCENDING);