Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
saravanaboopati
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

How to Sort ListField?

Can anyone tellme how to sort the ListField.

Currently  I am using String collection set like below

 

11-10-2008 India

12-07-2008 Canada

05-10-2008 London

06-11-2008 Paris

 

 

I need to sort the items in the list. 

 


Thanks

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to Sort ListField?

Please see my earlier posts on the RIM collections and rants against databases specifically because

these are available. But, fwiw, I think Arrays with the parallel parameter was my choice ( esp if you can reduce

your dates to longs, this would be a natural):

 

$ grep -il "public.*sort(" *.txt
device.api.collection.util.BigIntVector.txt
device.api.collection.util.BigLongVector.txt
device.api.collection.util.BigVector.txt
device.api.collection.util.SortedReadableList.txt
device.api.util.Arrays.txt
device.api.util.SimpleSortingIntVector.txt
device.api.util.SimpleSortingVector.txt 

 

 

$ grep -il sort *.txt
blackberry.api.blackberrymessenger.Session.txt
blackberry.api.pdap.BlackBerryContactList.txt
device.api.collection.ChainableCollection.txt
device.api.collection.IntKeyProviderAdaptor.txt
device.api.collection.IntRangedActionTarget.txt
device.api.collection.LoadableCollection.txt
device.api.collection.LongKeyProviderAdaptor.txt
device.api.collection.LongRangedActionTarget.txt
device.api.collection.OrderedList.txt
device.api.collection.ReadableIntList.txt
device.api.collection.ReadableList.txt
device.api.collection.ReadableLongList.txt
device.api.collection.ReadableTree.txt
device.api.collection.SortableCollection.txt
device.api.collection.WritableIntMap.txt
device.api.collection.package-frame.txt
device.api.collection.package-summary.txt
device.api.collection.package-tree.txt
device.api.collection.util.BigIntVector.txt
device.api.collection.util.BigLongVector.txt
device.api.collection.util.BigSortedReadableList.txt
device.api.collection.util.BigUnsortedReadableList.txt
device.api.collection.util.BigVector.txt
device.api.collection.util.CollectionListenerManager.txt
device.api.collection.util.IntSortedReadableList.txt
device.api.collection.util.LongHashtableCollection.txt
device.api.collection.util.LongSortedReadableList.txt
device.api.collection.util.ReadableListCombiner.txt
device.api.collection.util.ReadableListUtil.txt
device.api.collection.util.SortedReadableList.txt
device.api.collection.util.SparseList.txt
device.api.collection.util.UnsortedReadableList.txt
device.api.collection.util.package-frame.txt
device.api.collection.util.package-summary.txt
device.api.collection.util.package-tree.txt
device.api.crypto.tls.TLSAlertException.txt
device.api.i18n.Locale.txt
device.api.ldap.LDAPComparator.txt
device.api.ldap.package-summary.txt
device.api.system.PersistentContent.txt
device.api.system.PersistentObject.txt
device.api.ui.MenuItem.txt
device.api.ui.component.ActiveFieldCookie.txt
device.api.ui.component.Menu.txt
device.api.util.Arrays.txt
device.api.util.IntMultiMap.txt
device.api.util.IntVector.txt
device.api.util.ObjectUtilities.txt
device.api.util.SimpleSortingIntVector.txt
device.api.util.SimpleSortingVector.txt
device.api.util.StringMatch.txt
device.api.util.StringUtilities.txt
device.api.util.package-frame.txt
device.api.util.package-summary.txt
device.api.util.package-tree.txt

Please use plain text.
Developer
simon_hain
Posts: 15,805
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to Sort ListField?

i think simplesortingvector is the easiest way, at least i use it.
for very large data structures of simple data arrays will probably be faster.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to Sort ListField?

I just got my test code to work- seems to sort 50 zip codes quite well ( at least they look like they are ordered

by how close they are to me, LOL, haven't done detailed check yet but it is easy to ask the server to return

100's of them). Anyway, I recommended and used sort with the parallel option specifically to remove the

comparator overhead. My presumption is that the long keyed sort is implemented in native code and

doesn't have the overhead of any arbitrary comparator. The pointer swaps are presumably fast.

If you have dates as keys, longs are a natural anyway. I made an index on the fly - Euclid wouldn't approve

but for a quick test I used scaled lat/long difference squared - but if you took more care and can scale

things to longs or ints and retain your key arrays, it may be worth removing the compartor overhead.

 

Please use plain text.
Developer
saravanaboopati
Posts: 147
Registered: ‎09-10-2008
My Device: Not Specified

Re: How to Sort ListField?

I am using Vector,

Is it possible to sort the vector in ascending order based on the Current millisecond ?

Please use plain text.
Developer
simon_hain
Posts: 15,805
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: How to Sort ListField?

even on the threat of repeating myself:
simplesortingvector
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to Sort ListField?

AFAIK, there are two issues: 1) the Comparator vs keys and 2) the array<->Vector conversion.

From what I have seen of list field, it is really neutral and you could write your own either way.

I'm still trying to work out the details for my "database" system but I'm probably going to make

all my gui components use arrays and write a few structs to include a target data array along with

some long index arrays and various names. The attraction of Vector is the arbitrary length that hides all

the fixed length problems. Presumably this is implemented in native code and is fast but I don't think

there are analogues of System.arraycopy etc. For sure, if you have a dynamic list, need a really wierd key computation

per pair, then a vector sort with a comparator function may be the way to go. If you have keys that reduce to longs or

ints, have a static list that is easily represented as an array, I think the array sort with parallel option is probably better.

 

I'm not sure what strategy SQL would use to do a high-dimensional

proximity look up, but I'm going to need things like "closes few points to randomly selected centers" and

thing I can do reasonably well making stuff up as I go along.

 

 

Please use plain text.
Developer
marchywka
Posts: 1,415
Registered: ‎07-30-2008
My Device: Not Specified

Re: How to Sort ListField?

I just ran my first app having converted the listfield and related classes to use arrays, not vectors.

It hadn't occured to me but if you load these from a DOM, you have some idea on an upper bound for how many

things you will load so the size issue is not a big problem. Anyway, from creation from a DOM ( this will change when

I get my SAX handler to work) to sorting and display, the encapsulated array seems like a good way to go.

I'll be creating many indicies on the fly ( I finally got accurate spherical distance metrics for GPS

point array manipulation ) and the collections themselves have zero volatility so this may not be for

everyone but looks good in this case.

 

Given the RIM sorting/binsearch things where a hashtable doesn't quite get it, I think this will be a good approach for a database as all of these things are Persistable.

Implementing an SQL similar query capability doesn't seem to be that difficult.

 

Please use plain text.