• 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: EOSortOrdering numerical question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: EOSortOrdering numerical question


  • Subject: Re: EOSortOrdering numerical question
  • From: Chuck Hill <email@hidden>
  • Date: Wed, 20 Oct 2004 15:24:19 -0700

Yep, that will work too, as long as it is in memory sorting and not as part of a fetch spec. EOSortOrdering uses KVC for in-memory evaluation so any public method can be used. Check the docs! :-)


Chuck


On Oct 20, 2004, at 3:12 PM, Nathan Dumar wrote:

Just last night I encountered a similar response in my code.

What I had thought of doing (and had not yet had a chance to try) was adding to my class definition a method that would return the value as a number instead of a string. Then I would sort by the number returned.

Currently there is only this:

    public String idNum() {
        return (String)storedValueForKey("idNum");
    }

What I intend to add is this:

	public Number idNumber() {
		return new Integer.parseInt((String)storedValueForKey("idNum"));
	}

But then, can EOSortOrdering sort by this, or can it only sort on a property specifically listed in the model? If it can't, can I somehow add this derived value to the model without altering the database, yet in a way that will be accessible to EOSortOrdering? (I'd really like to avoid changing the model this late in the game, I don't know how to accomplish #2 with any degree of efficiency, and #3 is still beyond my knowledge.)

Thank you for any responses.

Take care,
Nathan



On Oct 20, 2004, at 3:52 PM, Chuck Hill wrote:

At 03:38 PM 20/10/2004 -0400, james o wrote:
EOSortOrdering order = new EOSortOrdering
("displayTime",EOSortOrdering.CompareAscending); //or
CompareCaseIncensitiveAscending

how do i numerically sort numbers in WO? if i use the above code for
"displayTime" i get the following output?

1
16
2
3
33
4
5
6
61
7

i should see this:

No. You _should_ see exactly what you do see. What you _want_ to see is:
1
2
3
4
5
6
7
16
33
66

There is a crucial difference there! You are sorting on a string field and
they collate as characters, not as integers. You can do one of the following:


1. Use a numeric column instead of a String.
2. Left pad the string with spaces so that the rightmost digits line up
3. Create a new comparator that does what you want.


Chuck


--
Practical WebObjects - a book for intermediate WebObjects developers who want to increase their overall knowledge of WebObjects, or those who are trying to solve specific application development problems.
http://www.global-village.net/products/practical_webobjects




_______________________________________________
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


References: 
 >Re: EOSortOrdering numerical question (From: Chuck Hill <email@hidden>)
 >Re: EOSortOrdering numerical question (From: Nathan Dumar <email@hidden>)

  • Prev by Date: Re: EOSortOrdering numerical question
  • Next by Date: EOGenerator templates
  • Previous by thread: Re: EOSortOrdering numerical question
  • Next by thread: EOGenerator templates
  • Index(es):
    • Date
    • Thread