Class PairLexicoder<A extends Comparable<A>,B extends Comparable<B>>

java.lang.Object
org.apache.accumulo.core.client.lexicoder.AbstractEncoder<T>
org.apache.accumulo.core.client.lexicoder.AbstractLexicoder<org.apache.accumulo.core.util.ComparablePair<A,B>>
org.apache.accumulo.core.client.lexicoder.PairLexicoder<A,B>
All Implemented Interfaces:
Encoder<org.apache.accumulo.core.util.ComparablePair<A,B>>, Lexicoder<org.apache.accumulo.core.util.ComparablePair<A,B>>

public class PairLexicoder<A extends Comparable<A>,B extends Comparable<B>> extends AbstractLexicoder<org.apache.accumulo.core.util.ComparablePair<A,B>>
This class is a lexicoder that sorts a ComparablePair. Each item in the pair is encoded with the given lexicoder and concatenated together. This makes it easy to construct a sortable key based on two components. There are many examples of this- but a key/value relationship is a great one. If we decided we wanted a two-component key where the first component is a string and the second component a date which is reverse sorted, we can do so with the following example:
 
 StringLexicoder strEncoder = new StringLexicoder();
 ReverseLexicoder<Date> dateEnc = new ReverseLexicoder<>(new DateLexicoder());
 PairLexicoder<String,Date> pair = new PairLexicoder<>(strEncoder, dateEnc);
 long now = System.currentTimeMillis();
 byte[] pair1 = pair.encode(new ComparablePair<>("com", new Date(now)));
 byte[] pair2 = pair.encode(new ComparablePair<>("com", new Date(now + 500)));
 byte[] pair3 = pair.encode(new ComparablePair<>("org", new Date(now + 1000)));
 
 
In the example, pair2 will be sorted before pair1. pair3 will occur last since 'org' is sorted after 'com'. If we just used a DateLexicoder instead of a ReverseLexicoder, pair1 would have been sorted before pair2.
Since:
1.6.0
  • Constructor Summary

    Constructors
    Constructor
    Description
    PairLexicoder(Lexicoder<A> firstLexicoder, Lexicoder<B> secondLexicoder)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    org.apache.accumulo.core.util.ComparablePair<A,B>
    decode(byte[] b)
     
    protected org.apache.accumulo.core.util.ComparablePair<A,B>
    decodeUnchecked(byte[] data, int offset, int len)
    Decodes a byte array without checking if the offset and len exceed the bounds of the actual array.
    byte[]
    encode(org.apache.accumulo.core.util.ComparablePair<A,B> data)
     

    Methods inherited from class org.apache.accumulo.core.client.lexicoder.AbstractEncoder

    decode

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • encode

      public byte[] encode(org.apache.accumulo.core.util.ComparablePair<A,B> data)
    • decode

      public org.apache.accumulo.core.util.ComparablePair<A,B> decode(byte[] b)
      Specified by:
      decode in interface Encoder<A extends Comparable<A>>
      Overrides:
      decode in class AbstractEncoder<org.apache.accumulo.core.util.ComparablePair<A extends Comparable<A>,B extends Comparable<B>>>
    • decodeUnchecked

      protected org.apache.accumulo.core.util.ComparablePair<A,B> decodeUnchecked(byte[] data, int offset, int len)
      Description copied from class: AbstractEncoder
      Decodes a byte array without checking if the offset and len exceed the bounds of the actual array.
      Specified by:
      decodeUnchecked in class AbstractEncoder<org.apache.accumulo.core.util.ComparablePair<A extends Comparable<A>,B extends Comparable<B>>>