我想使用Collections的方法排序在IRC channellist中对用户列表进行排序,该列表存储为JList.以下代码在某种程度上实现了这一点:
users是包含用户的JList.
userList是中间数据结构(LinkedList),用于使用Collections对列表进行排序.
// Iterate through the JList and add the users to a LinkedList of strings.
for(Object userName : users.toArray())
userList.add(userName.toString());
// Sort
Collections.sort(userList);
// Clear the user list (removes all users).
users.clear();
// Put the sorted userList in users again.
while(iterator.hasNext() && i < userList.size())
users.addElement(userList(get(i++));
问题是IRC channelList有三个用户组:OP,有声用户和普通用户,它们需要按层次结构组织.当然,排序方法不考虑这一点.此外,sort方法区分小写和大写字母,这是不需要的.
总结的问题:
如何处理对不同用户组的排序;我可以用Collections的排序方法以某种方式指定它,以便它符合层次结构吗?
如何阻止排序方法区分小写和大写字母?
我建议的解决方案
>(效率低!)创建三个列表,并将相应的用户组添加到它们,排序,然后按顺序将它们添加到列表中.
>将用户名转换为小写(不幸).
有什么建议?谢谢.