Re: String.equals()



Oliver Wong wrote:
In order to actually obey the contract of Comparator,

Why try, if you know that what you'll submit it to will only care
whether it gives zero or non-zero?

you're forced to
come up with a total-ordering of all your elements of a given type.
Sometimes this is difficult or impossible.

So just make a Comparator that returns 0 or 1, and put a note in the
docs saying it doesn't obey the contract. Anything wrong with that?

I've created an interface which
is like Comparator, but only checks two items for equality, instead of an
ordering. I couldn't come up with a good name though: it's called
Equalitor<T>.


(I'd vote for the already mentioned "Equator".)

--
ss at comp dot lancs dot ac dot uk |
.



Relevant Pages

  • Re: String.equals()
    ... if you know that what you'll submit it to will only care ... whether it gives zero or non-zero? ... come up with a total-ordering of all your elements of a given type. ...
    (comp.lang.java.programmer)
  • Re: "0= if" or simply "if" ???
    ... A flag is either zero or non-zero. ... Doesn't matter how that zero or non-zero got on the stack. ... Words like < will ensure that you have a "well formed flag" and that is -1. ... All you care about is zero verses non-zero. ...
    (comp.lang.forth)
  • Re: how to return Comparator values
    ... positive or zero. ... Of course, you should read the Javadocs for the Comparator interface, but in ... a nutshell, the compare function returns the relative order of the ... compareTo function of Comparables (Strings, Numbers, etc all implement ...
    (comp.lang.java.help)
  • noop comparator for qsort
    ... The fourth argument is a comparator that returns `an integer less than, ... or greater than zero' depending on the ordering of its ... If I don't care about the order and simply want qsort() to run as ...
    (comp.lang.c)
  • Re: Synchronous rectifier
    ... I have said that the comparator is a zero-crossing detector. ... used to compare Vds with zero, but in fact there are some offset ... a negative several milivolts will cause oscillation under ...
    (sci.electronics.design)