Partition { public Partition splitBefore(int cellIndex, int splitElement) { Partition r = new Partition(); for (int j = 0; j < cellIndex; j++) { r.addCell(this.copyBlock(j)); } r.addSingletonCell(splitElement); SortedSet<Integer> splitBlock = this.copyBlock(cellIndex); splitBlock.remove(splitElement); r.addCell(splitBlock); for (int j = cellIndex + 1; j < this.size(); j++) { r.addCell(this.copyBlock(j)); } return r; } Partition();  Partition(Partition other);  Partition(int[][] cellData); static Partition unit(int size); @Override boolean equals(Object o); @Override int hashCode(); int size(); int numberOfElements(); boolean isDiscrete(); Permutation toPermutation(); boolean inOrder(); int getFirstInCell(int cellIndex); SortedSet<Integer> getCell(int cellIndex); Partition splitBefore(int cellIndex, int splitElement); Partition splitAfter(int cellIndex, int splitElement); Permutation setAsPermutation(int upTo); boolean isDiscreteCell(int cellIndex); int getIndexOfFirstNonDiscreteCell(); void addSingletonCell(int element); void removeCell(int index); void addCell(int... elements); void addCell(Collection<Integer> elements); void addToCell(int index, int element); void insertCell(int index, SortedSet<Integer> cell); SortedSet<Integer> copyBlock(int cellIndex); void order(); boolean inSameCell(int elementI, int elementJ); @Override String toString(); static Partition fromString(String strForm);  }
@Test public void splitBeforeTest() { int[][] cellData = new int[][]{{0, 1}, {2, 3, 4}, {5, 6}}; Partition p = new Partition(cellData); int cellIndex = 1; int splitElement = 3; Partition q = p.splitBefore(cellIndex, splitElement); Assert.assertEquals(p.numberOfElements(), q.numberOfElements()); Assert.assertEquals(p.size() + 1, q.size()); SortedSet<Integer> cell = q.getCell(cellIndex); Assert.assertTrue(cell.size() == 1); Assert.assertEquals(splitElement, (int) cell.first()); }