Uploaded image for project: 'FtpServer'
  1. FtpServer
  2. FTPSERVER-442

BaseUser Does Not Implement hashcode() or equals()

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 1.0.6
    • None
    • Core
    • None

    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:

      BaseUser.java
      	/* (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;
      	}
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            belugabehr David Mollitor
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Time Tracking

                Estimated:
                Original Estimate - 0.5h
                0.5h
                Remaining:
                Remaining Estimate - 0.5h
                0.5h
                Logged:
                Time Spent - Not Specified
                Not Specified