1 21 22 27 28 package javax.mail.internet; 29 30 import java.util.Vector ; 31 import java.util.StringTokenizer ; 32 import javax.mail.*; 33 34 40 41 public class NewsAddress extends Address { 42 43 protected String newsgroup; 44 protected String host; 46 private static final long serialVersionUID = -4203797299824684143L; 47 48 51 public NewsAddress() { } 52 53 58 public NewsAddress(String newsgroup) { 59 this(newsgroup, null); 60 } 61 62 68 public NewsAddress(String newsgroup, String host) { 69 this.newsgroup = newsgroup; 70 this.host = host; 71 } 72 73 77 public String getType() { 78 return "news"; 79 } 80 81 86 public void setNewsgroup(String newsgroup) { 87 this.newsgroup = newsgroup; 88 } 89 90 95 public String getNewsgroup() { 96 return newsgroup; 97 } 98 99 104 public void setHost(String host) { 105 this.host = host; 106 } 107 108 113 public String getHost() { 114 return host; 115 } 116 117 122 public String toString() { 123 return newsgroup; 124 } 125 126 129 public boolean equals(Object a) { 130 if (!(a instanceof NewsAddress )) 131 return false; 132 133 NewsAddress s = (NewsAddress )a; 134 return newsgroup.equals(s.newsgroup) && 135 ((host == null && s.host == null) || 136 (host != null && s.host != null && host.equalsIgnoreCase(s.host))); 137 } 138 139 142 public int hashCode() { 143 int hash = 0; 144 if (newsgroup != null) 145 hash += newsgroup.hashCode(); 146 if (host != null) 147 hash += host.toLowerCase().hashCode(); 148 return hash; 149 } 150 151 163 public static String toString(Address[] addresses) { 164 if (addresses == null || addresses.length == 0) 165 return null; 166 167 StringBuffer s = 168 new StringBuffer (((NewsAddress )addresses[0]).toString()); 169 for (int i = 1; i < addresses.length; i++) 170 s.append(",").append(((NewsAddress )addresses[i]).toString()); 171 172 return s.toString(); 173 } 174 175 183 public static NewsAddress [] parse(String newsgroups) 184 throws AddressException { 185 StringTokenizer st = new StringTokenizer (newsgroups, ","); 187 Vector nglist = new Vector (); 188 while (st.hasMoreTokens()) { 189 String ng = st.nextToken(); 190 nglist.addElement(new NewsAddress (ng)); 191 } 192 int size = nglist.size(); 193 NewsAddress [] na = new NewsAddress [size]; 194 if (size > 0) 195 nglist.copyInto(na); 196 return na; 197 } 198 } 199 | Popular Tags |