public class PairLexicoder<A extends Comparable<A>,B extends Comparable<B>>
extends org.apache.accumulo.core.client.lexicoder.impl.AbstractLexicoder<org.apache.accumulo.core.util.ComparablePair<A,B>>
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.Constructor and Description |
---|
PairLexicoder(Lexicoder<A> firstLexicoder,
Lexicoder<B> secondLexicoder) |
Modifier and Type | Method and 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) |
decode
public org.apache.accumulo.core.util.ComparablePair<A,B> decode(byte[] b)
decode
in interface org.apache.accumulo.core.iterators.TypedValueCombiner.Encoder<org.apache.accumulo.core.util.ComparablePair<A extends Comparable<A>,B extends Comparable<B>>>
decode
in class AbstractEncoder<org.apache.accumulo.core.util.ComparablePair<A extends Comparable<A>,B extends Comparable<B>>>
protected org.apache.accumulo.core.util.ComparablePair<A,B> decodeUnchecked(byte[] data, int offset, int len)
AbstractEncoder
decodeUnchecked
in class AbstractEncoder<org.apache.accumulo.core.util.ComparablePair<A extends Comparable<A>,B extends Comparable<B>>>
Copyright © 2011–2019 The Apache Software Foundation. All rights reserved.