From: Mike Schilling on
Lew wrote:
> Feed a
> man a meal and you feed him for an hour; send him to the diner and
> you feed him for a lifetime.

Build a man a fire, and he's warm for a night, set him on fire, and he's
warm his whole life.

>> I do use a TreeMap --
>> "final Map<String, String> map = new
>> TreeMap<String, String>();",
>> but the order is not getting preserved when I call "map.entrySet".

> And you didn't even provide an SSCCE! What is wrong with you?

Since he wanted to sort by value, not key, he's correct -- the entry set
won't be sorted the way he wanted.


From: Lew on
Mike Schilling wrote:
> Lew wrote:
>> Feed a
>> man a meal and you feed him for an hour; send him to the diner and
>> you feed him for a lifetime.
>
> Build a man a fire, and he's warm for a night, set him on fire, and he's
> warm his whole life.
>
>>> I do use a TreeMap --
>>> "final Map<String, String> map = new
>>> TreeMap<String, String>();",
>>> but the order is not getting preserved when I call "map.entrySet".
>
>> And you didn't even provide an SSCCE! What is wrong with you?
>
> Since he wanted to sort by value, not key, he's correct -- the entry set
> won't be sorted the way he wanted.

Unless, of course, he uses a custom Comparator that does sort the way he wants.

--
Lew
From: Mike Schilling on
Lew wrote:
> Mike Schilling wrote:
>> Lew wrote:
>>> Feed a
>>> man a meal and you feed him for an hour; send him to the diner and
>>> you feed him for a lifetime.
>>
>> Build a man a fire, and he's warm for a night, set him on fire, and
>> he's warm his whole life.
>>
>>>> I do use a TreeMap --
>>>> "final Map<String, String> map = new
>>>> TreeMap<String, String>();",
>>>> but the order is not getting preserved when I call "map.entrySet".
>>
>>> And you didn't even provide an SSCCE! What is wrong with you?
>>
>> Since he wanted to sort by value, not key, he's correct -- the entry
>> set won't be sorted the way he wanted.
>
> Unless, of course, he uses a custom Comparator that does sort the way
> he wants.

Not Map.entrySet(); that always sorts by the map's keys. (You can *copy*
the result of entrySet() and sort that copy however you like, of course.)


From: Tom Anderson on
On Fri, 23 Apr 2010, Lew wrote:

> laredotornado wrote:
>>>> Omg, Tom, can I buy you a beer or something? That solution is exactly
>>>> what I was looking for.
>
> Lew wrote:
>>> Do I get a beer, too, then?
>
> Eric Sosman wrote:
>> Queue<Beer> wall = ...;
>> assert wall.size() == 99;
>
> I recommend "Loose Cannon" beer from Clipper City Beer in Baltimore,
> Maryland, USA. <www.clippercitybeer.com> and not merely because
> "lewscanon.com" was a pun on that expression.
>
> Loose Cannon is very, very hoppy to the point of tasting like a citrus
> beverage. That took some getting used to, but by the second glass it
> was a favorite.

I think this is an American thing. In the fusty old Old World, we tend to
consider such things unbalanced. But over there, you guys love taking one
particular knob and turning it up to 11.

I mostly drink London Pride, because it's local, easily available, and
alright.

I have a bottle of this in my cupboard, because it's local to where i grew
up, should be alright (their other beers are good), and is carbon-neutral:

http://about.adnams.co.uk/post/News/2008/08/East-Green.aspx

Which i thought was an enterprising marketing angle.

tom

--
DO NOT WANT!
From: Tom Anderson on
On Fri, 23 Apr 2010, Lew wrote:

> Mind you, I have no objection to providing code to help the OP.
>
> I do have a real objection to one ignoring advice that lacks every last
> freaking detail of the code and prevents the querent from having to do
> any work whatsoever. The OP pretended that your answer came out of
> nowhere, and that no one else had suggested the same thing, as if the
> lack of code made the other answer(s) any less valuable.

Yes, that was an unacceptable snub.

> If they really didn't see the value of being told, "Custom Comparator.
> Load the entries into a SortedSet with that Comparator." then they
> should have *asked* about it. Then when you gave the code for that (I
> assume that's what they were really answering, not the post to which
> they actually replied) they pretended like you were the first to even
> suggest such a thing in answer to their question.

You may be right that laredotornado is just too lazy to do his own
programming.

I have a terrible vice of optimism. I think that for someone who doesn't
know about the collections API, and hasn't built up a general
understanding of the 'Tao of Java', if you will, that will let them grok
it from reading the docs, advice such as you gave, correct though it is,
might as well be in Greek. In that case, a picture is worth a thousand
words, and in programming a picture is a snippet.

Imagine if you were learning to maintain tractors, and you asked on a
tractor newsgroup about how to fix a noisy second gear, and someone said
"Tappet rod shim. Run the treadle via a coupling cone using that shim.",
would you be confident in going off to do that? Would you even know what a
sensible question to ask in response was? On the other hand, if someone
gave you detailed instructions, or ideally showed you how to do it, you'd
be able to do it, and if you were a smart person, you'd be looking at that
and figuring out how it works, and so learning how to do something similar
in future. I think there's enormous educational value in examples.

> laredotornado, you are not going to make real progress in computer
> programming until you grasp how to take a topic suggestion into code.

Yes. The theory advanced in the preceding paragraph hinges on "if you were
a smart person", and that's what's not clear in the OP's case. If this guy
is still around in two years asking the same entry-level questions, then
the theory will have been disproven, and i ought to start leaving him to
stew.

> There are wise people out there, for example Roedy Green, who will give
> you a signpost to the restaurant instead of a sandwich. Feed a man a
> meal and you feed him for an hour; send him to the diner and you feed
> him for a lifetime.

Send him to a diner in Bulgaria and he'll still starve, because he doesn't
know what to order.

tom

--
DO NOT WANT!