public Partition splitBefore ( int cellIndex , int splitElement ) { Partition r = new Partition ( ) ; // copy the cells up to cellIndex for ( int j = 0 ; j < cellIndex ; j ++ ) { r . addCell ( this . copyBlock ( j ) ) ; } // split the block at block index r . addSingletonCell ( splitElement ) ; SortedSet < Integer > splitBlock = this . copyBlock ( cellIndex ) ; splitBlock . remove ( splitElement ) ; r . addCell ( splitBlock ) ; // copy the blocks after blockIndex, shuffled up by one for ( int j = cellIndex + 1 ; j < this . size ( ) ; j ++ ) { r . addCell ( this . copyBlock ( j ) ) ; } return r ; }
Splits this partition by taking the cell at cellIndex and making two new cells - the first with the singleton splitElement and the second with the rest of the elements from that cell .