org.springframework.util.comparator.ComparableComparator Java Examples

The following examples show how to use org.springframework.util.comparator.ComparableComparator. 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 File: ConvertingComparatorTests.java    From spring-analysis-note with 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 File: ConvertingComparatorTests.java    From spring-analysis-note with 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 File: ConvertingComparatorTests.java    From java-technology-stack with 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 File: ConvertingComparatorTests.java    From java-technology-stack with 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
Source File: PageCollatorTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
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
Source File: ConvertingComparatorTests.java    From spring4-understanding with Apache License 2.0 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 #7
Source File: ConvertingComparatorTests.java    From spring4-understanding with Apache License 2.0 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 #8
Source File: RqueueMessageHandler.java    From rqueue with Apache License 2.0 4 votes vote down vote up
@Override
protected Comparator<MappingInformation> getMappingComparator(Message<?> message) {
  return new ComparableComparator<>();
}
 
Example #9
Source File: ConvertingComparator.java    From lams with 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
Source File: ConvertingComparator.java    From spring4-understanding with Apache License 2.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 #11
Source File: QueueMessageHandler.java    From spring-cloud-aws with Apache License 2.0 4 votes vote down vote up
@Override
protected Comparator<MappingInformation> getMappingComparator(Message<?> message) {
	return new ComparableComparator<>();
}