Results 1 to 6 of 6
Thread: customize sorting
- 03-27-2010, 12:23 AM #1
Member
- Join Date
- Mar 2010
- Posts
- 8
- Rep Power
- 0
customize sorting
if u wanted to sort string in a ridiculous way such as placing the rule
a - z comes before A - Z
example Aab , aAb
ordering would result in aAb then Aab
obviously you can hard code this. but i'm looking for something more of a shortcut
anything that lets me state or modified small change that will allow me to do this
have read comparable interface, Collection, comparator
looking for general method that allows u to state rules for sorting and it will sort
- 03-27-2010, 02:56 AM #2
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
If you've read about the Comparator interface, then you know that it is the way to specify your "rules for sorting".
-Gary-
- 03-27-2010, 05:17 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Perhaps you could say more precisely what you are trying to do.
gcalvin is quite right about Comparator being the "general method that allows [yo]u to state rules for sorting". Particular implementations of Comparator might be appropriate for the specific sorts you have in mind.
For example the example you gave looks like a lexical sort: where you examine the elements of a pair of sequences in turn and when you first discover a difference, use that to determine the ordering of the sequences. The "rule" for such a Comparator could be as simple as an array specifying the ordering you want individual characters to have. Setting the array would give your Comparator the precise behaviour you wanted.
A more elaborate example of a Comparator whose behaviour is specified by rules (specifically designed for locale sensitive sorting of strings) is RuleBasedCollator. The example you gave would be specified with rules that give the "tertiary" or case distinction, so called because it is typically applied after letter or accent difference. Don't know if this qualifies as a "shortcut" though...
- 03-27-2010, 06:06 AM #4
Senior Member
- Join Date
- Mar 2010
- Posts
- 953
- Rep Power
- 4
Yes, actually pbrockway2's answer was quite helpful, while mine was kind of snide and unhelpful. Sorry about that.
-Gary-
- 03-27-2010, 08:07 AM #5
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,547
- Rep Power
- 11
Actually your reply was what I was going to post some time ago! I mean the OP asked for the general method and that's ... a Comparator. I don't think it's snide to point that out.
I know it's difficult for people to decide how precisely they should describe a problem, but it's a pity there hasn't been a response to my suggestion that a little more detail would be helpful here. This being Java it's a fair bet that the answer will be a Comparator: but how do you implement it? For that it would be good to know more about how it's going to be used.
- 03-28-2010, 04:28 AM #6
Member
- Join Date
- Mar 2010
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
Can we customize the analyser in case of lucene for a more relevant search
By emilylocker in forum LuceneReplies: 2Last Post: 03-27-2010, 09:01 AM -
How to Customize Jfreechart value axis?
By neeraj.singh in forum AWT / SwingReplies: 0Last Post: 02-16-2009, 08:57 AM -
sorting
By jot321 in forum New To JavaReplies: 18Last Post: 10-02-2008, 10:30 AM -
Sorting CachedRowset
By Sayed in forum Advanced JavaReplies: 0Last Post: 07-18-2008, 12:14 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks