Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart9.png 23% of files have more coverage
36   218   21   3
16   80   0,58   12
12     1,75  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  Tag       Line # 46 36 0% 21 8 87,5% 0.875
 
  (254)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.domain;
33   
34    import net.sourceforge.pebble.util.StringUtils;
35   
36    import org.apache.commons.logging.Log;
37    import org.apache.commons.logging.LogFactory;
38   
39    import java.util.*;
40   
41    /**
42    * Represents a tag.
43    *
44    * @author Simon Brown
45    */
 
46    public class Tag implements Permalinkable, Comparable {
47   
48    /** the log used by this class */
49    private static final Log log = LogFactory.getLog(Tag.class);
50   
51    /** the owning blog */
52    private Blog blog;
53   
54    /** the name of the tag */
55    private String name = "";
56   
57    /** the rank for this tag */
58    protected int rank;
59   
60    /**
61    * Creates a new tag with the specified properties.
62    *
63    * @param name the name
64    * @param blog a Blog instance
65    */
 
66  614 toggle public Tag(String name, Blog blog) {
67  614 setName(name);
68  614 this.blog = blog;
69    }
70   
71    /**
72    * Gets the name of this tag.
73    *
74    * @return the name as a String
75    */
 
76  3876 toggle public String getName() {
77  3876 return name;
78    }
79   
80    /**
81    * Sets the name of this tag.
82    *
83    * @param name the new tag name
84    */
 
85  618 toggle public void setName(String name) {
86  618 this.name = Tag.encode(name);
87    }
88   
89    /**
90    * Gets the permalink for this object.
91    *
92    * @return a URL as a String
93    */
 
94  6 toggle public String getPermalink() {
95  6 return blog.getUrl() + "tags/" + name + "/";
96    }
97   
98    /**
99    * Gets the hashcode of this object.
100    *
101    * @return the hashcode as an int
102    */
 
103  0 toggle public int hashCode() {
104  0 return name.hashCode();
105    }
106   
107    /**
108    * Determines whether the specified object is equal to this one.
109    *
110    * @param o the object to compare against
111    * @return true if Object o represents the same tag, false otherwise
112    */
 
113  1784 toggle public boolean equals(Object o) {
114  1784 if (!(o instanceof Tag)) {
115  0 return false;
116    }
117   
118  1784 Tag tag = (Tag)o;
119  1784 return tag.getName().equals(name);
120    }
121   
122    /**
123    * Compares this object with the specified object for order. Returns a
124    * negative integer, zero, or a positive integer as this object is less
125    * than, equal to, or greater than the specified object.<p>
126    *
127    * @param o the Object to be compared.
128    * @return a negative integer, zero, or a positive integer as this object
129    * is less than, equal to, or greater than the specified object.
130    *
131    * @throws ClassCastException if the specified object's type prevents it
132    * from being compared to this Object.
133    */
 
134  782 toggle public int compareTo(Object o) {
135  782 Tag tag = (Tag)o;
136  782 return getName().compareTo(tag.getName());
137    }
138   
139    /**
140    * Returns a String representation of this object.
141    *
142    * @return a String
143    */
 
144  0 toggle public String toString() {
145  0 return this.name;
146    }
147   
148    /**
149    * Gets the rank for this tag.
150    *
151    * @return an int between 1 and 10;
152    */
 
153  0 toggle public int getRank() {
154  0 return this.rank;
155    }
156   
157    /**
158    * Given a string containing whitespace separated tags, this method returns a
159    * List containing the tags.
160    *
161    * @param tags a whitespace separated list of tags
162    * @return a List of Tag instances
163    */
 
164  706 toggle public static List<Tag> parse(Blog blog, String tags) {
165  706 List<Tag> list = new ArrayList<Tag>();
166   
167  706 if (tags != null && tags.trim().length() > 0) {
168  224 String s[] = tags.trim().split(" ");
169  738 for (int i = 0; i < s.length; i++) {
170  514 Tag tag = new Tag(StringUtils.transformHTML(s[i].trim()), blog);
171  514 if (!list.contains(tag)) {
172  510 list.add(tag);
173    }
174    }
175    }
176   
177  706 return list;
178    }
179   
180    /**
181    * Given a list of tags, this method formats them into a comma separated list.
182    *
183    * @param tags a List of tags
184    * @return a comma separated String
185    */
 
186  636 toggle public static String format(List<Tag> tags) {
187  636 StringBuilder builder = new StringBuilder();
188   
189  636 if (tags != null) {
190  634 Iterator it = tags.iterator();
191  1080 while (it.hasNext()) {
192  446 Tag tag = (Tag)it.next();
193  446 builder.append(tag.getName());
194  446 if (it.hasNext()) {
195  292 builder.append(", ");
196    }
197    }
198    }
199   
200  636 return builder.toString();
201    }
202   
203    /**
204    * Encodes a tag.
205    *
206    * @param tag a String
207    */
 
208  638 toggle public static String encode(String tag) {
209  638 if (tag == null) {
210  2 return "";
211    } else {
212  636 String encodedTag = tag.trim().toLowerCase();
213  636 encodedTag = encodedTag.replaceAll("\\+", " ");
214  636 return encodedTag;
215    }
216    }
217   
218    }