Skip to content

Commit

Permalink
Added a method to order the cells of a partition
Browse files Browse the repository at this point in the history
Signed-off-by: John May <john.wilkinsonmay@gmail.com>
  • Loading branch information
gilleain authored and egonw committed Nov 29, 2012
1 parent 1ad2ad4 commit 22c75eb
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/main/org/openscience/cdk/group/Partition.java
Expand Up @@ -25,6 +25,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
Expand Down Expand Up @@ -407,6 +408,21 @@ public void insertCell(int index, SortedSet<Integer> cell) {
public SortedSet<Integer> copyBlock(int cellIndex) {
return new TreeSet<Integer>(this.cells.get(cellIndex));
}

/**
* Sort the cells in increasing order.
*/
@TestMethod("orderTest")
public void order() {
Collections.sort(cells, new Comparator<SortedSet<Integer>>() {

@Override
public int compare(SortedSet<Integer> cellA, SortedSet<Integer> cellB) {
return cellA.first().compareTo(cellB.first());
}

});
}

/**
* @inheritDoc
Expand Down
10 changes: 10 additions & 0 deletions src/test/org/openscience/cdk/group/PartitionTest.java
Expand Up @@ -292,5 +292,15 @@ public void equalsTest() {
Partition o = new Partition(new int[][]{{0}, {1}});
Assert.assertEquals(p, o);
}

@Test
public void orderTest() {
Partition p = new Partition(new int[][]{{1, 3}, {0, 2}});
p.order();
SortedSet<Integer> cell0 = p.getCell(0);
SortedSet<Integer> cell1 = p.getCell(1);
Assert.assertTrue(cell0.first() < cell1.first());
Assert.assertTrue(cell0.last() < cell1.last());
}

}

0 comments on commit 22c75eb

Please sign in to comment.