private void processReport(int id,long seqno,long time,D datum){
  ThreadPosition tp=array.get(id);
  if (tp == null) {
    tp=new ThreadPosition();
    tp.id=id;
    tp.seqno=seqno;
    tp.time=time;
    tp.reportTime=System.currentTimeMillis();
    tp.datum=datum;
    array.put(id,tp);
    if (head == null) {
      head=tp;
      tail=tp;
    }
 else {
      ThreadPosition nextTp=head;
      while (nextTp != null) {
        if (nextTp.seqno > tp.seqno) {
          if (nextTp.before != null)           nextTp.before.after=tp;
          tp.before=nextTp.before;
          tp.after=nextTp;
          nextTp.before=tp;
          break;
        }
        nextTp=nextTp.after;
      }
      if (nextTp == null) {
        tail.after=tp;
        tp.before=tail;
        tail=tp;
      }
      if (tp.before == null)       head=tp;
    }
  }
 else {
    if (tp.seqno > seqno)     bug("Thread reporting position moved backwards: task=" + id + " previous seqno="+ tp.seqno+ " new seqno="+ seqno);
    tp.seqno=seqno;
    tp.time=time;
    tp.reportTime=System.currentTimeMillis();
    tp.datum=datum;
    ThreadPosition nextTp=tp.after;
    while (nextTp != null && tp.seqno > tp.after.seqno) {
      if (tp.before != null)       tp.before.after=nextTp;
      if (nextTp.after != null)       nextTp.after.before=tp;
      nextTp.before=tp.before;
      tp.after=nextTp.after;
      nextTp.after=tp;
      tp.before=nextTp;
      if (head == tp)       head=nextTp;
      nextTp=tp.after;
    }
    if (tp.after == null)     tail=tp;
  }
}

private void processReport ( int id , long seqno , long time , D datum ) { ThreadPosition tp = array . get ( id ) ; if ( tp == null ) { tp = new ThreadPosition ( ) ; tp . id = id ; tp . seqno = seqno ; tp . time = time ; tp . reportTime = System . currentTimeMillis ( ) ; tp . datum = datum ; array . put ( id , tp ) ; if ( head == null ) { head = tp ; tail = tp ; } else { ThreadPosition nextTp = head ; while ( nextTp != null ) { if ( nextTp . seqno > tp . seqno ) { if ( nextTp . before != null ) nextTp . before . after = tp ; tp . before = nextTp . before ; tp . after = nextTp ; nextTp . before = tp ; break ; } nextTp = nextTp . after ; } if ( nextTp == null ) { tail . after = tp ; tp . before = tail ; tail = tp ; } if ( tp . before == null ) head = tp ; } } else { if ( tp . seqno > seqno ) bug ( "Thread reporting position moved backwards: task=" + id + " previous seqno=" + tp . seqno + " new seqno=" + seqno ) ; tp . seqno = seqno ; tp . time = time ; tp . reportTime = System . currentTimeMillis ( ) ; tp . datum = datum ; ThreadPosition nextTp = tp . after ; while ( nextTp != null && tp . seqno > tp . after . seqno ) { if ( tp . before != null ) tp . before . after = nextTp ; if ( nextTp . after != null ) nextTp . after . before = tp ; nextTp . before = tp . before ; tp . after = nextTp . after ; nextTp . after = tp ; tp . before = nextTp ; if ( head == tp ) head = nextTp ; nextTp = tp . after ; } if ( tp . after == null ) tail = tp ; } }
insert the reported position into the array using the seqno for ordering .
