public static SortedSet<Integer> adjustPosition(Set<Integer> positions,int startPosition,int endPosition,int adjustBy){
  SortedSet<Integer> newPositions=new TreeSet<>();
  for (  Integer entry : positions) {
    int position=entry;
    if (position < startPosition || position > endPosition) {
      newPositions.add(position);
    }
 else     if (adjustBy > 0) {
      newPositions.add(position + adjustBy);
    }
 else     if (adjustBy < 0) {
      if (position > startPosition + adjustBy && position <= startPosition) {
        ;
      }
 else {
        newPositions.add(position + adjustBy);
      }
    }
  }
  return newPositions;
}

public static SortedSet < Integer > adjustPosition ( Set < Integer > positions , int startPosition , int endPosition , int adjustBy ) { SortedSet < Integer > newPositions = new TreeSet < > ( ) ; for ( Integer entry : positions ) { int position = entry ; if ( position < startPosition || position > endPosition ) { newPositions . add ( position ) ; } else if ( adjustBy > 0 ) { newPositions . add ( position + adjustBy ) ; } else if ( adjustBy < 0 ) { if ( position > startPosition + adjustBy && position <= startPosition ) { ; } else { newPositions . add ( position + adjustBy ) ; } } } return newPositions ; }
internal method to handle the selections if items are added / removed
