本文整理汇总了Java中java.util.Collections.sort方法的典型用法代码示例。如果您正苦于以下问题:Java Collections.sort方法的具体用法?Java Collections.sort怎么用?Java Collections.sort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.Collections
的用法示例。
在下文中一共展示了Collections.sort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WeekLessonDiaLogItemAdapter
import java.util.Collections; //导入方法依赖的package包/类
public WeekLessonDiaLogItemAdapter(@Nonnull Context context, @Nonnull List<WeekLessonDialogItem> list, int text_color, int bg_color) {
super(context, null);
mIsExpandPosList = new ArrayList<>();
Collections.sort(list, weekLessonDialogItemComparator);
mListData.addAll(list);
for (int i = 0; i < mListData.size(); i++) {
mIsExpandPosList.add(false);
}
try {
mRepeatList = mDbHelper.getRepeatList();
} catch (NullObjectException e) {
Log.d(TAG, e.toString());
}
mTextColor = text_color;
mBgColor = bg_color;
Resources resources = mContext.getResources();
mStatus_New = resources.getString(R.string.status_new);
mStatus_Unsaved = resources.getString(R.string.status_change);
}
示例2: toggleFileTree
import java.util.Collections; //导入方法依赖的package包/类
private void toggleFileTree(File file){
//路径名
mTvPath.setText(getString(R.string.nb_file_path,file.getPath()));
//获取数据
File[] files = file.listFiles(new SimpleFileFilter());
//转换成List
List<File> rootFiles = Arrays.asList(files);
//排序
Collections.sort(rootFiles,new FileComparator());
//加入
mAdapter.refreshItems(rootFiles);
//反馈
if (mListener != null){
mListener.onCategoryChanged();
}
}
示例3: onActualMessagePeerMessageReceived
import java.util.Collections; //导入方法依赖的package包/类
private void onActualMessagePeerMessageReceived(int accountId, int peerId, int unreadCount, Message message) {
if (accountId != this.dialogsOwnerId) {
return;
}
int index = indexOf(this.dialogs, peerId);
if (index != -1) {
Dialog dialog = this.dialogs.get(index);
dialog.setMessage(message)
.setUnreadCount(unreadCount)
.setLastMessageId(message.getId());
if (dialog.isChat()) {
dialog.setInterlocutor(message.getSender());
}
Collections.sort(this.dialogs, COMPARATOR);
}
safeNotifyDataSetChanged();
}
示例4: getCountries
import java.util.Collections; //导入方法依赖的package包/类
public static List<LocationDto> getCountries(LocationDto area) throws ExternalServiceException {
try {
List<LocationDto> countries = new ArrayList<LocationDto>();
if (area == null) {
return Collections.emptyList();
}
for (LocationDto loc : area.getChildren()) {
if (!isAlive(loc)) {
continue;
}
LocationType type = getLocationType(loc);
if (type != null && type == LocationType.COUNTRY) {
countries.add(loc);
}
}
Collections.sort(countries, new LocationComparator());
return countries;
} catch (Exception e) {
throw ExceptionUtils.getExternalServiceException(e);
}
}
示例5: toSort
import java.util.Collections; //导入方法依赖的package包/类
/**
* 简单的单维比较排序(正序)
*
* @author ZhengWei(HY)
* @createDate 2015-12-10
* @version v1.0
*
* @param i_Values
* @return
*/
@SafeVarargs
public final static <T extends Comparable<? super T>> List<T> toSort(T ... i_Values)
{
if ( Help.isNull(i_Values) )
{
return new ArrayList<T>(0);
}
List<T> v_Values = new ArrayList<T>(i_Values.length);
for (T v_Item : i_Values)
{
v_Values.add(v_Item);
}
Collections.sort(v_Values);
return v_Values;
}
示例6: orderCollection
import java.util.Collections; //导入方法依赖的package包/类
/**
* Ordernar uma lista
* @param collecao
* @param orderMode
*/
public static void orderCollection (List collecao, OrederBy orderMode)
{
Float f;
Integer i;
if (orderMode == OrederBy.ASC)
Collections.sort(collecao);
else
{
Comparator c = (Comparator) (Object o1, Object o2) ->
{
try
{
Comparable co1 = (Comparable) o1;
if (o1.getClass().equals(o2.getClass()))
{
return co1.compareTo(o2) * -1;
}
}catch(Exception ex) {}
return 0;
};
Collections.sort(collecao, c);
}
}
示例7: sortCraftManager
import java.util.Collections; //导入方法依赖的package包/类
public static void sortCraftManager()
{
bake();
FMLLog.fine("Sorting recipes");
warned.clear();
Collections.sort(CraftingManager.getInstance().getRecipeList(), INSTANCE);
}
示例8: dumpRandomSentences
import java.util.Collections; //导入方法依赖的package包/类
/**
* Dump a set of random sentences that fit this grammar
*
* @param count
* dumps no more than this. May dump less than this depending
* upon the number of uniqe sentences in the grammar.
*/
public void dumpRandomSentences(int count) {
Set<String> set = new HashSet<String>();
for (int i = 0; i < count; i++) {
String s = getRandomSentence();
if (!set.contains(s)) {
set.add(s);
}
}
List<String> sampleList = new ArrayList<String>(set);
Collections.sort(sampleList);
for (String sentence : sampleList) {
System.out.println(sentence);
}
}
示例9: setWidgets
import java.util.Collections; //导入方法依赖的package包/类
public void setWidgets(MultiHashMap<PackageItemInfo, WidgetItem> widgets) {
mEntries.clear();
WidgetItemComparator widgetComparator = new WidgetItemComparator();
for (Map.Entry<PackageItemInfo, ArrayList<WidgetItem>> entry : widgets.entrySet()) {
WidgetListRowEntry row = new WidgetListRowEntry(entry.getKey(), entry.getValue());
row.titleSectionName = mIndexer.computeSectionName(row.pkgItem.title);
Collections.sort(row.widgets, widgetComparator);
mEntries.add(row);
}
Collections.sort(mEntries, new WidgetListRowEntryComparator());
}
示例10: toSetOf
import java.util.Collections; //导入方法依赖的package包/类
private static byte[] toSetOf(Collection<?> values, Asn1Type elementType)
throws Asn1EncodingException {
List<byte[]> serializedValues = new ArrayList<>(values.size());
for (Object value : values) {
serializedValues.add(JavaToDerConverter.toDer(value, elementType, null));
}
if (serializedValues.size() > 1) {
Collections.sort(serializedValues, ByteArrayLexicographicComparator.INSTANCE);
}
return createTag(
BerEncoding.TAG_CLASS_UNIVERSAL, true, BerEncoding.TAG_NUMBER_SET,
serializedValues.toArray(new byte[0][]));
}
示例11: updateOrder
import java.util.Collections; //导入方法依赖的package包/类
public void updateOrder() {
synchronized (mAddedAppItems) {
Collections.sort(mAddedAppItems, new AppItem.IndexComparator());
}
notifyListener();
mHandler.obtainMessage(MSG_SAVE_ORDER).sendToTarget();
}
示例12: processResult
import java.util.Collections; //导入方法依赖的package包/类
public void processResult(int rc, String path, Object ctx,
List<String> children, Stat stat)
{
this.children =
(children == null ? new ArrayList<String>() : children);
Collections.sort(this.children);
super.processResult(Code.get(rc), path, ctx);
}
示例13: getHardwareProperties
import java.util.Collections; //导入方法依赖的package包/类
/**
* Returns the hardware properties defined in
* {@link AvdManager#HARDWARE_INI} as a {@link Map}.
*
* This is intended to be dumped in the config.ini and already contains
* the device name, manufacturer and device hash.
*
* @param d The {@link Device} from which to derive the hardware properties.
* @return A {@link Map} of hardware properties.
*/
@NonNull
public static Map<String, String> getHardwareProperties(@NonNull Device d) {
Map<String, String> props = getHardwareProperties(d.getDefaultState());
for (State s : d.getAllStates()) {
if (s.getKeyState().equals(KeyboardState.HIDDEN)) {
props.put("hw.keyboard.lid", getBooleanVal(true));
}
}
HashFunction md5 = Hashing.md5();
Hasher hasher = md5.newHasher();
ArrayList<String> keys = new ArrayList<String>(props.keySet());
Collections.sort(keys);
for (String key : keys) {
if (key != null) {
hasher.putString(key, Charsets.UTF_8);
String value = props.get(key);
hasher.putString(value == null ? "null" : value, Charsets.UTF_8);
}
}
// store the hash method for potential future compatibility
String hash = "MD5:" + hasher.hash().toString();
props.put(AvdManager.AVD_INI_DEVICE_HASH_V2, hash);
props.remove(AvdManager.AVD_INI_DEVICE_HASH_V1);
props.put(AvdManager.AVD_INI_DEVICE_NAME, d.getId());
props.put(AvdManager.AVD_INI_DEVICE_MANUFACTURER, d.getManufacturer());
return props;
}
示例14: testInnerClassSort
import java.util.Collections; //导入方法依赖的package包/类
public void testInnerClassSort()
{
Comparator<? super Coordinate> coordSorter = new Comp();
List<? extends Coordinate> points = (List)makeSampleList();
Collections.sort( points, coordSorter );
assertEquals( makeSampleList_Sorted(), points );
}
示例15: calculateMin
import java.util.Collections; //导入方法依赖的package包/类
private int calculateMin(List<Integer> items) {
Collections.sort(items);
return (items.size() > 0) ? items.get(0) : 0;
}