• 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: Nathan Dumar <email@hidden>
  • Date: Wed, 20 Oct 2004 18:12:14 -0400

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

_______________________________________________ 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: EOSortOrdering numerical question
      • From: Chuck Hill <email@hidden>
References: 
 >Re: EOSortOrdering numerical question (From: Chuck Hill <email@hidden>)

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