@ThreadSafe public final class SnowcastSequenceComparator extends Object implements Comparator<Long>
This Comparator
implementation can be used to compare and order two distinct
snowcast sequencer ids by their corresponding timestamps and counter values.
This is meant for legacy code or to integrate it with existing frameworks. In general use cases
SnowcastSequenceUtils.compareSequence(long, long)
or
SnowcastSequenceUtils.compareSequence(long, long, int)
should be preferred to prevent some unnecessary boxing/unboxing from long to Long
and back.
This comparator can be used just as any other Java Comparator
:
List<Long> elements = getSequencerIds(); Collections.sort( elements, new SnowcastSequenceComparator( 128 ) ); System.out.println( elements );
Alternatively an instance can be retrieved using a convenience method and a already existing
SnowcastSequencer
instance:
SnowcastSequencer sequencer = getSnowcastSequencer(); Comparator<Long> comparator = SnowcastSequenceUtils.snowcastSequenceComparator( sequencer );
Constructor and Description |
---|
SnowcastSequenceComparator(int maxLogicalNodeCount)
This constructor creates a new SnowcastSequenceComparator instance bound to the given
maximal logical node count.
There is also a convenience method in SnowcastSequenceUtils
to easy the creation process when a SnowcastSequencer is
available: |
Modifier and Type | Method and Description |
---|---|
int |
compare(Long sequenceId1,
Long sequenceId2) |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
public SnowcastSequenceComparator(@Min(value=128L) @Max(value=8192L) int maxLogicalNodeCount)
SnowcastSequenceUtils
to easy the creation process when a SnowcastSequencer
is
available:
SnowcastSequencer sequencer = getSnowcastSequencer(); Comparator<Long> comparator = SnowcastSequenceUtils.snowcastSequenceComparator( sequencer );
maxLogicalNodeCount
- the maximal logical node countCopyright © 2014-2017. All Rights Reserved.