In Theory, there is no difference between theory and practice.<br />In Practice, there is no relationship between theory and practice.
Originally posted by Alan Moore:
Grant, converting digit sequences to numbers is the obvious approach, but it has a major flaw: what if the number is too large to be represented as an int or long? The character-by-character approach also seems cleaner and more efficient to me.
Well, your code is certainly thorough! I think it's overkill for the OP's requirements (which, admittedly, are possibly not complete). If your digit-strings are more than 20 digits, you'll need more than a long - although if I really wanted to worry about that, I'd probably just convert to using BigInteger for it, rather than rolling my own.
But I think the real issue underlying this discussion is one of flawed design. Anytime I see code that wants to do more than one thing at a time, it suggests to me that I haven't stated the problem correctly.
Just my US$0.02,
Grant
[Edited because there is a difference between "you'll need a long" and "you'll need more than a long", and I are a idiot.]
[ April 14, 2006: Message edited by: Grant Gainey ]
In Theory, there is no difference between theory and practice.<br />In Practice, there is no relationship between theory and practice.
Originally posted by Alan Moore:
I did say I wrote it for my own use. And I'm sure the OP's (stated) requirements are incomplete; he didn't even say whether letters should be sorted case-sensitively or not. But this class should at least give him a good start on solving his problem.
Originally posted by Alan Moore:
I don't see this as trying to do more than one thing at a time; it's just another way of sorting strings. Unless you're saying that, instead of using strings, the OP should create a custom data object with a string field and a numeric field. If that's an option, I agree it would be a better way to go.
In Theory, there is no difference between theory and practice.<br />In Practice, there is no relationship between theory and practice.
Originally posted by Grant Gainey:
And I do think your Comparator above is a very nifty thing. May need to add it to my toolbox, if you don't mind.
Consider Paul's rocket mass heater. |