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
Posts: 112
Registered: ‎09-23-2009
My Device: Not Specified

Re: SimpleSortingVector extended from Vector, but it is not Persistable

I cannot leave SimpleSortingVector, because I need the object to be shown alphabetically sorted. I finally doing something like this:

 

 

public void saveContacts(SimpleSortingVector contacts) {
		synchronized (store) {			
			try {
				data = new Vector();
				int len = contacts.size();
				int i = 0;
				
				while (i < len) {
					data.addElement((MyContact)contacts.elementAt(i));
					i++;
				}
				
				store.setContents(contacts);
				store.commit();
			} catch (NonPersistableObjectException ex) {
				
			}
		}		
	}

 

 

I used this method after adding, modify or deleting data in contacts, which is SimpleSortingVector. It works. But I'm afraid it will takes time when we have a large number of contacts.

 

Is there any better solution?

 

 

Developer
Posts: 384
Registered: ‎08-12-2008
My Device: 8700

Re: SimpleSortingVector extended from Vector, but it is not Persistable

Hi ,

 

I think Peter_Strange explaination has already told you the trick one....

 

since SimpleSortedVector will hold comparable object, and this object is not persistale.

 

you need to created a comparable and persistable instance to replace default one.

 

Cheers.

 

New Developer
Posts: 17
Registered: ‎01-01-2009
My Device: Not Specified

Re: SimpleSortingVector extended from Vector, but it is not Persistable

I had the same problem: you don't want to write your own sort but you don't want to copy your data element by element to a new Vector.

 

I've noticed in the JavaDoc for Vector that there is the following protected field:  Object[] elementData.  This is the internal array buffer for the Vector.

 

Perhaps you can extend SimpleSortingVector and add public methods to access the elementData array buffer.  Then you can persist only the array buffer and not the Vector object.  When reading from the store just create one of your custom vectors and set the elementData field to the object array retrieved from the store.

Highlighted
Contributor
Posts: 15
Registered: ‎09-06-2011
My Device: none
My Carrier: none

Re: SimpleSortingVector extended from Vector, but it is not Persistable

[ Edited ]