1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package net.java.sip.communicator.impl.protocol.irc;
import java.util.*;
import net.java.sip.communicator.service.protocol.*;
/**
* The IRC implementation of a sip-communicator AccountID.
*
* @author Stephane Remy
* @author Loic Kempf
* @author Danny van Heumen
*/
public class IrcAccountID
extends AccountID
{
/**
* IRC account server host.
*/
private final String host;
/**
* IRC account server port.
*/
private final int port;
/**
* Creates an account id from the specified id and account properties.
*
* @param userID the user identifier corresponding to this account
* @param host IRC server host
* @param port IRC server port
* @param accountProperties any other properties necessary for the account.
*/
IrcAccountID(final String userID, final String host, final String port,
final Map<String, String> accountProperties)
{
super(userID, accountProperties, ProtocolNames.IRC,
getServiceName(accountProperties));
if (host == null)
{
throw new IllegalArgumentException("host cannot be null");
}
this.host = host;
if (port == null)
{
throw new IllegalArgumentException("port cannot be null");
}
this.port = Integer.parseInt(port);
}
/**
* {@inheritDoc}
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = super.hashCode();
result = prime * result + host.hashCode();
result = prime * result + port;
return result;
}
/**
* Equality extended with checking IRC server host and port, since different
* IRC networks can have users with similar names.
*
* @param obj other object
* @return returns true if equal or false otherwise
*/
@Override
public boolean equals(final Object obj)
{
// TODO if available, base equality on NETWORK=<identifier> in
// RPL_ISUPPORT.
return super.equals(obj)
&& this.host.equals(((IrcAccountID) obj).host)
&& this.port == ((IrcAccountID) obj).port;
}
/**
* Get the IRC server host.
*
* @return returns IRC server host
*/
public String getHost()
{
return this.host;
}
/**
* Get the IRC server port.
*
* @return returns IRC server port
*/
public int getPort()
{
return this.port;
}
/**
* Returns the service name - the server we are logging to if it is null
* which is not supposed to be - we return for compatibility the string we
* used in the first release for creating AccountID (Using this string is
* wrong, but used for compatibility for now).
*
* @param accountProperties Map the properties table configuring the account
* @return String the service name
*/
private static String getServiceName(
final Map<String, String> accountProperties)
{
String serviceName =
accountProperties.get(ProtocolProviderFactory.SERVER_ADDRESS);
if (serviceName != null)
{
final String port =
accountProperties.get(ProtocolProviderFactory.SERVER_PORT);
if (port != null)
{
serviceName += ":" + port;
}
}
return (serviceName == null) ? ProtocolNames.IRC : serviceName;
}
/**
* Get display name for this account instance.
*
* @return returns the display name for this AccountID instance
*/
@Override
public String getDisplayName()
{
// If the ACCOUNT_DISPLAY_NAME property has been set for this account
// we'll be using it as a display name.
String key = ProtocolProviderFactory.ACCOUNT_DISPLAY_NAME;
String accountDisplayName = accountProperties.get(key);
if (accountDisplayName != null && !accountDisplayName.isEmpty())
{
return accountDisplayName;
}
// Construct our own account display name.
return String.format("%s@%s:%s (%s)", this.getUserID(), this.host,
this.port, this.getProtocolName());
}
}
|