Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #9917 > unrolled thread
| Started by | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| First post | 2011-11-13 09:17 -0800 |
| Last post | 2011-11-21 04:03 -0800 |
| Articles | 13 on this page of 53 — 22 participants |
Back to article view | Back to comp.lang.java.programmer
toward null-safe cookie cutter Comparators Roedy Green <see_website@mindprod.com.invalid> - 2011-11-13 09:17 -0800
Re: toward null-safe cookie cutter Comparators Tom Anderson <twic@urchin.earth.li> - 2011-11-13 17:59 +0000
Re: toward null-safe cookie cutter Comparators Roedy Green <see_website@mindprod.com.invalid> - 2011-11-14 10:28 -0800
Re: toward null-safe cookie cutter Comparators Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-14 10:55 -0800
Re: toward null-safe cookie cutter Comparators Roedy Green <see_website@mindprod.com.invalid> - 2011-11-15 09:04 -0800
Re: toward null-safe cookie cutter Comparators kensi <kensi_kensington@zoonoses.de> - 2011-11-16 12:50 -0500
Re: toward null-safe cookie cutter Comparators Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-16 13:47 -0800
Re: toward null-safe cookie cutter Comparators Gene Wirchenko <genew@ocis.net> - 2011-11-16 16:09 -0800
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-16 17:02 -0800
Re: toward null-safe cookie cutter Comparators Gene Wirchenko <genew@ocis.net> - 2011-11-16 17:31 -0800
Re: toward null-safe cookie cutter Comparators Martin Gregorie <martin@address-in-sig.invalid> - 2011-11-17 22:51 +0000
Re: toward null-safe cookie cutter Comparators Paul Cager <paul.cager@googlemail.com> - 2011-11-17 02:43 -0800
Re: toward null-safe cookie cutter Comparators Tim Slattery <Slattery_T@bls.gov> - 2011-11-17 08:57 -0500
Re: toward null-safe cookie cutter Comparators Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-18 16:05 -0800
Re: toward null-safe cookie cutter Comparators kensi <kensi_kensington@zoonoses.de> - 2011-11-17 21:21 -0500
Re: toward null-safe cookie cutter Comparators Wanja Gayk <brixomatic@yahoo.com> - 2011-11-20 13:29 +0100
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-20 08:23 -0800
Re: toward null-safe cookie cutter Comparators Brixomatic <wanja.gayk@googlemail.com> - 2011-11-21 04:39 -0800
Re: toward null-safe cookie cutter Comparators Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-21 11:25 -0800
Re: toward null-safe cookie cutter Comparators Arne Vajhøj <arne@vajhoej.dk> - 2011-11-25 21:44 -0500
Re: toward null-safe cookie cutter Comparators Daniel Pitts <newsgroup.nospam@virtualinfinity.net> - 2011-11-26 15:34 -0800
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-21 14:20 -0800
Re: toward null-safe cookie cutter Comparators Gene Wirchenko <genew@ocis.net> - 2011-11-21 19:22 -0800
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-21 22:45 -0800
Re: toward null-safe cookie cutter Comparators Wanja Gayk <brixomatic@yahoo.com> - 2011-12-10 12:15 +0100
Re: toward null-safe cookie cutter Comparators ilAn <idonot@wantspam.net> - 2011-12-10 19:47 +0200
Re: toward null-safe cookie cutter Comparators Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-12-10 14:57 -0400
Re: toward null-safe cookie cutter Comparators ilAn <nosuch@email.com> - 2011-12-11 10:46 +0200
Re: toward null-safe cookie cutter Comparators Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-12-12 07:42 -0400
Re: toward null-safe cookie cutter Comparators ilAn <nosuch@email.com> - 2011-12-12 16:06 +0200
Re: toward null-safe cookie cutter Comparators "Qu0ll" <Qu0llSixFour@gmail.com> - 2011-12-13 02:01 +1100
Re: toward null-safe cookie cutter Comparators Wanja Gayk <brixomatic@yahoo.com> - 2011-12-17 12:30 +0100
Re: toward null-safe cookie cutter Comparators Wanja Gayk <brixomatic@yahoo.com> - 2011-12-17 12:30 +0100
Re: toward null-safe cookie cutter Comparators Roedy Green <see_website@mindprod.com.invalid> - 2011-11-22 19:47 -0800
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-16 14:02 -0800
Re: toward null-safe cookie cutter Comparators Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-17 08:42 +0000
Re: toward null-safe cookie cutter Comparators Nigel Wade <nmw-news@ion.le.ac.uk> - 2011-11-17 15:09 +0000
Re: toward null-safe cookie cutter Comparators kensi <kensi_kensington@zoonoses.de> - 2011-11-17 21:22 -0500
Re: toward null-safe cookie cutter Comparators spk <jhic@speak.invalid> - 2011-11-17 13:40 -0400
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-17 09:56 -0800
Re: toward null-safe cookie cutter Comparators spk <jhic@speak.invalid> - 2011-11-17 14:00 -0400
Re: toward null-safe cookie cutter Comparators Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> - 2011-11-17 19:23 +0000
Re: toward null-safe cookie cutter Comparators spk <jhic@speak.invalid> - 2011-11-17 16:35 -0400
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-17 13:50 -0800
Re: toward null-safe cookie cutter Comparators spk <jhic@speak.invalid> - 2011-11-17 18:48 -0400
Re: toward null-safe cookie cutter Comparators thoolen <tholen01@gmail.com> - 2011-11-17 18:33 -0800
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-17 13:48 -0800
Re: toward null-safe cookie cutter Comparators "Joe Attardi" <jattard1@gmail.com> - 2011-11-18 12:20 +0100
Re: toward null-safe cookie cutter Comparators thoolen <th00len@th0lenbot.thorium> - 2011-11-18 15:21 -0500
Re: toward null-safe cookie cutter Comparators thoolen <tholen01@gmail.com> - 2011-11-17 18:31 -0800
Re: toward null-safe cookie cutter Comparators Wanja Gayk <brixomatic@yahoo.com> - 2011-11-20 13:14 +0100
Re: toward null-safe cookie cutter Comparators Lew <lewbloch@gmail.com> - 2011-11-20 08:29 -0800
Re: toward null-safe cookie cutter Comparators Brixomatic <wanja.gayk@googlemail.com> - 2011-11-21 04:03 -0800
Page 3 of 3 — ← Prev page 1 2 [3]
| From | spk <jhic@speak.invalid> |
|---|---|
| Date | 2011-11-17 14:00 -0400 |
| Message-ID | <4ec54bae$0$22559$c3e8da3$e3f2c276@news.astraweb.com> |
| In reply to | #10009 |
Lew <lewbloch@gmail.com>, wrote: >Daniel Pitts is a well-known and respected contributor to the Java newsgroups. and?
[toc] | [prev] | [next] | [standalone]
| From | Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at> |
|---|---|
| Date | 2011-11-17 19:23 +0000 |
| Message-ID | <slrnjcanp7.fvg.avl@gamma.logic.tuwien.ac.at> |
| In reply to | #10010 |
spk <jhic@speak.invalid> wrote: > Lew <lewbloch@gmail.com>, wrote: >> Daniel Pitts is a well-known and respected contributor to the Java newsgroups. > and? to Lew: spk *didn't* respond to a posting of Daniel Pitts. As you're filtering away a lot, you should get into the habit of NOT-assuming that a followup was always to the preceding article in your newsclient's display.
[toc] | [prev] | [next] | [standalone]
| From | spk <jhic@speak.invalid> |
|---|---|
| Date | 2011-11-17 16:35 -0400 |
| Message-ID | <4ec57002$0$1507$c3e8da3$efbdef2c@news.astraweb.com> |
| In reply to | #10016 |
Andreas Leitgeb <avl@gamma.logic.tuwien.ac.at>, wrote: >spk <jhic@speak.invalid> wrote: >> Lew <lewbloch@gmail.com>, wrote: >>> Daniel Pitts is a well-known and respected contributor to the Java newsgroups. >> and? > >to Lew: >spk *didn't* respond to a posting of Daniel Pitts. > >As you're filtering away a lot, you should get into the habit >of NOT-assuming that a followup was always to the preceding >article in your newsclient's display. thank you kindly.
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-11-17 13:50 -0800 |
| Message-ID | <17631406.12.1321566611461.JavaMail.geo-discussion-forums@prms22> |
| In reply to | #10017 |
On Thursday, November 17, 2011 12:35:16 PM UTC-8, spk wrote: > Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>, wrote: > >spk <jhic@speak.invalid> wrote: > >> Lew <lewb...@gmail.com>, wrote: > >>> Daniel Pitts is a well-known and respected contributor to the Java newsgroups. > >> and? > > > >to Lew: > >spk *didn't* respond to a posting of Daniel Pitts. > > > >As you're filtering away a lot, you should get into the habit > >of NOT-assuming that a followup was always to the preceding > >article in your newsclient's display. > > thank you kindly. My error doesn't change the fact that your post, spk, was nothing but trollish crap. Go away unless you're willing to discuss matters related to Java programming. -- Lew
[toc] | [prev] | [next] | [standalone]
| From | spk <jhic@speak.invalid> |
|---|---|
| Date | 2011-11-17 18:48 -0400 |
| Message-ID | <4ec58f45$0$24176$c3e8da3$e3f2c276@news.astraweb.com> |
| In reply to | #10019 |
Lew <lewbloch@gmail.com>, wrote: >On Thursday, November 17, 2011 12:35:16 PM UTC-8, spk wrote: >> Andreas Leitgeb <a...@gamma.logic.tuwien.ac.at>, wrote: >> >spk <jhic@speak.invalid> wrote: >> >> Lew <lewb...@gmail.com>, wrote: >> >>> Daniel Pitts is a well-known and respected contributor to the Java newsgroups. >> >> and? >> > >> >to Lew: >> >spk *didn't* respond to a posting of Daniel Pitts. >> > >> >As you're filtering away a lot, you should get into the habit >> >of NOT-assuming that a followup was always to the preceding >> >article in your newsclient's display. >> >> thank you kindly. > >My error doesn't change the fact that your post, spk, was nothing >but trollish crap. Go away unless you're willing to discuss matters >related to Java programming. ummm...for some time now I have entertained the thought you and derbyshire are joined at the hip. your original comment is classic derbyshire error as is your reactive now. where your broken news client will not filter do not make more noise whining, consult http://helpdesk.astraweb.com/index.php
[toc] | [prev] | [next] | [standalone]
| From | thoolen <tholen01@gmail.com> |
|---|---|
| Date | 2011-11-17 18:33 -0800 |
| Message-ID | <7a895941-5796-4751-981e-bb1255f93277@p16g2000yqd.googlegroups.com> |
| In reply to | #10022 |
On Nov 17, 5:48 pm, "spk", an obvious murphy sock, wrote:
NaN> Newsgroups: comp.lang.java.programmer
NaN> ummm...for some time now I have entertained the thought you
NaN> and derbyshire are joined at the hip.
What does your thought have to do with Java, murphy?
NaN> your original comment is classic derbyshire error as is your
reactive
NaN> now.
Who is "derbyshire", murphy? There is nobody in this newsgroup using
that alias.
NaN> where your broken news client will not filter do not make more
noise
NaN> whining, consult
What does your classic erroneous presupposition have to do with Java,
murphy? Lew posted via Google Groups rather than using any news client
at all, murphy.
What does your URL have to do with Java, murphy?
"I had 'volunteered (years back) to support those who do endeavor
to provide free Free Usenet access, support those who offered
subscription based Free Usenet access, nothing more than
cooperation expected in return for what has been many
thousands of hours of work. I note most of those I joined with
are either deceased, severely disabled, or plain ole' MIA..
now it is my Time. ...
You just read my last. ...
For those who think they see me in future times I can only wish
you severe Tinnitus in your dreams. For those who know me
well (eMail, whatever) and see me, know I will be smiling also.
It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
for all the Good Times! May you and yours always bear well
with all Life brings you".
/0ut"
--murphy
http://www.uffnet.com/kookkamp/goodbye.htm
And some people wonder why I call them Famous Last Words.
P.S. You forgot to include a copy of your trademarked Lits o' Haet,
murphy. Still suffering from memory problems, murphy?
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-11-17 13:48 -0800 |
| Message-ID | <23591489.9.1321566539494.JavaMail.geo-discussion-forums@prap37> |
| In reply to | #10016 |
On Thursday, November 17, 2011 11:23:19 AM UTC-8, Andreas Leitgeb wrote: > spk <jhic@speak.invalid> wrote: > > Lew <lewb...@gmail.com>, wrote: > >> Daniel Pitts is a well-known and respected contributor to the Java newsgroups. > > and? > > to Lew: > spk *didn't* respond to a posting of Daniel Pitts. > > As you're filtering away a lot, you should get into the habit > of NOT-assuming that a followup was always to the preceding > article in your newsclient's display. You assume a lot yourself, assuming that's what I assumed. It was not. Nor were filters involved, and I wonder why you thought they were. Truth is I made a mistake reading the attributions. And it doesn't change the fact that Daniel Pitts is a respected member of this community. -- Lew
[toc] | [prev] | [next] | [standalone]
| From | "Joe Attardi" <jattard1@gmail.com> |
|---|---|
| Date | 2011-11-18 12:20 +0100 |
| Message-ID | <4ec63f7e$1@newsgate.x-privat.org> |
| In reply to | #10020 |
<23591489.9.1321566539494.JavaMail.geo-discussion-forums@prap37>,Lew <lewbloch@gmail.com>, wrote: >On Thursday, November 17, 2011 11:23:19 AM UTC-8, Andreas Leitgeb wrote: >> spk <jhic@speak.invalid> wrote: >> > Lew <lewb...@gmail.com>, wrote: >> >> Daniel Pitts is a well-known and respected contributor to the Java newsgroups. >> > and? >> >> to Lew: >> spk *didn't* respond to a posting of Daniel Pitts. >> >> As you're filtering away a lot, you should get into the habit >> of NOT-assuming that a followup was always to the preceding >> article in your newsclient's display. > >You assume a lot yourself, assuming that's what I assumed. It was not. > >Nor were filters involved, and I wonder why you thought they were. > >Truth is I made a mistake reading the attributions. And it doesn't change the fact that Daniel Pitts is a respected member of this community. \\\\ Do tell me why it is I am coaxed to give your post airtime? Perhaps you can persuade there is not an element of "hear me I be a self managed mannered masturbator", in your words...?... which in your head justifies that loss of credible code you so often publish? Little attention from us (who do publish) is paid to your titterings with your 'confession' now saying more than is needed to reason why that is - your meanderings. As comical as it is to read yet once again the snare you white rabbit types find yourself in is as the fact that the trap is set by one so plainly transparent (as the tormentor of the news group is) is evidence enough once again to never pay attention to code redirects posted here. Really it is comical. Get yourself a newsreader...dw33b. Lots 0f Fucking Laughter. http://al.howardknight.net/msgid.cgi?ID=132161385000 In engleze? PULL YOUR HEAD OOPTA YO ASS! >Truth is I made a mistake reading the attributions. And it doesn't change the fact that Daniel Pitts is a respected member of this Fix the line length, n00B. -- Smiley Joe
[toc] | [prev] | [next] | [standalone]
| From | thoolen <th00len@th0lenbot.thorium> |
|---|---|
| Date | 2011-11-18 15:21 -0500 |
| Message-ID | <ja6eo9$boj$1@speranza.aioe.org> |
| In reply to | #10039 |
On 18/11/2011 6:20 AM, murphy pretended to be Joe Attardi and wrote:
NaN> Newsgroups: comp.lang.java.programmer
NaN> \\\\
What does that have to do with Java, murphy?
NaN> Do tell me why it is I am coaxed to give your post airtime?
What does your question of Bloch have to do with Java, murphy?
NaN> Perhaps you can persuade there is not an element of "hear me I
NaN> be a self managed mannered masturbator", in your words...?...
What does your ridiculous question of Bloch have to do with Java, murphy?
NaN> which in your head justifies that loss of credible code you so often
NaN> publish?
Classic erroneous presupposition.
NaN> Little attention from us (who do publish) is paid to your titterings
NaN> with your 'confession' now saying more than is needed to reason
NaN> why that is - your meanderings.
Non sequitur.
NaN> As comical as it is to read yet once again the snare you white
NaN> rabbit types find yourself in is as the fact that the trap
NaN> is set by one so plainly transparent (as the tormentor of the
NaN> news group is) is evidence enough once again to never pay
NaN> attention to code redirects posted here.
Non sequitur.
Sign 1 of your forgery: this isn't how Joe Attardi writes, murphy.
NaN> Really it is comical.
What does your comical attempt at a forgery have to do with Java, murphy?
NaN> Get yourself a newsreader...dw33b.
What does your directive to Bloch have to do with Java, murphy?
Sign 2 of your forgery: disliking people who use Google Groups or GUI
newsreaders and demanding they get a newsreader (by which you seem to
mean a text-mode unix newsreader) is a classic murphyism, murphy.
NaN> Lots 0f Fucking Laughter.
What does your foul language have to do with Java, murphy?
Sign 3 of your forgery: foul language is much more characteristic of you
than it is of Attardi, murphy.
What does your URL have to do with Java, murphy?
Sign 4 of your forgery: howardknight URLs are a characteristic murphyism
and they are almost never seen except in your posts, murphy, and quoted
in followups to them.
NaN> In engleze?
What is "engleze", murphy, and what does it have to do with Java?
NaN> PULL YOUR HEAD OOPTA YO ASS!
What does your foul language have to do with Java, murphy?
NaN> Fix the line length, n00B.
Who is "n00B", murphy? There is nobody in this newsgroup using that alias.
"I had 'volunteered (years back) to support those who do endeavor
to provide free Free Usenet access, support those who offered
subscription based Free Usenet access, nothing more than
cooperation expected in return for what has been many
thousands of hours of work. I note most of those I joined with
are either deceased, severely disabled, or plain ole' MIA..
now it is my Time. ...
You just read my last. ...
For those who think they see me in future times I can only wish
you severe Tinnitus in your dreams. For those who know me
well (eMail, whatever) and see me, know I will be smiling also.
It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
for all the Good Times! May you and yours always bear well
with all Life brings you".
/0ut"
--murphy
http://www.uffnet.com/kookkamp/goodbye.htm
And some people wonder why I call them Famous Last Words.
P.S. You forgot to include a copy of your trademarked Lits o' Haet,
murphy. Still suffering from memory problems, murphy?
[toc] | [prev] | [next] | [standalone]
| From | thoolen <tholen01@gmail.com> |
|---|---|
| Date | 2011-11-17 18:31 -0800 |
| Message-ID | <a4e7438c-ac1d-4946-b6cc-fc7a28d1b116@r28g2000yqj.googlegroups.com> |
| In reply to | #10007 |
On Nov 17, 12:40 pm, "spk", an obvious murphy sock, wrote:
NaN> Newsgroups: comp.lang.java.programmer
NaN> One old Derbyshire sock popped a load of hogwash woven under
"kensi"
NaN> <kensi_kensing...@zoonoses.de>;
Who is "Derbyshire", murphy? There is nobody in this newsgroup using
that alias. And what does your unsubstantiated allegation regarding
kensi have to do with Java, murphy?
NaN> the pedant in you rises again?
What does your question of kensi have to do with Java, murphy?
NaN> you are lost for reason, Paul?
Who is "Paul", murphy? There is nobody in this newsgroup using that
alias.
NaN> How ironic.
I know your trollish posts are ironic, murphy. No need to tell me
about it.
NaN> failing to render "purpose" into the panorama before you, Paul?
Who is "Paul", murphy? There is nobody in this newsgroup using that
alias.
NaN> classic erroneous supposition.
On your part, murphy.
NaN> now just which of Murphy's list are you going to preserve for
CJLP from your
NaN> portfolio of known troll identities?
What does your unsubstantiated allegation of trolling on kensi's part
have to do with Java, murphy? Rather ironic, coming as it does from a
troll, murphy.
NaN> Murphy's list applies;
What does your trademarked Lits o' Haet have to do with Java, murphy?
NaN> Truth in Conclusions.
What does your classic unsubstantiated, erroneous, and ironic claim
have to do with Java, murphy?
NaN> "At some point, can't we find a bit
NaN> of charity for a guy who looks to be in for some real hellish
times up
NaN> ahead?"
How ironic.
What does your URL have to do with Java, murphy?
"I had 'volunteered (years back) to support those who do endeavor
to provide free Free Usenet access, support those who offered
subscription based Free Usenet access, nothing more than
cooperation expected in return for what has been many
thousands of hours of work. I note most of those I joined with
are either deceased, severely disabled, or plain ole' MIA..
now it is my Time. ...
You just read my last. ...
For those who think they see me in future times I can only wish
you severe Tinnitus in your dreams. For those who know me
well (eMail, whatever) and see me, know I will be smiling also.
It is to you I say "adieu mein frenz and adios .. grazie' [hugs]
for all the Good Times! May you and yours always bear well
with all Life brings you".
/0ut"
--murphy
http://www.uffnet.com/kookkamp/goodbye.htm
And some people wonder why I call them Famous Last Words.
[toc] | [prev] | [next] | [standalone]
| From | Wanja Gayk <brixomatic@yahoo.com> |
|---|---|
| Date | 2011-11-20 13:14 +0100 |
| Message-ID | <MPG.29330d65b85371949896d1@202.177.16.121> |
| In reply to | #9925 |
In article <alpine.DEB.2.00.1111131750140.19917@urchin.earth.li>,
twic@urchin.earth.li says...
> http://groups.google.com/group/comp.lang.java.advocacy/browse_thread/t
hread/83db33bcbd51905d#
>
> Approaches involving nested if-elses will be more efficient, but always
> strike me as rather awkward.
> > I have shown a number of possible snippets. Please let me know what
you
> > think and see if you can come up with something better - fast, terse and
> > comprehensible.
>
> I personally rather like your third option:
>
> final String aSpecies = a.species == null ? "" : a.species;
> final String bSpecies = b.species == null ? "" : b.species;
> return aSpecies.compareTo( bSpecies );
Looks good on first sight, but is ugly on second sight.
What if you need all nulls smaller than all empty strings?
That said I have seen a lot of client code that repeated the null-low or
null-high idiom all over the application in all possible ways, some of
them overly complicated or just plain wrong. Also, it doesn't help the
readability at all.
So I like to use the ComparatorUtils in the apache.commons project, or
create something alike, if the customer doesn't like to include the lib
and allows me to refactor the code. Just for your interest, in my coding
style that utility method would probably look something like this:
static <T> Comparator<T> nullLowComparator(final Comparator<T> delegate)
{
return new Comparator<T>(){
public int compare(final T a, final T b){
return a != null && b != null ? delegate.compare(a,b)
: a == null ? -1
: 1;
}
}
}
Once defined (or found in a library), the client code would reuse that
to avoid repeating the null-low/high idiom. I usually comment that null-
safety with an assertion:
static final Comparator<String> STRING_NATURAL_ORDER =
ComparatorUtils.nullLowComparator(new Comparator<String>(){
final int compare(final String a, final String b){
assert a != null && b != null : "Handled by NullLowComparator";
return a.compareTo(b);
}
});
Often it looks a bit slicker when used with static imports:
static final Comparator<String> STRING_NATURAL_ORDER=nullLowComparator(
new Comparator<String>(){
final int compare(final String a, final String b){
assert a != null && b != null : "Handled by NullLowComparator";
return a.compareTo(b);
}
});
Well, the ComparatorUtils already have a natural-order comparator, so,
this is just an example, usually you'd find a collator there, or a
length comparison or alike.
I have also built comparators that use other comparators in a similar
fashion:
static final Comparator<String> PERSON_BY_AGE= nullLowComparator(
new Comparator<String>(){
final int compare(final String a, final String b){
assert a != null && b != null : "Handled by NullLowComparator";
return reversedComparator(DATE_COMPARATOR)
.compare(a.getBirthday(), b.getBirthday());
}
});
Assuming "DATE_COMPARATOR" is a similar built nullsafe-comparator for
dates.
Personally I found that this is the best way to do it.
Kind regards,
Wanja
--
..Alesi's problem was that the back of the car was jumping up and down
dangerously - and I can assure you from having been teammate to
Jean Alesi and knowing what kind of cars that he can pull up with,
when Jean Alesi says that a car is dangerous - it is. [Jonathan Palmer]
--- Posted via news://freenews.netfront.net/ - Complaints to news@netfront.net ---
[toc] | [prev] | [next] | [standalone]
| From | Lew <lewbloch@gmail.com> |
|---|---|
| Date | 2011-11-20 08:29 -0800 |
| Message-ID | <22621389.2578.1321806550969.JavaMail.geo-discussion-forums@prou19> |
| In reply to | #10092 |
Wanja Gayk wrote:
> static <T> Comparator<T> nullLowComparator(final Comparator<T> delegate)
> {
> return new Comparator<T>(){
> public int compare(final T a, final T b){
> return a != null && b != null ? delegate.compare(a,b)
> : a == null ? -1
> : 1;
> }
> }
> }
So if both 'a' and 'b' are both 'null', it returns -1? That seems problematic - shouldn't it return 0?
I for one would expect 'null' to equal 'null'.
return a == b? 0 : a == null? -1 : b == null? 1 : delegate.compareTo(a, b);
The expression is a little easier if the type implements 'Comparable'.
--
Lew
[toc] | [prev] | [next] | [standalone]
| From | Brixomatic <wanja.gayk@googlemail.com> |
|---|---|
| Date | 2011-11-21 04:03 -0800 |
| Message-ID | <cf2c276f-3af9-4372-a40e-bd2c5bc78808@w7g2000yqc.googlegroups.com> |
| In reply to | #10106 |
On 20 Nov., 17:29, Lew <lewbl...@gmail.com> wrote:
> WanjaGayk wrote:
> > static <T> Comparator<T> nullLowComparator(final Comparator<T> delegate)
> > {
> > return new Comparator<T>(){
> > public int compare(final T a, final T b){
> > return a !=null&& b !=null? delegate.compare(a,b)
> > : a ==null? -1
> > : 1;
> > }
> > }
> > }
>
> So if both 'a' and 'b' are both 'null', it returns -1? That seems problematic - shouldn't it return 0?
Well, what should I say? Kind of embarrassing exception caused by:
PaidNoAttentionError.
Kind regards,
Wanja
[toc] | [prev] | [standalone]
Page 3 of 3 — ← Prev page 1 2 [3]
Back to top | Article view | comp.lang.java.programmer
csiph-web