Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.glorb.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: toward null-safe cookie cutter Comparators Date: Sun, 20 Nov 2011 08:29:10 -0800 (PST) Organization: http://groups.google.com Lines: 22 Message-ID: <22621389.2578.1321806550969.JavaMail.geo-discussion-forums@prou19> References: Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 173.164.137.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 X-Trace: posting.google.com 1321811375 20704 127.0.0.1 (20 Nov 2011 17:49:35 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Sun, 20 Nov 2011 17:49:35 +0000 (UTC) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10106 Wanja Gayk wrote: > static Comparator nullLowComparator(final Comparator delegate) > { > return new Comparator(){ > 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