com.atlassian.crowd.embedded.api
Class UserComparator

java.lang.Object
  extended by com.atlassian.crowd.embedded.api.UserComparator
All Implemented Interfaces:
Comparator<User>

public class UserComparator
extends Object
implements Comparator<User>

Supplies re-useable methods for equals, hashcode and compareTo that can be shared with different implementations of User in order to be compatible. You can also instantiate this class to get a Comparator of User.


Nested Class Summary
static class UserComparator.Key
           
 
Field Summary
static com.google.common.base.Function<User,UserComparator.Key> KEY_MAKER
          A Function to turn Users into representative keys that sort in the same order as this Comparator.
static Comparator<User> USER_COMPARATOR
          Singleton instance of Comparator
 
Method Summary
 int compare(User user1, User user2)
           
static int compareTo(User user1, User user2)
           
static boolean equal(User user1, User user2)
          Checks whether the two User objects are equal according to the contract of the User interface.
static boolean equalsObject(User user, Object o)
           
static int hashCode(User user)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.util.Comparator
equals
 

Field Detail

USER_COMPARATOR

public static final Comparator<User> USER_COMPARATOR
Singleton instance of Comparator


KEY_MAKER

public static com.google.common.base.Function<User,UserComparator.Key> KEY_MAKER
A Function to turn Users into representative keys that sort in the same order as this Comparator.

Method Detail

equal

public static boolean equal(User user1,
                            User user2)
Checks whether the two User objects are equal according to the contract of the User interface.

If you are implementing User.equals(Object) then just write code like this:

    public boolean equals(Object o)
    {
        return (o instanceof User) && UserComparator.equal(this, (User) o);
    }
 

Parameters:
user1 - First User
user2 - Second User
Returns:
true if these are two equal Users.

equalsObject

public static boolean equalsObject(User user,
                                   Object o)

hashCode

public static int hashCode(User user)

compareTo

public static int compareTo(User user1,
                            User user2)

compare

public int compare(User user1,
                   User user2)
Specified by:
compare in interface Comparator<User>


Copyright © 2013 Atlassian. All Rights Reserved.