question: public static SparseIntArray adjustPosition ( SparseIntArray positions , int startPosition , int endPosition , int adjustBy ) { SparseIntArray newPositions = new SparseIntArray ( ) ; for ( int i = 0 , size = positions . size ( ) ; i < size ; i ++ ) { int position = positions . keyAt ( i ) ; if ( position < startPosition || position > endPosition ) { newPositions . put ( position , positions . valueAt ( i ) ) ; } else if ( adjustBy > 0 ) { newPositions . put ( position + adjustBy , positions . valueAt ( i ) ) ; } else if ( adjustBy < 0 ) { if ( position > startPosition + adjustBy && position <= startPosition ) { ; } else { newPositions . put ( position + adjustBy , positions . valueAt ( i ) ) ; } } } return newPositions ; }
target:  internal method to handle the selections if items are added / removed