Java Code Examples for java.util.Collections.sort()

The following are Jave code examples for showing how to use sort() of the java.util.Collections class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: MyCalendar   File: WeekLessonDiaLogItemAdapter.java   View Source Code Vote up 6 votes
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);
}
 
Example 2
Project: NovelReader   File: FileCategoryFragment.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 3
Project: Phoenix-for-VK   File: DialogsPresenter.java   View Source Code Vote up 6 votes
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();
}
 
Example 4
Project: openNaEF   File: LocationUtil.java   View Source Code Vote up 6 votes
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);
    }
}
 
Example 5
Project: hy.common.base   File: Help.java   View Source Code Vote up 6 votes
/**
 * 简单的单维比较排序(正序)
 * 
 * @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;
}
 
Example 6
Project: NICON   File: OperacaoString.java   View Source Code Vote up 6 votes
/**
 * 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); 
    }
}
 
Example 7
Project: CustomWorldGen   File: RecipeSorter.java   View Source Code Vote up 6 votes
public static void sortCraftManager()
{
    bake();
    FMLLog.fine("Sorting recipes");
    warned.clear();
    Collections.sort(CraftingManager.getInstance().getRecipeList(), INSTANCE);
}
 
Example 8
Project: BrainControl   File: GrammarDump.java   View Source Code Vote up 6 votes
/**
 * 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);
	}
}
 
Example 9
Project: LaunchEnr   File: WidgetsListAdapter.java   View Source Code Vote up 5 votes
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());
}
 
Example 10
Project: FApkSigner   File: Asn1DerEncoder.java   View Source Code Vote up 5 votes
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][]));
}
 
Example 11
Project: Bigbang   File: AppManager.java   View Source Code Vote up 5 votes
public void updateOrder() {
    synchronized (mAddedAppItems) {
        Collections.sort(mAddedAppItems, new AppItem.IndexComparator());
    }
    notifyListener();
    mHandler.obtainMessage(MSG_SAVE_ORDER).sendToTarget();
}
 
Example 12
Project: fuck_zookeeper   File: AsyncOps.java   View Source Code Vote up 5 votes
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);
}
 
Example 13
Project: javaide   File: DeviceManager.java   View Source Code Vote up 5 votes
/**
 * 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;
}
 
Example 14
Project: manifold   File: StructuralTypeTest.java   View Source Code Vote up 5 votes
public void testInnerClassSort()
{
  Comparator<? super Coordinate> coordSorter = new Comp();
  List<? extends Coordinate>  points = (List)makeSampleList();
  Collections.sort( points, coordSorter );
  assertEquals( makeSampleList_Sorted(), points );
}
 
Example 15
Project: eadlsync   File: Statistic.java   View Source Code Vote up 4 votes
private int calculateMin(List<Integer> items) {
    Collections.sort(items);
    return (items.size() > 0) ? items.get(0) : 0;
}
 
Example 16
Project: MovieApp   File: PeopleDetailPresenter.java   View Source Code Vote up 4 votes
public List<Crew> getCrewList() {
    Collections.sort(crewList, new CrewReleaseDateComparator());
    return crewList;
}
 
Example 17
Project: airgram   File: ContactsController.java   View Source Code Vote up 4 votes
private void buildContactsSectionsArrays(boolean sort) {
    if (sort) {
        Collections.sort(contacts, new Comparator<TLRPC.TL_contact>() {
            @Override
            public int compare(TLRPC.TL_contact tl_contact, TLRPC.TL_contact tl_contact2) {
                TLRPC.User user1 = MessagesController.getInstance().getUser(tl_contact.user_id);
                TLRPC.User user2 = MessagesController.getInstance().getUser(tl_contact2.user_id);
                String name1 = UserObject.getFirstName(user1);
                String name2 = UserObject.getFirstName(user2);
                return name1.compareTo(name2);
            }
        });
    }

    StringBuilder ids = new StringBuilder();
    final HashMap<String, ArrayList<TLRPC.TL_contact>> sectionsDict = new HashMap<>();
    final ArrayList<String> sortedSectionsArray = new ArrayList<>();

    for (TLRPC.TL_contact value : contacts) {
        TLRPC.User user = MessagesController.getInstance().getUser(value.user_id);
        if (user == null) {
            continue;
        }

        String key = UserObject.getFirstName(user);
        if (key.length() > 1) {
            key = key.substring(0, 1);
        }
        if (key.length() == 0) {
            key = "#";
        } else {
            key = key.toUpperCase();
        }
        String replace = sectionsToReplace.get(key);
        if (replace != null) {
            key = replace;
        }
        ArrayList<TLRPC.TL_contact> arr = sectionsDict.get(key);
        if (arr == null) {
            arr = new ArrayList<>();
            sectionsDict.put(key, arr);
            sortedSectionsArray.add(key);
        }
        arr.add(value);
        if (ids.length() != 0) {
            ids.append(",");
        }
        ids.append(value.user_id);
    }
    UserConfig.contactsHash = Utilities.MD5(ids.toString());
    UserConfig.saveConfig(false);

    Collections.sort(sortedSectionsArray, new Comparator<String>() {
        @Override
        public int compare(String s, String s2) {
            char cv1 = s.charAt(0);
            char cv2 = s2.charAt(0);
            if (cv1 == '#') {
                return 1;
            } else if (cv2 == '#') {
                return -1;
            }
            return s.compareTo(s2);
        }
    });

    usersSectionsDict = sectionsDict;
    sortedUsersSectionsArray = sortedSectionsArray;
}
 
Example 18
Project: incubator-netbeans   File: ToolbarPool.java   View Source Code Vote up 4 votes
final synchronized String[] getConfigurationsNow () {
    ArrayList<String> list = new ArrayList<String>( toolbarConfigs.keySet() );
    Collections.sort( list );
    String[] arr = new String[ list.size() ];
    return list.toArray( arr );
}
 
Example 19
Project: n4js   File: EdgeGuideQueue.java   View Source Code Vote up 4 votes
/** Adds several {@link EdgeGuide}s to this queue */
void addAll(Collection<EdgeGuide> edgeGuides) {
	edgeGuideQueue.addAll(edgeGuides);
	Collections.sort(edgeGuideQueue, this::compareForRemoveFirst);
}
 
Example 20
Project: JavaGraph   File: ReteNetwork.java   View Source Code Vote up 3 votes
/**
 * Returns the collection of edges in the given graph's {@link GGraph#edgeSet()}
 * in the order that is deemed suitable for making RETE.
 *
 * @param c The condition from target of which the edges have to be listed.
 * @return A collection of edges of the given condition.
 */
protected Collection<RuleEdge> getEdgeCollection(Condition c) {
    List<RuleEdge> result = new ArrayList<>(c.getPattern()
        .edgeSet());
    Collections.sort(result, EdgeComparator.instance());
    return result;
}