public void add ( long date , T element ) { if ( size == 0 ) { elements [ 0 ] = element ; dates [ 0 ] = date ; size = 1 ; oldestIndex = 0 ; newestIndex = 0 ; return ; } if ( size < elements . length ) { elements [ size ] = element ; dates [ size ] = date ; if ( date < dates [ oldestIndex ] ) oldestIndex = size ; if ( date > dates [ newestIndex ] ) newestIndex = size ; size ++ ; return ; } if ( dates [ oldestIndex ] > date ) { // older than oldest if ( newestIndex < 0 ) refreshNewestIndex ( ) ; elements [ newestIndex ] = element ; dates [ newestIndex ] = date ; oldestIndex = newestIndex ; newestIndex = - 1 ; return ; } if ( newestIndex < 0 ) refreshNewestIndex ( ) ; if ( dates [ newestIndex ] < date ) return ; // newer than newest // replace the newest elements [ newestIndex ] = element ; dates [ newestIndex ] = date ; oldestIndex = newestIndex ; newestIndex = - 1 ; return ; }
Add an elements with the given timestamp .