org.apache.activemq.store.kahadb.disk.util
Class SequenceSet

java.lang.Object
  extended by org.apache.activemq.store.kahadb.disk.util.LinkedNodeList<Sequence>
      extended by 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

Nested Class Summary
static class SequenceSet.Marshaller
           
 
Constructor Summary
SequenceSet()
           
 
Method Summary
 boolean add(long value)
           
 void add(Sequence value)
           
 boolean contains(int first, int last)
           
 boolean contains(long value)
          Returns true if the value given is contained within one of the sequences held in this set.
 List<Sequence> getMissing(long first, long last)
           
 List<Sequence> getReceived()
           
 Iterator<Long> iterator()
           
 long rangeSize()
          Computes the size of this Sequence by summing the values of all the contained sequences.
 boolean remove(long value)
          Removes the given value from the Sequence set, splitting a contained sequence if necessary.
 long removeFirst()
          Removes and returns the first element from this list.
 Sequence removeFirstSequence(long count)
          Removes and returns the first sequence that is count range large.
 Sequence removeLastSequence()
          Removes and returns the last sequence from this list.
 
Methods inherited from class org.apache.activemq.store.kahadb.disk.util.LinkedNodeList
addFirst, addFirst, addLast, addLast, clear, getHead, getTail, isEmpty, reparent, rotate, rotateTo, size, toArrayList, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SequenceSet

public SequenceSet()
Method Detail

add

public void add(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)

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>


Copyright © 2005-2013 The Apache Software Foundation. All Rights Reserved.