src/main/java/pityoulish/msgboard/MixedMessageBoardImpl.java
public MessageBatch listMessages(int limit, String marker)
  {
    String problem = null;
    if (marker != null)
       problem = sanityChecker.checkMarker(marker);
    if (problem != null)
       throw new IllegalArgumentException(problem);

    Iterator<Map.Entry<String,MTMsg>> iter = null;
    int     count = 0;
    boolean discontinuous = false;

    if (marker == null)
     {
       // list oldest messages
       iter  = boardMessages.entrySet().iterator();
       count = boardMessages.size();
       if (limit > 0)
          count = Math.min(count, limit);
     }
    else
     {
       // list messages newer than marker
       NavigableMap<String,MTMsg>
         newerMessages = boardMessages.tailMap(marker, false);
       count = newerMessages.size();
       if (limit > 0)
          count = Math.min(count, limit);
       iter = newerMessages.entrySet().iterator();
       discontinuous = (boardSequencer.getComparator().
                        compare(lastDroppedUserMessageID, marker) > 0);
     }

    List<MTMsg> messages = new ArrayList<>(count);
    String    tailMarker = null; // becomes the marker in the result

    while ((count > 0) && iter.hasNext())
     {
       Map.Entry<String,MTMsg> entry = iter.next();
       messages.add(entry.getValue());
       tailMarker = entry.getKey();
       count--;
     }

    if (tailMarker == null) // no messages since marker
       tailMarker = marker;

    if (tailMarker == null) // board still empty
       tailMarker = lastDroppedUserMessageID;

    return new MessageBatchImpl
      (Collections.<Message> unmodifiableList(messages),
       tailMarker, discontinuous);
  }
// non-javadoc, see interface MessageBoard
non-javadoc, see interface MessageBoard
non - javadoc see interface MessageBoard
public MessageBatch listMessages(int limit, String marker)
  {
    String problem = null;
    if (marker != null)
       problem = sanityChecker.checkMarker(marker);
    if (problem != null)
       throw new IllegalArgumentException(problem);
    Iterator<Map.Entry<String,MTMsg>> iter = null;
    int     count = 0;
    boolean discontinuous = false;
    if (marker == null)
     {
       iter  = boardMessages.entrySet().iterator();
       count = boardMessages.size();
       if (limit > 0)
          count = Math.min(count, limit);
     }
    else
     {
       NavigableMap<String,MTMsg>
         newerMessages = boardMessages.tailMap(marker, false);
       count = newerMessages.size();
       if (limit > 0)
          count = Math.min(count, limit);
       iter = newerMessages.entrySet().iterator();
       discontinuous = (boardSequencer.getComparator().
                        compare(lastDroppedUserMessageID, marker) > 0);
     }
    List<MTMsg> messages = new ArrayList<>(count);
    String    tailMarker = null; 
    while ((count > 0) && iter.hasNext())
     {
       Map.Entry<String,MTMsg> entry = iter.next();
       messages.add(entry.getValue());
       tailMarker = entry.getKey();
       count--;
     }
    if (tailMarker == null) 
       tailMarker = marker;
    if (tailMarker == null) 
       tailMarker = lastDroppedUserMessageID;
    return new MessageBatchImpl
      (Collections.<Message> unmodifiableList(messages),
       tailMarker, discontinuous);
  }
public MessageBatch listMessages ( int limit , String marker ) { String problem = null ; if ( marker != null ) problem = sanityChecker . checkMarker ( marker ) ; if ( problem != null ) throw new IllegalArgumentException ( problem ) ; Iterator < Map . Entry < String , MTMsg > > iter = null ; int count = 0 ; boolean discontinuous = false ; if ( marker == null ) { iter = boardMessages . entrySet ( ) . iterator ( ) ; count = boardMessages . size ( ) ; if ( limit > 0 ) count = Math . min ( count , limit ) ; } else { NavigableMap < String , MTMsg > newerMessages = boardMessages . tailMap ( marker , false ) ; count = newerMessages . size ( ) ; if ( limit > 0 ) count = Math . min ( count , limit ) ; iter = newerMessages . entrySet ( ) . iterator ( ) ; discontinuous = ( boardSequencer . getComparator ( ) . compare ( lastDroppedUserMessageID , marker ) > 0 ) ; } List < MTMsg > messages = new ArrayList < > ( count ) ; String tailMarker = null ; while ( ( count > 0 ) && iter . hasNext ( ) ) { Map . Entry < String , MTMsg > entry = iter . next ( ) ; messages . add ( entry . getValue ( ) ) ; tailMarker = entry . getKey ( ) ; count -- ; } if ( tailMarker == null ) tailMarker = marker ; if ( tailMarker == null ) tailMarker = lastDroppedUserMessageID ; return new MessageBatchImpl ( Collections . < Message > unmodifiableList ( messages ) , tailMarker , discontinuous ) ; }
non-javadoc, see interface MessageBoard
non - javadoc see interface MessageBoard
// list oldest messages // list messages newer than marker // becomes the marker in the result // no messages since marker // board still empty