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
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel
Accepted Solution

Vectors, and Vectors and Storage

Hi, I am new to the idea of Persistent Storage. But I have managed to simply store a String...that's all

I am going to try implement Vectors with persistent storage.

I do however want the following questions answered.

 

  1. Can a Vector store other things besides elementary data types? For example can a vector store Editfields or LabelFields along with there contents?
  2. A Vector stores objects; so does that mean that I can create a custom object, and then make a vector out of more than one of my custom object? How do you make a custom object? 
  3. What is casting? What is its purpose?

 

 

_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vectors, and Vectors and Storage

1. Yes, but if you want to persist a vector, all the Objects contained in the Vector must be Persistable.  EditField and LabelField are not, so you can't persist these.

2. Yes you can create a Custom Object.  You do it every time you extend another Object.  This is standard Java. 

3. Casting the process of making on Object look like another one.

 

With the exception of (1), these questions are not BlackBerry questions, they are java questions.  I suggest you search else where for information on these java constructs.  There are some great tutorials around and of course you could always buy a Java book. 

Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Vectors, and Vectors and Storage

Thanks for the response.
And...

Relating to question 1, I would like to ask the following questions.

1. If I have a class that implements Persistable, and it contains a Vector with custom objects. Do I still need to make the objects in the Vector persistable?

2. If an EditField as it is, is not persistable, can I create an object that extends EditField that also implements Persistable?
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vectors, and Vectors and Storage

1. "Do I still need to make the objects in the Vector persistable?"

Yes

 

2. "can I create an object that extends EditField that also implements Persistable?"

No, if you have to have an EditField then you will need a set process to extract the required details into a Persistable class and a reverse process to recreate the EditField. 

Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Vectors, and Vectors and Storage

Relating to question one.. Really? Even though the Vector is in a Persistable class?..Whoa..ok

Thank you so much so far, you have increased my knowledge.

I do have another question.

If I have to make all the objects in the Vector Persistable, how will I save them and access them. Sorry what I mean to say is that I have no clue how to implement this.

For starters I have a class that implements Persistable and it has a Vector that I want to fill with Strings. Any suggestions on how to implement it please, so that it is Persistable?
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vectors, and Vectors and Storage

To me it makes sense that the Objects in the Vector have to be Persistable.  After all the Vector is just a collection of Objects. 

 

Regarding how to use it, a Vector is really like an Array, but one that is possible to extend and to insert Objects into.  So you can do things like

 

Vector myVector = new Vector();

myVector.addElement("Test");

myVector.addElement("Test 2");

myVector.addElement("Another String");

 

Now if do

String xxx = (String) myVector.elementAt(2);

then xxx will reference the String "Another String".

 

You can use Vector methods to specifically add certain entries and specific 'indexes' too. 

 

But if you are looking at this sort of thing to manage a Persistent collection, I would encourage you to review Hahtable, or intHashtable.

 

You should find information online that explains how to use a Hashtable and more on Vectors too. 

Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Vectors, and Vectors and Storage

Thanks! My question though is, will the Vector of Strings be Persistable if it is in a class that implements Persistent?
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Vectors, and Vectors and Storage

[ Edited ]

If you look at the doc for PersistentObject, you will find a list of the Objects that are implicitly Persistable - this includes String and Vector.  If you look at the Persistable doc, you will find a list of other Objects that are persistable.  If you wish to create a Persistable Object, you can create it using or extending one of these, making sure that all the classes that are added to the Object (or collection) also implement Persistable, directly or implicitly.

 

Note that you must explicitly define a class as Persistable.  If you just say

 

class MyString extends String {

}

 

then MyString is not Persistable. 

 

Hopefully now I have understood and answered all your questions!  Sorry about not doing that at the beginning. 

Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Vectors, and Vectors and Storage

Hahaha...yes I am satisfied..Thank you!
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.
Highlighted
Trusted Contributor
Posts: 204
Registered: ‎07-03-2011
My Device: Torch
My Carrier: Digicel

Re: Vectors, and Vectors and Storage

By the way, is it possible to equate Vectors?

Vector v1=new Vector();
v1.addElement(a);
v1.addElement(b);
v1.addelement(c);

Vector v2=new Vector();

v2=v1;

?
_______________________________________________________
Never be close-fisted with the knowledge you've received. For if others were the same to you, you would not be painted as the person you are; the flowing definition of you, would be non existent.

You would be meaningless.