當前位置: 首頁>>代碼示例>>Java>>正文


Java Comparator類代碼示例

本文整理匯總了Java中net.rim.device.api.util.Comparator的典型用法代碼示例。如果您正苦於以下問題:Java Comparator類的具體用法?Java Comparator怎麽用?Java Comparator使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Comparator類屬於net.rim.device.api.util包,在下文中一共展示了Comparator類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sortedUsers

import net.rim.device.api.util.Comparator; //導入依賴的package包/類
static RichVector sortedUsers(Users users) {
    final RichVector listItems = new RichVector();
    char last = ' ';

    SimpleSortingVector v = new SimpleSortingVector();
    v.setSortComparator(new Comparator() {

        public int compare(Object o1, Object o2) {
            if (o1 instanceof User && o2 instanceof User) {
                return ((User) o1).getFullName().compareTo(((User) o2).getFullName());
            } else {
                return 0;
            }
        }
    });

    for (int i = 0; i < users.size(); ++i) {
        v.addElement(users.getObject(i));
    }

    v.reSort();

    for (int i = 0; i < v.size(); ++i) {
        if (v.elementAt(i) instanceof User) {
            User u = (User) v.elementAt(i);
            char c = u.getFullName().charAt(0);
            if (c != last) {
                listItems.addElement(new SeparatorItem(c + ""));
                last = c;
            }

            listItems.addElement(new UserItem(u));
        }
    }

    return listItems;
}
 
開發者ID:yanex,項目名稱:vika,代碼行數:38,代碼來源:UsersChatsConverter.java

示例2: FriendSelector

import net.rim.device.api.util.Comparator; //導入依賴的package包/類
FriendSelector(JSONObject Current, UiApplication app) {
	int direction = Display.DIRECTION_NORTH;
	Ui.getUiEngineInstance().setAcceptableDirections(direction);
	this.setTitle(" CrapSnap - Select Receiver...");
	Bitmap back = EncodedImage.getEncodedImageResource("Back.jpg")
			.getBitmap();
	this.setBackground(BackgroundFactory.createBitmapBackground(back));
	monApp = app;
	Send.setChangeListener(new FieldChangeListener() {
		public void fieldChanged(Field field, int context) {
			exitbol = false;
			if (CheckBox.getChecked() == true) {
				storybol = true;
			}
			quit();
		}
	});
	
	String[] names;
	try {
		JSONArray friends = Current.getJSONArray("friends");
		names  = new String[friends.length()];
		for (int i = 0; i < friends.length(); i++) {
			JSONObject friend = friends.getJSONObject(i);
			names[i] = friend.getString("name");
		}
		Comparator strComparator = new Comparator() {
		    public int compare(Object o1, Object o2) {
		        return o1.toString().compareTo(o2.toString());
		    }
		};
		Arrays.sort(names, strComparator);
		
		for (int i = 0; i < names.length; i++) {
			ListManager.add(new FriendSelectorObject(names[i]));
			ListManager.add(new SeparatorField());
		}
	} catch (JSONException e) {
		e.printStackTrace();
	}
	
	this.addMenuItem(AddMenuItem);
	this.addMenuItem(CancelMenuItem);
	BtnManager.add(Send);
	MainManager.add(ListManager);
	HorizontalFieldManager StoryManager = new  HorizontalFieldManager();
	CheckBox.setFont(CheckBox.getFont().derive(Font.BOLD, 9, Ui.UNITS_pt));
	StoryManager.add(new LabelField("  "));
	StoryManager.add(CheckBox);
	MainManager.add(StoryManager);
	MainManager.add(BtnManager);
	this.add(MainManager);
}
 
開發者ID:PropheteMath,項目名稱:CrapSnap,代碼行數:54,代碼來源:FriendSelector.java


注:本文中的net.rim.device.api.util.Comparator類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。