• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDictionary.isEmpty
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDictionary.isEmpty


  • Subject: Re: NSDictionary.isEmpty
  • From: Mark Ritchie <email@hidden>
  • Date: Thu, 16 Sep 2010 10:02:20 -0700

Hey!

On 16/Sep/2010, at 7:34 AM, ISHIMOTO Ken wrote:
Hi all, was a nice WOWODC, and really nice Job done Pascal.
Glad to hear that WOWODC was fun... Too bad I missed it.  OTOH, I head for Germany this weekend for my first european vacation so that's where my time off is going this year. ;-)

I have a small Problem about NSDictionary.
NSArray<Movie> movies= Movie.fetchAllMovies(defaultEditingContext());
EOEnterpriseObject eo = movies.objectAtIndex(0);
NSDictionary pDic = EOUtilities.primaryKeyForObject(defaultEditingContext(), eo);
System.err.println("1:" + pDic); -->1:{movieID = 102; }
System.err.println("isEmpty:" + pDic.isEmpty()); -->isEmpty:true
System.err.println("count:" + pDic.count()); -->count:1
Hadn't isEmpty not to be false ?
I tried to reproduce your problem with a non-wonder app and could not.  I was able to reproduce it with a Wonder app.  

Also looking into isEmpty 
public int count() {
return _count;
}
public boolean isEmpty() {
System.err.println("_count : " + _count); -->_count : 0
System.err.println("count() : " + count()); -->count : 1
return _count <= 0;
}
Why is the result of _count and count() different?
Any ideas what's going wrong?
This was the part that really confused me until, I looked at this:
System.err.println("pDic.getClass().getName() = " + pDic.getClass().getName());
and I see:
pDic.getClass().getName() = com.webobjects.eocontrol._EOMutableKnownKeyDictionary

So, primaryKeyForObject() is returning a private subclass.
And that subclass has it's own _count ivar.
However it does not have an implementation of isEmpty() so it's inheriting the one from NSDictionary.
Now, that's the WONDER version of NSDictionary.  And it's using it's own _count ivar. :-(

The fix is to change NSDictionary.java's isEmpty() method to be:
public boolean isEmpty() {
return count() <= 0;
}

For the record, size() should be changed as well! 
And perhaps others, but I don't have unit tests for NSDictionary so I'm not changing anything! ;-)

Good luck!
M.

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: NSDictionary.isEmpty
      • From: Mike Schrag <email@hidden>
    • Re: NSDictionary.isEmpty
      • From: Mike Schrag <email@hidden>
    • Re: NSDictionary.isEmpty
      • From: Chuck Hill <email@hidden>
References: 
 >NSDictionary.isEmpty (From: ISHIMOTO Ken <email@hidden>)

  • Prev by Date: Re: NSDictionary.isEmpty
  • Next by Date: Re: NSDictionary.isEmpty
  • Previous by thread: Re: NSDictionary.isEmpty
  • Next by thread: Re: NSDictionary.isEmpty
  • Index(es):
    • Date
    • Thread