Java 类org.springframework.util.comparator.ComparableComparator 实例源码
项目:alfresco-repository
文件:PageCollatorTest.java
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);
}
项目:spring4-understanding
文件:ConvertingComparatorTests.java
@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"));
}
项目:spring4-understanding
文件:ConvertingComparatorTests.java
@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));
}
项目:eHMP
文件:JsonVistaAccountDao.java
@Override
public List<VistaAccount> findAll(final Sort sort) {
List<VistaAccount> accounts = getVistaAccounts();
if (sort == null) return Collections.unmodifiableList(accounts);
Collections.sort(accounts, new Comparator<VistaAccount>() {
private Comparator nullSafeComparableComparator = new NullSafeComparator(new ComparableComparator(), false);
@Override
public int compare(VistaAccount a1, VistaAccount a2) {
BeanWrapper b1 = new BeanWrapperImpl(a1);
BeanWrapper b2 = new BeanWrapperImpl(a2);
for (Sort.Order order : sort) {
Object val1 = b1.getPropertyValue(order.getProperty());
Object val2 = b2.getPropertyValue(order.getProperty());
int val = nullSafeComparableComparator.compare(val1, val2);
if (val != 0) return val;
}
return 0;
}
});
return Collections.unmodifiableList(accounts);
}
项目:community-edition-old
文件:PageCollatorTest.java
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);
}
项目:class-guard
文件:ConvertingComparatorTests.java
@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"));
}
项目:class-guard
文件:ConvertingComparatorTests.java
@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));
}
项目:spring-rich-client
文件:LabeledEnumComboBoxBinding.java
protected void doBindControl(ListModel bindingModel) {
setRenderer(new LabeledEnumListRenderer(getMessageSource()));
setEditor(new LabeledEnumComboBoxEditor(getMessageSource(), getEditor()));
CompoundComparator comparator = new CompoundComparator();
comparator.addComparator(LabeledEnum.LABEL_ORDER);
comparator.addComparator(new ComparableComparator());
setComparator(comparator);
super.doBindControl(bindingModel);
}
项目:spring-rich-client
文件:DefaultComponentFactory.java
public void configureForEnum(JComboBox comboBox, Class enumType) {
Collection enumValues = getEnumResolver().getLabeledEnumSet(enumType);
if (logger.isDebugEnabled()) {
logger.debug("Populating combo box model with enums of type '" + enumType.getName() + "'; enums are ["
+ enumValues + "]");
}
CompoundComparator comparator = new CompoundComparator();
comparator.addComparator(LabeledEnum.LABEL_ORDER);
comparator.addComparator(new ComparableComparator());
comboBox.setModel(new ComboBoxListModel(new ArrayList(enumValues), comparator));
comboBox.setRenderer(new LabeledEnumListRenderer(messageSource));
comboBox.setEditor(new LabeledEnumComboBoxEditor(messageSource, comboBox.getEditor()));
}
项目:spring-rich-client
文件:ComboBoxBindingTests.java
public void testComparator() {
ComboBoxBinder binder = new ComboBoxBinder();
binder.setSelectableItems(new Object[] { "2", "4", "1", "2", "3" });
binder.setComparator(new ComparableComparator());
ComboBoxBinding binding = (ComboBoxBinding) binder.bind(fm, "simpleProperty", Collections.EMPTY_MAP);
ListModel bindingModel = binding.getBindingModel();
assertEquals(5, bindingModel.getSize());
assertEquals("1", bindingModel.getElementAt(0));
assertEquals("2", bindingModel.getElementAt(1));
assertEquals("2", bindingModel.getElementAt(2));
assertEquals("3", bindingModel.getElementAt(3));
assertEquals("4", bindingModel.getElementAt(4));
}
项目:spring-richclient
文件:LabeledEnumComboBoxBinding.java
protected void doBindControl(ListModel bindingModel) {
setRenderer(new LabeledEnumListRenderer(getMessageSource()));
setEditor(new LabeledEnumComboBoxEditor(getMessageSource(), getEditor()));
CompoundComparator comparator = new CompoundComparator();
comparator.addComparator(LabeledEnum.LABEL_ORDER);
comparator.addComparator(new ComparableComparator());
setComparator(comparator);
super.doBindControl(bindingModel);
}
项目:spring-richclient
文件:DefaultComponentFactory.java
public void configureForEnum(JComboBox comboBox, Class enumType) {
Collection enumValues = getEnumResolver().getLabeledEnumSet(enumType);
if (logger.isDebugEnabled()) {
logger.debug("Populating combo box model with enums of type '" + enumType.getName() + "'; enums are ["
+ enumValues + "]");
}
CompoundComparator comparator = new CompoundComparator();
comparator.addComparator(LabeledEnum.LABEL_ORDER);
comparator.addComparator(new ComparableComparator());
comboBox.setModel(new ComboBoxListModel(new ArrayList(enumValues), comparator));
comboBox.setRenderer(new LabeledEnumListRenderer(messageSource));
comboBox.setEditor(new LabeledEnumComboBoxEditor(messageSource, comboBox.getEditor()));
}
项目:spring-richclient
文件:ComboBoxBindingTests.java
public void testComparator() {
ComboBoxBinder binder = new ComboBoxBinder();
binder.setSelectableItems(new Object[] { "2", "4", "1", "2", "3" });
binder.setComparator(new ComparableComparator());
ComboBoxBinding binding = (ComboBoxBinding) binder.bind(fm, "simpleProperty", Collections.EMPTY_MAP);
ListModel bindingModel = binding.getBindingModel();
assertEquals(5, bindingModel.getSize());
assertEquals("1", bindingModel.getElementAt(0));
assertEquals("2", bindingModel.getElementAt(1));
assertEquals("2", bindingModel.getElementAt(2));
assertEquals("3", bindingModel.getElementAt(3));
assertEquals("4", bindingModel.getElementAt(4));
}
项目:spring4-understanding
文件:ConvertingComparator.java
/**
* Create a new {@link ConvertingComparator} instance.
* @param converter the converter
*/
@SuppressWarnings("unchecked")
public ConvertingComparator(Converter<S, T> converter) {
this(ComparableComparator.INSTANCE, converter);
}
项目:spring
文件:ConvertingComparator.java
/**
* Create a new {@link ConvertingComparator} instance.
* @param converter the converter
*/
@SuppressWarnings("unchecked")
public ConvertingComparator(Converter<S, T> converter) {
this(ComparableComparator.INSTANCE, converter);
}
项目:spring-cloud-aws
文件:QueueMessageHandler.java
@Override
protected Comparator<MappingInformation> getMappingComparator(Message<?> message) {
return new ComparableComparator<>();
}
项目:class-guard
文件:ConvertingComparator.java
/**
* Create a new {@link ConvertingComparator} instance.
*
* @param converter the converter
*/
@SuppressWarnings("unchecked")
public ConvertingComparator(Converter<S, T> converter) {
this(ComparableComparator.INSTANCE, converter);
}