SVN auth
[fedora-idea.git] / plugins / svn4idea / src / org / jetbrains / idea / svn / SvnAuthEquals.java
blobec1e9f09ddb9100f712687434bad24893df8ddda
1 /*
2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.jetbrains.idea.svn;
18 import com.intellij.openapi.util.Comparing;
19 import org.tmatesoft.svn.core.auth.*;
21 public class SvnAuthEquals {
22 private SvnAuthEquals() {
25 public static boolean equals(final SVNAuthentication a1, final SVNAuthentication a2) {
26 if (a1 == a2) return true;
27 if (a1 == null || a2 == null) return false;
28 if (! Comparing.equal(a1.getKind(), a2.getKind())) return false;
29 if (! Comparing.equal(a1.getUserName(), a2.getUserName())) return false;
31 final Class<? extends SVNAuthentication> a1Class = a1.getClass();
32 if (! a1Class.equals(a2.getClass())) return false;
34 if (SVNUserNameAuthentication.class.equals(a1Class)) return true;
35 if (SVNPasswordAuthentication.class.equals(a1Class)) {
36 return Comparing.equal(((SVNPasswordAuthentication) a1).getPassword(), ((SVNPasswordAuthentication) a2).getPassword());
38 if (SVNSSLAuthentication.class.equals(a1Class)) {
39 if (! Comparing.equal(((SVNSSLAuthentication) a1).getCertificateFile(), ((SVNSSLAuthentication) a2).getCertificateFile())) return false;
40 return Comparing.equal(((SVNSSLAuthentication) a1).getPassword(), ((SVNSSLAuthentication) a2).getPassword());
42 if (SVNSSHAuthentication.class.equals(a1Class)) {
43 if (! Comparing.equal(((SVNSSHAuthentication) a1).getPrivateKeyFile(), ((SVNSSHAuthentication) a2).getPrivateKeyFile())) return false;
44 if (! Comparing.equal(((SVNSSHAuthentication) a1).getPassphrase(), ((SVNSSHAuthentication) a2).getPassphrase())) return false;
45 if (! Comparing.equal(((SVNSSHAuthentication) a1).getPortNumber(), ((SVNSSHAuthentication) a2).getPortNumber())) return false;
46 return Comparing.equal(((SVNSSHAuthentication) a1).getPassword(), ((SVNSSHAuthentication) a2).getPassword());
48 return false;
51 public static int hashCode(final SVNAuthentication a) {
52 int result = a.getKind().hashCode();
53 if (a.getUserName() != null) {
54 result = (31 * result) + a.getUserName().hashCode();
56 return result;