FileDocCategorySizeDatePackage
NewsAddress.javaAPI DocGlassfish v2 API6032Mon May 14 15:28:50 BST 2007javax.mail.internet

NewsAddress

public class NewsAddress extends Address
This class models an RFC1036 newsgroup address.
author
Bill Shannon
author
John Mani

Fields Summary
protected String
newsgroup
protected String
host
private static final long
serialVersionUID
Constructors Summary
public NewsAddress()
Default constructor.


           
       
public NewsAddress(String newsgroup)
Construct a NewsAddress with the given newsgroup.

param
newsgroup the newsgroup

	this(newsgroup, null);
    
public NewsAddress(String newsgroup, String host)
Construct a NewsAddress with the given newsgroup and host.

param
newsgroup the newsgroup
param
host the host

	this.newsgroup = newsgroup;
	this.host = host;
    
Methods Summary
public booleanequals(java.lang.Object a)
The equality operator.

	if (!(a instanceof NewsAddress))
	    return false;

	NewsAddress s = (NewsAddress)a;
	return newsgroup.equals(s.newsgroup) &&
	    ((host == null && s.host == null) ||
	     (host != null && s.host != null && host.equalsIgnoreCase(s.host)));
    
public java.lang.StringgetHost()
Get the host.

return
host

	return host;
    
public java.lang.StringgetNewsgroup()
Get the newsgroup.

return
newsgroup

	return newsgroup;
    
public java.lang.StringgetType()
Return the type of this address. The type of a NewsAddress is "news".

	return "news";
    
public inthashCode()
Compute a hash code for the address.

	int hash = 0;
	if (newsgroup != null)
	    hash += newsgroup.hashCode();
	if (host != null)
	    hash += host.toLowerCase(Locale.ENGLISH).hashCode();
	return hash;
    
public static javax.mail.internet.NewsAddress[]parse(java.lang.String newsgroups)
Parse the given comma separated sequence of newsgroup into NewsAddress objects.

param
newsgroups comma separated newsgroup string
return
array of NewsAddress objects
exception
AddressException if the parse failed

	// XXX - verify format of newsgroup name?
	StringTokenizer st = new StringTokenizer(newsgroups, ",");
	Vector nglist = new Vector();
	while (st.hasMoreTokens()) {
	    String ng = st.nextToken();
	    nglist.addElement(new NewsAddress(ng));
	}
	int size = nglist.size();
	NewsAddress[] na = new NewsAddress[size];
	if (size > 0)
	    nglist.copyInto(na);
	return na;
    
public voidsetHost(java.lang.String host)
Set the host.

param
host the host

	this.host = host;
    
public voidsetNewsgroup(java.lang.String newsgroup)
Set the newsgroup.

param
newsgroup the newsgroup

	this.newsgroup = newsgroup;
    
public static java.lang.StringtoString(javax.mail.Address[] addresses)
Convert the given array of NewsAddress objects into a comma separated sequence of address strings. The resulting string contains only US-ASCII characters, and hence is mail-safe.

param
addresses array of NewsAddress objects
exception
ClassCastException, if any address object in the given array is not a NewsAddress objects. Note that this is a RuntimeException.
return
comma separated address strings

	if (addresses == null || addresses.length == 0)
	    return null;

	StringBuffer s = 
		new StringBuffer(((NewsAddress)addresses[0]).toString());
	for (int i = 1; i < addresses.length; i++)
	    s.append(",").append(((NewsAddress)addresses[i]).toString());
	
	return s.toString();
    
public java.lang.StringtoString()
Convert this address into a RFC 1036 address.

return
newsgroup

	return newsgroup;