use of java.util.Comparator in project robovm by robovm.
the class ArraysTest method test_binarySearch$Ljava_lang_ObjectLjava_lang_ObjectLjava_util_Comparator.
/**
* java.util.Arrays#binarySearch(java.lang.Object[],
* java.lang.Object, java.util.Comparator)
*/
public void test_binarySearch$Ljava_lang_ObjectLjava_lang_ObjectLjava_util_Comparator() {
// Test for method int java.util.Arrays.binarySearch(java.lang.Object
// [], java.lang.Object, java.util.Comparator)
Comparator comp = new ReversedIntegerComparator();
for (int counter = 0; counter < arraySize; counter++) objectArray[counter] = objArray[arraySize - counter - 1];
assertTrue("Binary search succeeded for value not present in array 1", Arrays.binarySearch(objectArray, new Integer(-1), comp) == -(arraySize + 1));
assertEquals("Binary search succeeded for value not present in array 2", -1, Arrays.binarySearch(objectArray, new Integer(arraySize), comp));
for (int counter = 0; counter < arraySize; counter++) assertTrue("Binary search on Object[] with custom comparator answered incorrect position", Arrays.binarySearch(objectArray, objArray[counter], comp) == arraySize - counter - 1);
}
use of java.util.Comparator in project rstudio by rstudio.
the class BranchToolbarButton method populateMenu.
private void populateMenu(final ToolbarPopupMenu menu, final Map<String, List<String>> branchMap) {
MapUtil.forEach(branchMap, new MapUtil.ForEachCommand<String, List<String>>() {
@Override
public void execute(final String caption, final List<String> branches) {
// place commonly-used branches at the top
Collections.sort(branches, new Comparator<String>() {
private final String[] specialBranches_ = new String[] { "master", "develop", "trunk" };
@Override
public int compare(String o1, String o2) {
for (String specialBranch : specialBranches_) {
if (o1.endsWith(specialBranch))
return -1;
else if (o2.endsWith(specialBranch))
return 1;
}
return o1.compareToIgnoreCase(o2);
}
});
menu.addSeparator(new CustomMenuItemSeparator() {
@Override
public Widget createMainWidget() {
String branchLabel = caption.equals(LOCAL_BRANCHES) ? LOCAL_BRANCHES : "(Remote: " + caption + ")";
Label label = new Label(branchLabel);
label.addStyleName(ThemeStyles.INSTANCE.menuSubheader());
label.getElement().getStyle().setPaddingLeft(2, Unit.PX);
return label;
}
});
menu.addSeparator();
for (String branch : branches) {
// skip detached branches
if (branch.contains("HEAD detached at"))
continue;
// skip HEAD branches
if (branch.contains("HEAD ->"))
continue;
// construct branch label without remotes prefix
final String branchLabel = branch.replaceAll("^remotes/" + caption + "/", "");
final String branchValue = branch.replaceAll("\\s+\\-\\>.*", "");
menu.addItem(new MenuItem(branchLabel, new SwitchBranchCommand(branchLabel, branchValue)));
}
}
});
}
use of java.util.Comparator in project StylishMusicPlayer by ryanhoo.
the class FolderPresenter method loadFolders.
@Override
public void loadFolders() {
Subscription subscription = mRepository.folders().subscribeOn(Schedulers.io()).doOnNext(new Action1<List<Folder>>() {
@Override
public void call(List<Folder> folders) {
Collections.sort(folders, new Comparator<Folder>() {
@Override
public int compare(Folder f1, Folder f2) {
return f1.getName().compareToIgnoreCase(f2.getName());
}
});
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Subscriber<List<Folder>>() {
@Override
public void onStart() {
mView.showLoading();
}
@Override
public void onCompleted() {
mView.hideLoading();
}
@Override
public void onError(Throwable e) {
mView.hideLoading();
mView.handleError(e);
}
@Override
public void onNext(List<Folder> folders) {
mView.onFoldersLoaded(folders);
}
});
mSubscriptions.add(subscription);
}
use of java.util.Comparator in project spring-framework by spring-projects.
the class RequestMappingInfoTests method compareTwoHttpMethodsOneParam.
@Test
public void compareTwoHttpMethodsOneParam() {
RequestMappingInfo none = paths().build();
RequestMappingInfo oneMethod = paths().methods(RequestMethod.GET).build();
RequestMappingInfo oneMethodOneParam = paths().methods(RequestMethod.GET).params("foo").build();
ServerWebExchange exchange = MockServerHttpRequest.get("/foo").toExchange();
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, exchange);
List<RequestMappingInfo> list = asList(none, oneMethod, oneMethodOneParam);
Collections.shuffle(list);
list.sort(comparator);
assertEquals(oneMethodOneParam, list.get(0));
assertEquals(oneMethod, list.get(1));
assertEquals(none, list.get(2));
}
use of java.util.Comparator in project spring-framework by spring-projects.
the class RequestMappingInfoTests method compareToWithHttpHeadMapping.
// SPR-14383
@Test
public void compareToWithHttpHeadMapping() {
MockHttpServletRequest request = new MockHttpServletRequest();
request.setMethod("HEAD");
request.addHeader("Accept", "application/json");
RequestMappingInfo noMethods = paths().build();
RequestMappingInfo getMethod = paths().methods(GET).produces("application/json").build();
RequestMappingInfo headMethod = paths().methods(HEAD).build();
Comparator<RequestMappingInfo> comparator = (info, otherInfo) -> info.compareTo(otherInfo, request);
List<RequestMappingInfo> list = asList(noMethods, getMethod, headMethod);
Collections.shuffle(list);
Collections.sort(list, comparator);
assertEquals(headMethod, list.get(0));
assertEquals(getMethod, list.get(1));
assertEquals(noMethods, list.get(2));
}
Aggregations