Java Code Examples for org.springframework.util.comparator.ComparableComparator

The following examples show how to use org.springframework.util.comparator.ComparableComparator. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: spring-analysis-note   Source File: ConvertingComparatorTests.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldGetMapEntryKeys() throws Exception {
	ArrayList<Entry<String, Integer>> list = createReverseOrderMapEntryList();
	Comparator<Map.Entry<String, Integer>> comparator = ConvertingComparator.mapEntryKeys(new ComparableComparator<String>());
	Collections.sort(list, comparator);
	assertThat(list.get(0).getKey(), is("a"));
}
 
Example 2
Source Project: spring-analysis-note   Source File: ConvertingComparatorTests.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldGetMapEntryValues() throws Exception {
	ArrayList<Entry<String, Integer>> list = createReverseOrderMapEntryList();
	Comparator<Map.Entry<String, Integer>> comparator = ConvertingComparator.mapEntryValues(new ComparableComparator<Integer>());
	Collections.sort(list, comparator);
	assertThat(list.get(0).getValue(), is(1));
}
 
Example 3
Source Project: java-technology-stack   Source File: ConvertingComparatorTests.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldGetMapEntryKeys() throws Exception {
	ArrayList<Entry<String, Integer>> list = createReverseOrderMapEntryList();
	Comparator<Map.Entry<String, Integer>> comparator = ConvertingComparator.mapEntryKeys(new ComparableComparator<String>());
	Collections.sort(list, comparator);
	assertThat(list.get(0).getKey(), is("a"));
}
 
Example 4
Source Project: java-technology-stack   Source File: ConvertingComparatorTests.java    License: MIT License 5 votes vote down vote up
@Test
public void shouldGetMapEntryValues() throws Exception {
	ArrayList<Entry<String, Integer>> list = createReverseOrderMapEntryList();
	Comparator<Map.Entry<String, Integer>> comparator = ConvertingComparator.mapEntryValues(new ComparableComparator<Integer>());
	Collections.sort(list, comparator);
	assertThat(list.get(0).getValue(), is(1));
}
 
Example 5
public void assertCollate(List<Integer> results, Integer[] source, int skip, int pageSize, boolean boundsError)
            throws Exception
{
    Arrays.sort(source);
    Collections.sort(results);
    int[] expected = createMergedPage(skip,
                                      pageSize,
                                      results,
                                      source);
    PagingResults<Integer> actualResults = new PageCollator<Integer>().collate(results,
                                                                               new ArrayPageSource(source),
                                                                               new PagingRequest(skip,
                                                                                                 pageSize),
                                                                               new ComparableComparator<Integer>());
    List<Integer> actualPage = actualResults.getPage();

    final String message = "[" + results + " + " + Arrays.toString(source) + " ] -> " + Arrays.toString(expected)
                + " != " + actualPage;
    assertEqualPages(message,
                     expected,
                     actualPage);
    assertEquals("Invalid moreItems info!",
                 (pageSize != 0) && (skip + pageSize < results.size() + source.length),
                 actualResults.hasMoreItems());
    assertTrue(message,
               (pageSize == 0) || actualPage.size() <= pageSize);
    final int expectedTotal = source.length + results.size();
    if (boundsError && !new Pair<Integer, Integer>(null,
                                                   null).equals(actualResults.getTotalResultCount()))
    {
        assertEquals("Invalid total info",
                     new Pair<Integer, Integer>(expectedTotal,
                                                expectedTotal),
                     actualResults.getTotalResultCount());
    }
    logger.info(actualPage);
}
 
Example 6
@Test
public void shouldGetMapEntryKeys() throws Exception {
	ArrayList<Entry<String, Integer>> list = createReverseOrderMapEntryList();
	Comparator<Map.Entry<String, Integer>> comparator = ConvertingComparator.mapEntryKeys(new ComparableComparator<String>());
	Collections.sort(list, comparator);
	assertThat(list.get(0).getKey(), is("a"));
}
 
Example 7
@Test
public void shouldGetMapEntryValues() throws Exception {
	ArrayList<Entry<String, Integer>> list = createReverseOrderMapEntryList();
	Comparator<Map.Entry<String, Integer>> comparator = ConvertingComparator.mapEntryValues(new ComparableComparator<Integer>());
	Collections.sort(list, comparator);
	assertThat(list.get(0).getValue(), is(1));
}
 
Example 8
Source Project: rqueue   Source File: RqueueMessageHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Comparator<MappingInformation> getMappingComparator(Message<?> message) {
  return new ComparableComparator<>();
}
 
Example 9
Source Project: lams   Source File: ConvertingComparator.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * Create a new {@link ConvertingComparator} instance.
 * @param converter the converter
 */
@SuppressWarnings("unchecked")
public ConvertingComparator(Converter<S, T> converter) {
	this(ComparableComparator.INSTANCE, converter);
}
 
Example 10
/**
 * Create a new {@link ConvertingComparator} instance.
 * @param converter the converter
 */
@SuppressWarnings("unchecked")
public ConvertingComparator(Converter<S, T> converter) {
	this(ComparableComparator.INSTANCE, converter);
}
 
Example 11
Source Project: spring-cloud-aws   Source File: QueueMessageHandler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected Comparator<MappingInformation> getMappingComparator(Message<?> message) {
	return new ComparableComparator<>();
}