001/*-------------------------------------------------------------------------+ 002| | 003| Copyright 2005-2011 the ConQAT Project | 004| | 005| Licensed under the Apache License, Version 2.0 (the "License"); | 006| you may not use this file except in compliance with the License. | 007| You may obtain a copy of the License at | 008| | 009| http://www.apache.org/licenses/LICENSE-2.0 | 010| | 011| Unless required by applicable law or agreed to in writing, software | 012| distributed under the License is distributed on an "AS IS" BASIS, | 013| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 014| See the License for the specific language governing permissions and | 015| limitations under the License. | 016+-------------------------------------------------------------------------*/ 017package org.conqat.engine.service.shared.client; 018 019/** 020 * Stores all information required to contact a server. 021 * 022 * This class is immutable. 023 */ 024public class ServerDetails { 025 026 /** The default timeout in seconds. */ 027 private static final int DEFAULT_TIMEOUT_SECONDS = 10; 028 029 /** The URL. */ 030 private final String url; 031 032 /** The username. */ 033 private final String username; 034 035 /** The password. */ 036 private final String password; 037 038 /** The connection timeout in seconds. */ 039 private final int timeoutSeconds; 040 041 /** Constructor using the default timeout of 10 seconds. */ 042 public ServerDetails(String url, String username, String password) { 043 this(url, username, password, DEFAULT_TIMEOUT_SECONDS); 044 } 045 046 /** Constructor. */ 047 public ServerDetails(String url, String username, String password, int timeoutSeconds) { 048 this.url = url; 049 this.username = username; 050 this.password = password; 051 this.timeoutSeconds = timeoutSeconds; 052 } 053 054 /** Returns the URL. */ 055 public String getUrl() { 056 return url; 057 } 058 059 /** Returns the username. */ 060 public String getUsername() { 061 return username; 062 } 063 064 /** Returns the password. */ 065 public String getPassword() { 066 return password; 067 } 068 069 /** 070 * Returns the precommit branch name, @see 071 * ProjectBranchesService#PRECOMMIT_BRANCH_PREFIX. 072 */ 073 public String getPreCommitBranch() { 074 return "__precommit__" + this.getUsername(); 075 } 076 077 /** Hashing is based on {@link #url} only. */ 078 @Override 079 public int hashCode() { 080 return url.hashCode(); 081 } 082 083 /** Two ServerDetails are equal if the {@link #url} is the same. */ 084 @Override 085 public boolean equals(Object obj) { 086 if (!(obj instanceof ServerDetails)) { 087 return false; 088 } 089 return url.equals(((ServerDetails) obj).url); 090 } 091 092 /** {@inheritDoc} */ 093 @Override 094 public String toString() { 095 return username + "@" + url; 096 } 097 098 /** Returns the timeout for the connection to use (in seconds). */ 099 public int getTimeoutSeconds() { 100 return timeoutSeconds; 101 } 102 103 /** Returns a copy of the server details with the new timeout value. */ 104 public ServerDetails withTimeOut(int timeOutSeconds) { 105 return new ServerDetails(url, username, password, timeOutSeconds); 106 } 107}