private static int compareNodes(Sortable node1, Sortable node2) { int result = node1.getNodeWeight() - node2.getNodeWeight(); if (0 == result) { result = StringUtils.stringCompare(node1.getText(), node2.getText()); } return result; }
/* 22: */ /* 23: */ public void apply(Object object) /* 24: */ { /* 25:37 */ if ((object instanceof Sortable)) /* 26: */ { /* 27:38 */ Sortable sortable = (Sortable) object; /* 28:39 */ sortable.sort(this); /* 29: */ } /* 30: */ }
public static void main(String[] args) { Sortable sortable = new BubbleSort(); int[] input = {2, 0, 0, 2, 1, 4, 7, 0, 0, 4}; System.out.println("\nBefore Sort : "); SortUtil.display(input); sortable.sort(input); System.out.println("\nAfter Sort : "); SortUtil.display(input); }
@Test public void testSort() throws Exception { Integer[] arr = new Integer[] {5, 2, 3, 1, 0, 4}; Integer[] sorted = sortable.sort(arr); assertNotNull(sorted); assertEquals(arr.length, sorted.length); assertArrayEquals(sorted, new Integer[] {0, 1, 2, 3, 4, 5}); assertSame(sorted[0], Integer.valueOf(0)); assertSame(sorted[5], Integer.valueOf(5)); }
/** * Sorts the test in <code>runner</code> using <code>comparator</code> * * @param object */ public void apply(Object object) { if (object instanceof Sortable) { Sortable sortable = (Sortable) object; sortable.sort(this); } }
@Override public void sort(int[] inputArray) { super.sort(inputArray); insertionSort(); }