Clover coverage report - Maven Clover report
Coverage timestamp: Sun Aug 20 2006 04:01:04 PDT
file stats: LOC: 150   Methods: 13
NCLOC: 81   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
NewsAddress.java 38.5% 55.8% 61.5% 51.2%
coverage coverage
 1    /**
 2    *
 3    * Copyright 2003-2004 The Apache Software Foundation
 4    *
 5    * Licensed under the Apache License, Version 2.0 (the "License");
 6    * you may not use this file except in compliance with the License.
 7    * You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    */
 17   
 18    package javax.mail.internet;
 19   
 20    import java.util.ArrayList;
 21    import java.util.List;
 22    import java.util.StringTokenizer;
 23   
 24    import javax.mail.Address;
 25   
 26    import sun.security.provider.Sun;
 27   
 28    /**
 29    * A representation of an RFC1036 Internet newsgroup address.
 30    *
 31    * @version $Rev: 381393 $ $Date: 2006-02-27 09:38:03 -0800 (Mon, 27 Feb 2006) $
 32    */
 33    public class NewsAddress extends Address {
 34    /**
 35    * The host for this newsgroup
 36    */
 37    protected String host;
 38   
 39    /**
 40    * The name of this newsgroup
 41    */
 42    protected String newsgroup;
 43   
 44  0 public NewsAddress() {
 45    }
 46   
 47  13 public NewsAddress(String newsgroup) {
 48  13 this.newsgroup = newsgroup;
 49    }
 50   
 51  3 public NewsAddress(String newsgroup, String host) {
 52  3 this.newsgroup = newsgroup;
 53  3 this.host = host;
 54    }
 55   
 56    /**
 57    * The type of this address; always "news".
 58    * @return "news"
 59    */
 60  2 public String getType() {
 61  2 return "news";
 62    }
 63   
 64  0 public void setNewsgroup(String newsgroup) {
 65  0 this.newsgroup = newsgroup;
 66    }
 67   
 68  3 public String getNewsgroup() {
 69  3 return newsgroup;
 70    }
 71   
 72  0 public void setHost(String host) {
 73  0 this.host = host;
 74    }
 75   
 76  3 public String getHost() {
 77  3 return host;
 78    }
 79   
 80  7 public String toString() {
 81    // Sun impl only appears to return the newsgroup name, no host.
 82  7 return newsgroup;
 83    }
 84   
 85  10 public boolean equals(Object o) {
 86  0 if (this == o) return true;
 87  0 if (!(o instanceof NewsAddress)) return false;
 88   
 89  10 final NewsAddress newsAddress = (NewsAddress) o;
 90   
 91  0 if (host != null ? !host.equals(newsAddress.host) : newsAddress.host != null) return false;
 92  0 if (newsgroup != null ? !newsgroup.equals(newsAddress.newsgroup) : newsAddress.newsgroup != null) return false;
 93   
 94  10 return true;
 95    }
 96   
 97  0 public int hashCode() {
 98  0 int result;
 99  0 result = (host != null ? host.toLowerCase().hashCode() : 0);
 100  0 result = 29 * result + (newsgroup != null ? newsgroup.hashCode() : 0);
 101  0 return result;
 102    }
 103   
 104    /**
 105    * Parse a comma-spearated list of addresses.
 106    *
 107    * @param addresses the list to parse
 108    * @return the array of extracted addresses
 109    * @throws AddressException if one of the addresses is invalid
 110    */
 111  10 public static NewsAddress[] parse(String addresses) throws AddressException {
 112  10 List result = new ArrayList();
 113  10 StringTokenizer tokenizer = new StringTokenizer(addresses, ",");
 114  10 while (tokenizer.hasMoreTokens()) {
 115  12 String address = tokenizer.nextToken().trim();
 116  12 int index = address.indexOf('@');
 117  12 if (index == -1) {
 118  10 result.add(new NewsAddress(address));
 119    } else {
 120  2 String newsgroup = address.substring(0, index).trim();
 121  2 String host = address.substring(index+1).trim();
 122  2 result.add(new NewsAddress(newsgroup, host));
 123    }
 124    }
 125  10 return (NewsAddress[]) result.toArray(new NewsAddress[result.size()]);
 126    }
 127   
 128    /**
 129    * Convert the supplied addresses to a comma-separated String.
 130    * If addresses is null, returns null; if empty, returns an empty string.
 131    *
 132    * @param addresses the addresses to convert
 133    * @return a comma-separated list of addresses
 134    */
 135  0 public static String toString(Address[] addresses) {
 136  0 if (addresses == null) {
 137  0 return null;
 138    }
 139  0 if (addresses.length == 0) {
 140  0 return "";
 141    }
 142   
 143  0 StringBuffer result = new StringBuffer(addresses.length * 32);
 144  0 result.append(addresses[0]);
 145  0 for (int i = 1; i < addresses.length; i++) {
 146  0 result.append(',').append(addresses[i].toString());
 147    }
 148  0 return result.toString();
 149    }
 150    }