[
https://issues.apache.org/jira/browse/FTPSERVER-442?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
DAVID MOLLITOR updated FTPSERVER-442:
-------------------------------------
Description:
The BaseUser class does not implement hashcode() or equals. In my
FileSystemFactory implementation, I show a different view to the same client
based on the number of concurrent logins for a single user. To perform this
task, I track the number of user logins in Map<User, Integer>. This does not
work though because BaseUser does not implement hashcode() or equals(). As a
work around, I user Map<String, Integer> and use User.getName() as the key. I
recommend... for BaseUser:
{code:title=BaseUser.java|borderStyle=solid}
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
String name = getName();
return (name == null) ? 0 : name.hashCode();
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BaseUser other = (BaseUser) obj;
if (name == null) {
if (other.getName()!= null) {
return false;
}
} else if (!getName().equals(other.getName())) {
return false;
}
return true;
}
{code}
was:
The BaseUser class does not implement hashcode() or equals. In my
FileSystemFactory implementation, I show a different view to the same client
based on the number of concurrent logins for a single user. To perform this
task, I track the number of user logins in Map<User, Integer>. This does not
work though because BaseUser does not implement hashcode() or equals(). As a
work around, I user Map<String, Integer> and use User.getName() as the key. I
recommend... for BaseUser:
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
String name = getName();
return (name == null) ? 0 : name.hashCode();
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
BaseUser other = (BaseUser) obj;
if (name == null) {
if (other.getName()!= null) {
return false;
}
} else if (!getName().equals(other.getName())) {
return false;
}
return true;
}
> BaseUser Does Not Implement hashcode() or equals()
> --------------------------------------------------
>
> Key: FTPSERVER-442
> URL: https://issues.apache.org/jira/browse/FTPSERVER-442
> Project: FtpServer
> Issue Type: Improvement
> Components: Core
> Affects Versions: 1.0.6
> Reporter: DAVID MOLLITOR
> Priority: Minor
> Original Estimate: 0.5h
> Remaining Estimate: 0.5h
>
> The BaseUser class does not implement hashcode() or equals. In my
> FileSystemFactory implementation, I show a different view to the same client
> based on the number of concurrent logins for a single user. To perform this
> task, I track the number of user logins in Map<User, Integer>. This does not
> work though because BaseUser does not implement hashcode() or equals(). As a
> work around, I user Map<String, Integer> and use User.getName() as the key.
> I recommend... for BaseUser:
> {code:title=BaseUser.java|borderStyle=solid}
> /* (non-Javadoc)
> * @see java.lang.Object#hashCode()
> */
> @Override
> public int hashCode() {
> String name = getName();
> return (name == null) ? 0 : name.hashCode();
> }
> /* (non-Javadoc)
> * @see java.lang.Object#equals(java.lang.Object)
> */
> @Override
> public boolean equals(Object obj) {
> if (this == obj) {
> return true;
> }
> if (obj == null) {
> return false;
> }
> if (getClass() != obj.getClass()) {
> return false;
> }
> BaseUser other = (BaseUser) obj;
> if (name == null) {
> if (other.getName()!= null) {
> return false;
> }
> } else if (!getName().equals(other.getName())) {
> return false;
> }
> return true;
> }
> {code}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira