001/*
002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the Eclipse Public License v1.0
006 * which accompanies this distribution, and is available at
007 * http://www.eclipse.org/legal/epl-v10.html
008 *
009 * Contributors:
010 *     Florent Guillaume
011 */
012
013package org.nuxeo.ecm.core.storage;
014
015/**
016 * Simple username + password.
017 *
018 * @author Florent Guillaume
019 */
020public final class Credentials {
021
022    private final String username;
023
024    private final String password;
025
026    public Credentials(String username, String password) {
027        this.username = username;
028        this.password = password;
029    }
030
031    public String getUserName() {
032        return username;
033    }
034
035    public String getPassword() {
036        return password;
037    }
038
039    @Override
040    public int hashCode() {
041        int result = 31 + ((username == null) ? 0 : username.hashCode());
042        return 31 * result + ((password == null) ? 0 : password.hashCode());
043    }
044
045    @Override
046    public boolean equals(Object other) {
047        if (other == this) {
048            return true;
049        }
050        if (other instanceof Credentials) {
051            return equals((Credentials) other);
052        }
053        return false;
054    }
055
056    private boolean equals(Credentials other) {
057        if (username == null) {
058            if (other.username != null) {
059                return false;
060            }
061        } else if (!username.equals(other.username)) {
062            return false;
063        }
064        if (password == null) {
065            if (other.password != null) {
066                return false;
067            }
068        } else if (!password.equals(other.password)) {
069            return false;
070        }
071        return true;
072    }
073
074}