2010-07-19 7 views
1

나는 오래 지속되는 객체에서 많은 날짜를 저장하는 응용 프로그램을 만들고 있습니다.영구 데이터를 정렬하는 방법은 무엇입니까?

이러한 긴 값의 목록을 오름차순으로 만들고 싶습니다. 새로운 값이 오면 지속성 내에서 목록이 정렬됩니다.

나를 도와 줄 사람이 있습니까?

답변

4

net.rim.device.api.util.SimpleSortingVector를 사용하여 데이터를 저장하십시오.

2

oxigen이 말했듯이, SimpleSortingVector를 사용합니다 ... 처음 보면 간단하지 않습니다!

정렬 벡터로 전달할 비교기 클래스를 만들어야합니다. 예보기 :

// Your hashtable with key value pairs 
Hashtable data = getMyHashTableWithSomeDataInIt(); 

// Your sorting vector 
SimpleSortingVector sorted = new SimpleSortingVector(); 

// Iterate through you hashtable and add the keys to the sorting vector 
for (Enumeration e = data.keys(); e.hasMoreElements();) 
{ 
    String key = (String) e.nextElement(); 
    sorted.addElement(key); 
} 

// Pass in the comparator and sort the keys 
sorted.setSortComparator(new MyComparator()); 
sorted.reSort(); 

// Iterate through your sorted vector 
for (Enumeration e = sorted.elements(); e.hasMoreElements();) 
{ 
    String key = (String) e.nextElement(); 
    Object sortedItem = (Object) data.get(key); 

    // Do whatever you have to with the sortedItem 
} 

// Sort compartor for sorting strings 
class MyComparator implements Comparator { 
    public int compare(Object k1, Object k2) { 
     return ((((String) k1).compareTo((String) k2))); 
    } 
} 
관련 문제