Get all outstanding Notifications which have a sequence number
that is equal to or greater than the specified one. The sequence
number in this case is the overarching one maintained by this buffer,
and has nothing to do with the sequence number within any particular
Notification.
A sequence number of 0 means all Notifications.
The array returned contains the following:
result[ 0 ] is the next sequence number (for the next call)
result[ 1 ] a Notification[] of the available Notifications
if ( sequenceNumberIn < 0 )
{
throw new IllegalArgumentException( "" + sequenceNumberIn );
}
final Map<String,Object> result = new HashMap<String,Object>();
result.put( NEXT_SEQUENCE_NUMBER_KEY, LONG_ZERO );
result.put( NOTIFICATIONS_KEY, EMPTY_NOTIFS );
synchronized( mNotifications )
{
final int numNotifsAvailable = mNotifications.size();
final long nextAvailSequenceNumber = getNextSequenceNumber();
result.put(NEXT_SEQUENCE_NUMBER_KEY,
Long.valueOf(nextAvailSequenceNumber));
if ( numNotifsAvailable != 0 )
{
final long lastAvailSequenceNumber = nextAvailSequenceNumber - 1;
final long firstAvailSequenceNumber = 1 + (lastAvailSequenceNumber - numNotifsAvailable);
assert( firstAvailSequenceNumber >= 1 );
final long requestedSequenceNumber = sequenceNumberIn == 0 ?
firstAvailSequenceNumber : sequenceNumberIn;
if ( requestedSequenceNumber >= firstAvailSequenceNumber &&
requestedSequenceNumber <= lastAvailSequenceNumber)
{
final int numMatches = 1 +
(int)(lastAvailSequenceNumber - requestedSequenceNumber);
final Notification[] notifs = new Notification[ numMatches ];
final int startIndex = (int)
(requestedSequenceNumber - firstAvailSequenceNumber);
for( int i = 0 ; i < numMatches; ++i )
{
notifs[ i ] = (Notification)
mNotifications.get( startIndex + i );
}
result.put( NOTIFICATIONS_KEY, notifs );
}
}
}
assert( result.get( NOTIFICATIONS_KEY ) instanceof Notification[] );
assert( result.get( NEXT_SEQUENCE_NUMBER_KEY ) instanceof Long );
return( result );