Hello you smart people out there. I need your help (again).
I have an NSArray that contains arrays of objects. Among the object's properties, one is called "name".
Each of the nested Arrays contains objects with the same 'name' (but different values for other properties). Simplified, it looks like this:
#[
#[myObject.name=#"c",myObject.name=#"c",myObject.name=#"c"],
#[myObject.name=#"a",myObject.name=#"a"],
#[myObject.name=#"b",myObject.name=#"b",myObject.name=#"b",myObject.name=#"b",myObject.name=#"b"]
]
Now, I want to sort my array, in such a way, that the nested arrays are in alphabetical order, like this:
#[
#[myObject.name=#"a",myObject.name=#"a"],
#[myObject.name=#"b",myObject.name=#"b",myObject.name=#"b",myObject.name=#"b",myObject.name=#"b"],
#[myObject.name=#"c",myObject.name=#"c",myObject.name=#"c"]
]
Does any of you have a hint on how to approach this? The nested arrays should not be sorted or rearranged internally.
Thanks for your advice
Related
In Acceleo I have an OrderedSet of objects, where each object has a string as attribute.
I want to get a container(e.g. OrderedSet) of those strings, where each string is unique.
First, I collect all the strings into an collection ->collect(attribute). Then I convert to an Ordered Set ->asOrderedSet(). This will remove all duplicates.
A String is an (E)DataType rather than an (E)Class instance consequently it has no (e)container. You could do a total model search for all String-typed attributes and check their values - very expensive. Much better to revisit the OrderedSet construction so that the 'container' knowledge is not discarded requiring rediscovery.
My data looks like this:
[
{"name":"Jimmy H.","title":"Mr."},
{"name": "Janice H."}
]
So, if field does not have value, then also the field name is missing. What's the proper term for that?
EDIT:
Basically I'm looking for a term that differentiates structure above from structure where every field name (even without value) is guaranteed to exist in every record.
The one in the example is a combination of well known structures, it seems indeed an array of maps. At least, in JavaScript it would be an array of objects, but those objects behave like maps the way they are used in the example.
I mean,
Collections.sort(myBuilder.getMyRepeatedItem(), myComparator);
Can I assume items will then be in the sorted order after calling build() later, or it is better to sort in a separate array and use clearMyRepeatedItem() and then addAllMyRepeatedItem(...) ?
Seems that not even possible:
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableList.sort(Collections.java:1331)
at java.util.Collections.sort(Collections.java:175)
Sorry, I initially assumed may work but may not be recommended as something undocumented. However while you can add elements to the Builder, the list that the Builder returns is not a modifyable list.
In an application I'm making in Ruby, I store objects in a MongoDB database using MongoMapper.
Among other things, I need to store an array that is a property of a document:
{String => { [Strings] }
Or to put it in a more Javascript style notation:
{
"fooArray" [
"one",
"two",
"three"
]
}
Is the order of this array guaranteed to be preserved, or must I do something else to guarantee order? After a few tests it seems to work, but I need to be sure.
Array is an ordered data structure. So yes, the order should be preserved. Your tests confirm this. If the order wasn't preserved, this would be a major bug in MongoMapper.
Yes, the order of the items inside an array will stay the same.
You can read more here: http://ruby-doc.org/core-2.0/Array.html
Arrays are ordered, integer-indexed collections of any object.
I have two NSArrays of NSRects (stored using NSStringFromRect(NSRect)). Is there a quick way to check and see if the items in the array are equal or will I have to do a loop? So item 1 in array 1 = item 1 in array 2, etc. etc.
Thanks
If you check the NSArray Reference, you'll find a handy -isEqualToArray: method that should do just what you want
From the documentation for -[NSArray isEqualToArray:]:
Compares the receiving array to another array. Two arrays have equal contents if they each hold the same number of objects and objects at a given index in each array satisfy the isEqual: test.
This is exactly what you are looking for.