1 23 package com.sun.appserv.management.client.prefs; 24 25 32 public final class LoginInfo implements Comparable <LoginInfo> { 33 private String host; 34 private int port; 35 private String user; 36 private String password; 37 38 48 public LoginInfo(final String host, final int port, final String user, final String password) { 49 if (host == null || port < 0 || user == null || password == null) 50 throw new IllegalArgumentException ("null value"); init(host, port, user, password); 52 } 53 public String getHost() { 54 return ( host ); 55 } 56 public int getPort() { 57 return ( port ); 58 } 59 public String getUser() { 60 return ( user ); 61 } 62 public String getPassword() { 63 return ( password ); 64 } 65 public boolean equals(final Object other) { 66 boolean same = false; 67 if (other instanceof LoginInfo) { 68 final LoginInfo that = (LoginInfo) other; 69 same = this.host.equals(that.host) && 70 this.port == that.port && 71 this.user.equals(that.user) && 72 this.password.equals(that.password); 73 } 74 return ( same ); 75 } 76 public int hashCode() { 77 return ( (int) 31 * host.hashCode() + 23 * port + 53 * user.hashCode() + 13 * password.hashCode() ); 78 } 79 80 private void init(final String host, final int port, final String user, final String password) { 81 this.host = host; 82 this.port = port; 83 this.user = user; 84 this.password = password; 85 } 86 87 public String toString() { 88 return ( host + port + user + password ); 89 } 90 91 public int compareTo(final LoginInfo that) { 92 final String thisKey = this.user + this.host + this.port; 93 final String thatKey = that.user + that.host + that.port; 94 return ( thisKey.compareTo(thatKey) ); 95 } 96 } | Popular Tags |