public List < LogSegment > trunc ( int newStart ) { if ( newStart < 0 ) { throw new IllegalArgumentException ( "Starting index must be positive." ) ; } while ( true ) { List < LogSegment > curr = contents . get ( ) ; int newLength = Math . max ( curr . size ( ) - newStart , 0 ) ; List < LogSegment > updatedList = new ArrayList < LogSegment > ( curr . subList ( Math . min ( newStart , curr . size ( ) - 1 ) , curr . size ( ) ) ) ; if ( contents . compareAndSet ( curr , updatedList ) ) { return curr . subList ( 0 , curr . size ( ) - newLength ) ; } } }
Delete the first n items from the list