package com.atlassian.bitbucket.user;

import com.atlassian.crowd.embedded.impl.IdentifierUtils;

public class ApplicationUserEquality {

    public static boolean equals(ApplicationUser user, Object object) {
        if (user == object) {
            return true;
        }
        if (!(object instanceof ApplicationUser)) {
            return false;
        }

        if (user == null) {
            return false;
        }
        
        ApplicationUser other = (ApplicationUser) object;

        String left = user.getName();
        String right = other.getName();
        if (left == null || right == null) {
            return left == null && right == null;
        }

        return IdentifierUtils.toLowerCase(left).equals(IdentifierUtils.toLowerCase(right));
    }
    
    public static int hashCode(ApplicationUser user) {
        return user.getName() == null ? 0 : IdentifierUtils.toLowerCase(user.getName()).hashCode();
    }
}
