Prev: Problems with JTable using fixed rows
Next: is the open sourcing of IntelliJ IDEA getting some love?
From: Wojtek on 2 Nov 2009 19:09 How would you sort timezones? I am trying to sort them according to their offset from UTC. I cannot use a TreeMap because there are many timezones with the same offset, which of course over-writes the previously put timezone. The preferred sort would be offset, then display name. -- Wojtek :-)
From: markspace on 2 Nov 2009 19:22 Wojtek wrote: > How would you sort timezones? > > I am trying to sort them according to their offset from UTC. I cannot > use a TreeMap because there are many timezones with the same offset, > which of course over-writes the previously put timezone. > > The preferred sort would be offset, then display name. > I guess put them all in an array, the use Array.sort( Object[], Comparator<T>) to sort them as you desire.
From: Peter Duniho on 2 Nov 2009 19:22 Wojtek wrote: > How would you sort timezones? > > I am trying to sort them according to their offset from UTC. I cannot > use a TreeMap because there are many timezones with the same offset, > which of course over-writes the previously put timezone. > > The preferred sort would be offset, then display name. Are you asking what the sort order should be? Or how to implement a particular sort order? Pete
From: Patricia Shanahan on 2 Nov 2009 19:38 Wojtek wrote: > How would you sort timezones? > > I am trying to sort them according to their offset from UTC. I cannot > use a TreeMap because there are many timezones with the same offset, > which of course over-writes the previously put timezone. > > The preferred sort would be offset, then display name. > You could use a TreeMap or TreeSet if you constructed it with a Comparator that implements your preferred order. Patricia
From: Wojtek on 2 Nov 2009 19:48 markspace wrote : > Wojtek wrote: >> How would you sort timezones? >> >> I am trying to sort them according to their offset from UTC. I cannot use a >> TreeMap because there are many timezones with the same offset, which of >> course over-writes the previously put timezone. >> >> The preferred sort would be offset, then display name. >> > > > I guess put them all in an array, the use Array.sort( Object[], > Comparator<T>) to sort them as you desire. Yes, I made my own custom Comparator. But I just found out what the problem is. You can retrieve a TimeZone using a variety of names, but that TimeZone only has one display name. For instance, in Canada: Canada/Newfoundland Newfoundland Standard Time Canada/Atlantic Atlantic Standard Time Canada Eastern Eastern Standard Time Canada/Central Central Standard Time * Canada/East-Saskatchewan Central Standard Time * Canada/Saskatchewan Central Standard Time * Canada/Mountain Mountain Standard Time Canada/Pacific Pacific Standard Time * Canada/Yukon Pacific Standard Time * I retrieve them using the left names, but the .getDisplayName() returns the right side. Which throws the sorting out. Ok, I can make this work. Funny how actually _asking_ a question can lead to an answer... -- Wojtek :-)
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: Problems with JTable using fixed rows Next: is the open sourcing of IntelliJ IDEA getting some love? |