当前位置: 首页>>代码示例>>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;未经允许,请勿转载。