SandstoneDB and SortedCollection

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

SandstoneDB and SortedCollection

David Zmick
I have a User that hold a Collection of decisions. Each decision holds a sorted collection of candidates and a sorted collection of objectives. User is a subclass of SDActiveRecord. I have class side code to create and example user with an example decision.

this code fails with "Error: This message is not appropriate for this object"

u := User example.
u save

This is what is at the very top of the debugging output:

SortedCollection(Object)>>error:

SortedCollection(Object)>>shouldNotImplement

SortedCollection>>at:put:

[] in SortedCollection(SequenceableCollection)>>sandstoneDeepCopyVisits:


I am not sure where to go from here. Thank you for any help you might have!

David Zmick
/dz0004455\
Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDB and SortedCollection

Alan Rodas
The problem seams to be the kind of collection you are using.


A SortedCollection holds elements sorted by a given criteria (In the form of a block). 
When you add elements to an instance of SortedCollection, the rule is execute with the new object added, and the contained object to determinate the object position.
Now, the at: put: message in this kind of collections (SortedCollection is a specific class of OrderedCollection), is used to put an object instead of another.
But in a SortedCollection, if you replace an object by other, then you are breaking the sort of the collection.
That's why SortedCollection overrides at:put: as self shouldNotImplement, which raises an exception indicating that you send a message that should not be implemented by that object (Although for me, this reflects a bad design in the hierarchy of Collection)

So the possible solutions are:
-If what you want is sort the elements by a giving criteria, use add: to add the objects to the collection.
-If you want to sort the collection by the order in which you added the elements, use OrderedCollection instead. You should use add: for this to, as at: put: is used to replace an object by another.
-If you have a fixed number of elements to add, you should use an Array, you should set the object of the array using at: put:


Hope that helps.
And, if I misunderstood you problem, please forgive me.

Cheers
--
Alan Rodas Bonjour

Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDB and SortedCollection

Mariano Martinez Peck
In addition the great answer of Alan, I want to add that you should be really careful about using SortedCollections, because adding is much slower than in other collections.
So....what yo can do, depending on your needs, is to use a OrderedCollection or similar, and then, when you need it to be sorted, you use the message #asSortedCollection:

cheers

mariano

On Sat, Dec 11, 2010 at 11:27 PM, Alan Rodas <[hidden email]> wrote:
The problem seams to be the kind of collection you are using.


A SortedCollection holds elements sorted by a given criteria (In the form of a block). 
When you add elements to an instance of SortedCollection, the rule is execute with the new object added, and the contained object to determinate the object position.
Now, the at: put: message in this kind of collections (SortedCollection is a specific class of OrderedCollection), is used to put an object instead of another.
But in a SortedCollection, if you replace an object by other, then you are breaking the sort of the collection.
That's why SortedCollection overrides at:put: as self shouldNotImplement, which raises an exception indicating that you send a message that should not be implemented by that object (Although for me, this reflects a bad design in the hierarchy of Collection)

So the possible solutions are:
-If what you want is sort the elements by a giving criteria, use add: to add the objects to the collection.
-If you want to sort the collection by the order in which you added the elements, use OrderedCollection instead. You should use add: for this to, as at: put: is used to replace an object by another.
-If you have a fixed number of elements to add, you should use an Array, you should set the object of the array using at: put:


Hope that helps.
And, if I misunderstood you problem, please forgive me.

Cheers
--
Alan Rodas Bonjour


Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDB and SortedCollection

Alan Rodas
Sometimes an image is worth a thousand words. So this image I made may help you.

Also, as Mariano points out, remember that you can convert from one collection to another by sending the message #asCollectionName replacing the CollectionName for the collection you want.

So for example to remove all duplicates from a collection, asSet is a simple and pretty way to do it.

Cheers
--
Alan Rodas Bonjour


choosing_the_right_collection.bmp (2M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDB and SortedCollection

Alan Rodas
Sometimes an image is worth a thousand words. So this image I made may help you.

Also, as Mariano points out, remember that you can convert from one collection to another by sending the message #asCollectionName replacing the CollectionName for the collection you want.

So for example to remove all duplicates from a collection, asSet is a simple and pretty way to do it.

Cheers
-- 
Alan Rodas Bonjour

choosing_the_right_collection.bmp (415K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: SandstoneDB and SortedCollection

David Zmick
I am sorry, I should have said also that I am using SandstoneDb to try to save these objects. A SortedCollection is the type of collection I need, but SandstoneDb cannot save it.

Sorry I failed to specify that.

David Zmick
/dz0004455\


On Sat, Dec 11, 2010 at 5:14 PM, Alan Rodas <[hidden email]> wrote:
Sometimes an image is worth a thousand words. So this image I made may help you.

Also, as Mariano points out, remember that you can convert from one collection to another by sending the message #asCollectionName replacing the CollectionName for the collection you want.

So for example to remove all duplicates from a collection, asSet is a simple and pretty way to do it.

Cheers
-- 
Alan Rodas Bonjour