Class SequenceSet

java.lang.Object
org.apache.activemq.store.kahadb.disk.util.LinkedNodeList<Sequence>
org.apache.activemq.store.kahadb.disk.util.SequenceSet
All Implemented Interfaces:
Iterable<Long>

public class SequenceSet extends LinkedNodeList<Sequence> implements Iterable<Long>
Keeps track of a added long values. Collapses ranges of numbers using a Sequence representation. Use to keep track of received message ids to find out if a message is duplicate or if there are any missing messages.
Author:
chirino
  • Constructor Details

    • SequenceSet

      public SequenceSet()
  • Method Details

    • add

      public void add(Sequence value)
    • merge

      public void merge(SequenceSet sequenceSet)
    • remove

      public void remove(SequenceSet sequenceSet)
    • remove

      public void remove(Sequence value)
    • add

      public boolean add(long value)
      Parameters:
      value - the value to add to the list
      Returns:
      false if the value was a duplicate.
    • remove

      public boolean remove(long value)
      Removes the given value from the Sequence set, splitting a contained sequence if necessary.
      Parameters:
      value - The value that should be removed from the SequenceSet.
      Returns:
      true if the value was removed from the set, false if there was no sequence in the set that contained the given value.
    • removeFirst

      public long removeFirst()
      Removes and returns the first element from this list.
      Returns:
      the first element from this list.
      Throws:
      NoSuchElementException - if this list is empty.
    • removeLastSequence

      public Sequence removeLastSequence()
      Removes and returns the last sequence from this list.
      Returns:
      the last sequence from this list or null if the list is empty.
    • removeFirstSequence

      public Sequence removeFirstSequence(long count)
      Removes and returns the first sequence that is count range large.
      Returns:
      a sequence that is count range large, or null if no sequence is that large in the list.
    • getMissing

      public List<Sequence> getMissing(long first, long last)
      Returns:
      all the id Sequences that are missing from this set that are not in between the range provided.
    • getReceived

      public List<Sequence> getReceived()
      Returns:
      all the Sequence that are in this list
    • contains

      public boolean contains(long value)
      Returns true if the value given is contained within one of the sequences held in this set.
      Parameters:
      value - The value to search for in the set.
      Returns:
      true if the value is contained in the set.
    • contains

      public boolean contains(int first, int last)
    • get

      public Sequence get(int value)
    • rangeSize

      public long rangeSize()
      Computes the size of this Sequence by summing the values of all the contained sequences.
      Returns:
      the total number of values contained in this set if it were to be iterated over like an array.
    • iterator

      public Iterator<Long> iterator()
      Specified by:
      iterator in interface Iterable<Long>