+3  A: 

You can abstract that method in a utilities method like:

public boolean allUnique(Object... objs) {
  Set<Object> set = new HashSet<Object>();
  for (Object o : objs)
    set.add(o);
  return set.size() == objs.length
}

The method may not perform well for small numbers (due to the overhead of creating the Set and the varargs array). However, it grows linearly O(n), and for large values it's better than the quadratic growth of a nested if statements.

notnoop
As a side note, make sure that the hashcode() is consistent with equals(),
James
+4  A: 
boolean areDistinct(Object a, Object b, Object c) {
    return (!a.equals(b) &&
            (c == null || (!c.equals(a) && !c.equals(b))));
}
Avi
Putting this into it's own method for reuse gets the upvote.
Dean J
Abel
+6  A: 

EDIT: I removed my first solution as it implemented the wrinkle-scenario as invalid, and it shouldn't

No need to check for null (shortest?):

if(A.equals(B) || B.equals(C) || A.equals(C))
   // not unique

and, as others have already suggested, you can put it in a method for reuse. Or a generic method if you need more reuse ;-)

EDIT: A note to first-timers (if any): the example uses a feature of equals: if its argument is null it should not throw, but return false.

Abel
You don't need the last term; if A equals B and B equals C, then A must equal C (or the implementation of equals() is buggy).
Aaron Digulla
@Aaron: it is not `and`, it is `or`. If one term is false, the other term can still be true: `Auto.equals(Bike) or Bike.equals(Car) or Auto.equals(Car)`. First two are false, third is true: it's needed ;-)
Abel
What if A != B and C == null? My reading of the question is that these are unique, but your first answer tests C first and returns "not unique".
Nefrubyr
+1 Good reading of the question, I can't say whether that's true or not. My thought was, at first, null is illegal and if so, should be discarded. The second solution, shorter, deals with your scenario correctly. Well spotted!
Abel
A != B and C == null is a valid scenario.
John Topley
Thanks John for elaborating, I removed that part from the answer.
Abel
Thanks for your answer. Hmm, it seems kind of obvious now that I see it written out like that!
John Topley
Thinking in autos, bikes and cars helped me out. When in the middle of something, you can't always see the forest for the trees :).
Abel
Agreed. I could have nitpicked and pointed out that a Car is a kind of Auto! ;-)
John Topley
That was the idea: Car == Auto, hence the series is not unique: the statement in the answer would equal true.
Abel
+6  A: 

Since I never start a Java project without using Apache commons-lang, try ObjectUtils.equals (it's null safe):

if (ObjectUtils.equals(a, b) || ObjectUtils.equals(b, c) || ObjectUtils.equals(a, c)) {
  // error condition
}

Put that logic in a generic method, and you'll do even better.

While the business logic allows C to be null, in scenarios like this, it's often better to code defensively and assume that either A or B could be null as well.

Ryan McGeary
I didn't know about ObjectUtils - thanks!
John Topley
Putting the logic into a varargs method seems more useful than a generic method. A varargs method should enable you to compare any number of objects for equality
Don
Don, I agree with that.
Ryan McGeary