package com.tandbergtv.workflow.auth;

/**
 * A user that can be a resource
 * 
 * @author xcargar
 */
public class User implements Comparable<User> {
	private String email;
	private String userName;

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	/*
	 * Returns the trimmed userName of the user. If the userName is null, returns an empty string
	 */
	private String getTrimmedNotNullName(User user) {
		if(user.getUserName() == null) {
			return "";
		} else {
			return user.getUserName().trim();
		}
	}

	@Override
	public int compareTo(User other) {
		if(other == null) {
			return -1;
		}		
		
		String name = getTrimmedNotNullName(this);
		String otherName = getTrimmedNotNullName(other);
		
		return name.compareTo(otherName);
	}

}
