NSMutableDictionary Enumeration - nsenumerator

I used both object and key NSEnumerators to look through a dictionary and I noticed that it changes the order in which it enumerates through the dictionary. I find that rather annoying. Is there a way to get the NSEnumerator object or key, to look through in the order in which I created it? Formatting it into an NSArray isn't an option.

a dictionary is inherently not an ordered set so it doesn't matter in which order you store your data in it. you could use an nsarray and store your keys in it and then invoke your objects from the dictionary in the order stored in that array.

found via this thread last year, you'll find a good OrderedDictionary class here

Related

Avoiding database queries in Anylogic

I would like to avoid costly repeated data base queries in Anylogic. I have seen the following thread in Stack Overflow What is the fastest way to look up continuous data on Anylogic (Java, SQL) where a simple three step answer is provided but I'm not sure what the second point of the three actually means:
Save all rows as instances of that class at model start-up into a map - you can use Origin/Destination as the key (use Anylogic's Pair object) and the class instance as the value
I have created a class that takes as inputs the information from each column of my database. I would now like to save each row as an instance of that class - is there an easy way to do this? I may be missing something simple as I'm new to Anylogic.
I'm also unsure of how to create a mapping, if anyone could add more detail to point 2 above I'd be very grateful!
this is effectively the best advice, you created the class, which is a great step, but now, one element of that class, will be used as the key... for example the name... for instance if your class has firstName as one variable and lastName as another variable, you will use a string that is the concatenation of firstName and lastName as your key. Of course any key is fine, assuming that it is unique for all your table. Also an integer as an id is ok too.
create a collection of type LinkedHashMap
Create a class (you did that)
Your collection will take as the key a String (first + last name) and as the value of the elment the class...
now, when you read your database you will have something like this:
for(Tuple t : yourQueryResults){
YourClass yc=new YourClass(t.get(db.var1),t.get(db.var2));
String totalName=t.get(db.first_name)+"_"+t.get(db.last_name);
yourCollection.put(totalName,yc);
}
Now every time you want to find someone with the a name, for example "John Doe", instead of making a query, you will do
yourCollection.get("John_Doe").theVarYouWant;
if you use an id instead of the name, you can set an int as the key, and then you will just do yourCollection.get(theId).theVarYouWant

Django - get queryset with id's not in set of values

According to doc -
https://docs.djangoproject.com/en/dev/topics/db/queries/#the-pk-lookup-shortcut -
I can get set of objects with specified in list ids. Is there any short way to get another set of objects, with id's not in the specified list. Blog.objects.filter(pk__not_in=[1,4,7]) - did not work for me. PS: is there any annotation of possible expresissions for filtering querysets, of making own short expressions?
Use the exclude method.
Blog.objects.exclude(pk__in=[1,4,7])
At first your query is wrong. You should write your query Blog.objects.filter(pk__in=[1,4,7]). And if you want to use not then you should read here

Correct way to retrieve a single object from Realm database

I am absolutely loving Realm (0.92) in combination with Swift but have a question about reading an object from the database. My goal is to retrieve a single object with a known, unique ID (which also happens to be the primary key.
All the documentation appears to be oriented around queries for multiple objects which are then filtered. In this case I know the object ID and, since it is known to be unique, would like to retrieve it directly.
My current approach is as follows:
Realm().objects(Book).filter("id == %#", prevBook.nextID).first
This seems heavy-handed. Documentation from prior versions suggest that there is a more direct way but I can't seem to locate it in the documentation.
The problem with my current approach is that it is crashing with an exception on the following function:
public func filter(predicateFormat: String, _ args: CVarArgType...) -> Results<T>
The exception is mysteriously reported as:
EXC_BAD_ACCESS (code=1, address=0xedf)
Any suggestions are very welcome.
Anticipating one line of questioning: I have confirmed that replacing prevBook.nextID with a known, good ID does not solve the problem
object(ofType:forPrimaryKey:) is what you're looking for: Realm().object(ofType: Book.self, forPrimaryKey: prevBook.nextId). There's no simpler way than filter().first if you need to search for the object by something other than the primary key.

Order Coredata Sub-entity

My entities called Score contains entites called Messages. It's a one-to-many relationship, we can have many Messages for a single Score.
When I'm fetching my Score, i can access my Messages objects in an NSOrderedSet, because I ticked Ordered in the .xcdatamodel file.
They're just not ordered properly and I'd like to know if that can be fixed.
I'm displaying them in a tableview from an array built like this
//_score exists and is set properly.
someArray = array-alloc-init;
for (Message *msg in _score.messages)
{
//Do my stuff because objects need remodeling in that view
//
[someArray addObject:msg];
}
[tableview reloadData]; //the tableview uses someArray
everything works like a charm except it's just not in the right order.
Where (if possible) can I tell the model to order by "CreationDate" for example. The "Ordered" tickbox seems to order it in a way that doesn't work.
The ordered set is in whatever order you originally populated the relationship (either in one go or as items were added to the end of the relationship).
So, if you can guarantee that you can add them in order or you write some code to insert into the relationship in the correct place then you can continue with your current code.
Alternatively, you can create a fetch request that uses the relationship 'backwards' to find Messages for a specified Score and sorts them appropriately. The main benefit here is that you can decide to change the sort order if you want to on-the-fly, you can specify multiple sort orderings (allowing the user to change if they want) and you can explicitly set the fetch batch size (which can help if you have lots of messages).

XWiki - Database (How XWO_ID is created ?)

I know how XWD_ID (xwikidoc) is created, but I don't know how XWO_ID (xwikiobject) is
created. I know that this is the same ID for tables xwikidates, xwikiintegers, xwikilargestrings,... But I don't know how it is created.
Can you help me ?
Thanks,
Caroline.
All IDs are assigned manually so far, and they are obtained from the entity's getId() method. For objects, this is BaseElement.getId() which is the new method of computing IDs (introduced in 4.0). Up to 3.5, it used to be BaseCollection.getId() which is actually the hashCode of the object, which is the hashcode of the string obtained by concatenating the document name, the XClass name, and the object number.

Resources