@Test public void testExtractAndSort() { Stack<Month> stack = new Stack<>(); ListIterator<Month> listIterator = stack.listIterator(); Iterator<Month> iterator = SortUtil.extractAndSort(listIterator, null); assertTrue(stack.empty()); assertEquals("[]", stack.toString()); assertEquals(10, stack.capacity()); assertEquals(0, stack.size()); assertTrue(stack.isEmpty()); assertFalse(listIterator.hasNext()); assertFalse(listIterator.hasPrevious()); assertNotNull(iterator); }
public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor) { TreeMultimap<E, T> reorgnized = TreeMultimap.create(); while (input.hasNext()) { T t = input.next(); E e = extractor.apply(t); reorgnized.put(e, t); } return reorgnized.values().iterator(); }
SortUtil { public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor) { TreeMultimap<E, T> reorgnized = TreeMultimap.create(); while (input.hasNext()) { T t = input.next(); E e = extractor.apply(t); reorgnized.put(e, t); } return reorgnized.values().iterator(); } }
SortUtil { public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor) { TreeMultimap<E, T> reorgnized = TreeMultimap.create(); while (input.hasNext()) { T t = input.next(); E e = extractor.apply(t); reorgnized.put(e, t); } return reorgnized.values().iterator(); } private  SortUtil(); }
SortUtil { public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor) { TreeMultimap<E, T> reorgnized = TreeMultimap.create(); while (input.hasNext()) { T t = input.next(); E e = extractor.apply(t); reorgnized.put(e, t); } return reorgnized.values().iterator(); } private  SortUtil(); static Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor); }
SortUtil { public static <T extends Comparable, E extends Comparable> Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor) { TreeMultimap<E, T> reorgnized = TreeMultimap.create(); while (input.hasNext()) { T t = input.next(); E e = extractor.apply(t); reorgnized.put(e, t); } return reorgnized.values().iterator(); } private  SortUtil(); static Iterator<T> extractAndSort(Iterator<T> input, Function<T, E> extractor);  }