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
29   217   24   1,61
10   81   0,83   18
18     1,33  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  CountedUrl       Line # 46 29 0% 24 8 86% 0.8596491
 
  (86)
 
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.logging;
33   
34    import net.sourceforge.pebble.domain.Blog;
35   
36    import java.util.List;
37    import java.util.LinkedList;
38    import java.util.Collections;
39   
40    /**
41    * Represents a visited or referer URL along with a count of how many times
42    * that URL has been accessed/referred from.
43    *
44    * @author Simon Brown
45    */
 
46    public abstract class CountedUrl {
47   
48    /** the maximum length of the name */
49    public static final int NAME_LENGTH_LIMIT = 60;
50   
51    /** the URL as a String */
52    private String url;
53   
54    /** the displayable name for the URL */
55    private String name;
56   
57    /** the collection of log entries that relate to this url */
58    private List<LogEntry> logEntries = new LinkedList<LogEntry>();
59   
60    private boolean newsFeed = false;
61    private boolean pageView = false;
62    private boolean fileDownload = false;
63   
64    protected Blog blog;
65   
66    /**
67    * Creates a new CountedUrl representing the specified url.
68    *
69    * @param url the url as a String
70    */
 
71  210 toggle public CountedUrl(String url) {
72  210 setUrl(url);
73    }
74   
75    /**
76    * Creates a new CountedUrl representing the specified url.
77    *
78    * @param url the url as a String
79    */
 
80  68 toggle public CountedUrl(String url, Blog blog) {
81  68 this.blog = blog;
82  68 setUrl(url);
83    }
84   
85    /**
86    * Gets the underlying url.
87    *
88    * @return the url as a String
89    */
 
90  44 toggle public String getUrl() {
91  44 return url;
92    }
93   
94    /**
95    * Sets the underlying url.
96    *
97    * @param url the url as a String
98    */
 
99  278 toggle protected void setUrl(String url) {
100  278 this.url = url;
101    }
102   
103    /**
104    * Gets a name representation of the url. This is just the url, but truncated
105    * to a maximum number of characters.
106    *
107    * @return a String
108    */
 
109  344 toggle public String getName() {
110  344 return this.name;
111    }
112   
113    /**
114    * Sets the name.
115    *
116    * @param name the name as a String
117    */
 
118  278 toggle protected void setName(String name) {
119  278 this.name = name;
120    }
121   
122    /**
123    * Gets a name representation of the url. This is just the url, but truncated
124    * to a maximum number of characters.
125    *
126    * @return a String
127    */
 
128  8 toggle public String getTruncatedName() {
129  8 String s = getName();
130  8 if (s.length() <= NAME_LENGTH_LIMIT) {
131  4 return s;
132    } else {
133  4 return s.substring(0, NAME_LENGTH_LIMIT - 3) + "...";
134    }
135    }
136   
137    /**
138    * Adds a LogEntry.
139    *
140    * @param logEntry a LogEntry instance
141    */
 
142  92 toggle public void addLogEntry(LogEntry logEntry) {
143  92 logEntries.add(logEntry);
144    }
145   
146    /**
147    * Gets the list of log entries associated with this URL
148    *
149    * @return a List of LogEntry instances
150    */
 
151  0 toggle public List<LogEntry> getLogEntries() {
152  0 return new LinkedList<LogEntry>(logEntries);
153    }
154   
155    /**
156    * Gets the count associated with this url.
157    *
158    * @return the count as an int
159    */
 
160  56 toggle public int getCount() {
161  56 return logEntries.size();
162    }
163   
164    /**
165    * Implementation of the hashCode() method.
166    *
167    * @return the hashcode of the underlying url
168    */
 
169  8 toggle public int hashCode() {
170  8 return url == null ? 0 : url.hashCode();
171    }
172   
173    /**
174    * Determines whether this object is equal to another.
175    *
176    * @param o the object to test against
177    * @return true if the specified object is the same as this one (i.e. the
178    * underlying urls match, false otherwise
179    */
 
180  32 toggle public boolean equals(Object o) {
181  4 if (this == o) return true;
182  8 if (!(o instanceof CountedUrl)) return false;
183   
184  20 CountedUrl cUrl = (CountedUrl)o;
185   
186  20 if (url == null && cUrl.getUrl() == null) {
187  4 return true;
188    } else {
189  16 return (url != null && url.equals(cUrl.getUrl()));
190    }
191    }
192   
 
193  0 toggle public boolean isNewsFeed() {
194  0 return newsFeed;
195    }
196   
 
197  40 toggle public void setNewsFeed(boolean newsFeed) {
198  40 this.newsFeed = newsFeed;
199    }
200   
 
201  0 toggle public boolean isPageView() {
202  0 return pageView;
203    }
204   
 
205  104 toggle public void setPageView(boolean pageView) {
206  104 this.pageView = pageView;
207    }
208   
 
209  0 toggle public boolean isFileDownload() {
210  0 return fileDownload;
211    }
212   
 
213  4 toggle public void setFileDownload(boolean fileDownload) {
214  4 this.fileDownload = fileDownload;
215    }
216   
217    }