File Source: countedurl.java
/*
P/P * Method: net.sourceforge.pebble.logging.CountedUrl__static_init
*/
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 */
/*
P/P * Method: void net.sourceforge.pebble.logging.CountedUrl(String)
*
* Postconditions:
* init'ed(this.blog)
* init'ed(this.fileDownload)
* this.logEntries == &new LinkedList(CountedUrl#1)
* possibly_updated(this.name)
* init'ed(this.newsFeed)
* init'ed(this.pageView)
* init'ed(this.url)
* new LinkedList(CountedUrl#1) num objects == 1
*/
71 public CountedUrl(String url) {
72 setUrl(url);
73 }
74
75 /**
76 * Creates a new CountedUrl representing the specified url.
77 *
78 * @param url the url as a String
79 */
/*
P/P * Method: void net.sourceforge.pebble.logging.CountedUrl(String, Blog)
*
* Postconditions:
* this.blog == blog
* init'ed(this.blog)
* init'ed(this.fileDownload)
* this.logEntries == &new LinkedList(CountedUrl#1)
* possibly_updated(this.name)
* init'ed(this.newsFeed)
* init'ed(this.pageView)
* init'ed(this.url)
* new LinkedList(CountedUrl#1) num objects == 1
*/
80 public CountedUrl(String url, Blog blog) {
81 this.blog = blog;
82 setUrl(url);
83 }
84
85 /**
86 * Gets the underlying url.
87 *
88 * @return the url as a String
89 */
90 public String getUrl() {
/*
P/P * Method: String getUrl()
*
* Preconditions:
* init'ed(this.url)
*
* Postconditions:
* return_value == this.url
* init'ed(return_value)
*/
91 return url;
92 }
93
94 /**
95 * Sets the underlying url.
96 *
97 * @param url the url as a String
98 */
99 protected void setUrl(String url) {
/*
P/P * Method: void setUrl(String)
*
* Postconditions:
* this.url == url
* init'ed(this.url)
*/
100 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 public String getName() {
/*
P/P * Method: String getName()
*
* Preconditions:
* init'ed(this.name)
*
* Postconditions:
* return_value == this.name
* init'ed(return_value)
*/
110 return this.name;
111 }
112
113 /**
114 * Sets the name.
115 *
116 * @param name the name as a String
117 */
118 protected void setName(String name) {
/*
P/P * Method: void setName(String)
*
* Postconditions:
* this.name == name
* init'ed(this.name)
*/
119 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 public String getTruncatedName() {
/*
P/P * Method: String getTruncatedName()
*
* Preconditions:
* this.name != null
*
* Postconditions:
* return_value != null
*
* Test Vectors:
* java.lang.String:length(...)@130: {61..232-1}, {0..60}
*/
129 String s = getName();
130 if (s.length() <= NAME_LENGTH_LIMIT) {
131 return s;
132 } else {
133 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 public void addLogEntry(LogEntry logEntry) {
/*
P/P * Method: void addLogEntry(LogEntry)
*
* Preconditions:
* this.logEntries != null
*/
143 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 public List<LogEntry> getLogEntries() {
/*
P/P * Method: List getLogEntries()
*
* Preconditions:
* init'ed(this.logEntries)
*
* Postconditions:
* return_value == &new LinkedList(getLogEntries#1)
* new LinkedList(getLogEntries#1) num objects == 1
*/
152 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 public int getCount() {
/*
P/P * Method: int getCount()
*
* Preconditions:
* this.logEntries != null
*
* Postconditions:
* init'ed(return_value)
*/
161 return logEntries.size();
162 }
163
164 /**
165 * Implementation of the hashCode() method.
166 *
167 * @return the hashcode of the underlying url
168 */
169 public int hashCode() {
/*
P/P * Method: int hashCode()
*
* Preconditions:
* init'ed(this.url)
*
* Postconditions:
* init'ed(return_value)
*/
170 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 public boolean equals(Object o) {
/*
P/P * Method: bool equals(Object)
*
* Preconditions:
* (soft) init'ed(o.url)
* (soft) init'ed(this.url)
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* o.url: Inverse{null}, Addr_Set{null}
* this == o: {0}, {1}
* this.url: Inverse{null}, Addr_Set{null}
* java.lang.String:equals(...)@189: {0}, {1}
*/
181 if (this == o) return true;
182 if (!(o instanceof CountedUrl)) return false;
183
184 CountedUrl cUrl = (CountedUrl)o;
185
186 if (url == null && cUrl.getUrl() == null) {
187 return true;
188 } else {
189 return (url != null && url.equals(cUrl.getUrl()));
190 }
191 }
192
193 public boolean isNewsFeed() {
/*
P/P * Method: bool isNewsFeed()
*
* Preconditions:
* init'ed(this.newsFeed)
*
* Postconditions:
* return_value == this.newsFeed
* init'ed(return_value)
*/
194 return newsFeed;
195 }
196
197 public void setNewsFeed(boolean newsFeed) {
/*
P/P * Method: void setNewsFeed(bool)
*
* Postconditions:
* this.newsFeed == newsFeed
* init'ed(this.newsFeed)
*/
198 this.newsFeed = newsFeed;
199 }
200
201 public boolean isPageView() {
/*
P/P * Method: bool isPageView()
*
* Preconditions:
* init'ed(this.pageView)
*
* Postconditions:
* return_value == this.pageView
* init'ed(return_value)
*/
202 return pageView;
203 }
204
205 public void setPageView(boolean pageView) {
/*
P/P * Method: void setPageView(bool)
*
* Postconditions:
* this.pageView == pageView
* init'ed(this.pageView)
*/
206 this.pageView = pageView;
207 }
208
209 public boolean isFileDownload() {
/*
P/P * Method: bool isFileDownload()
*
* Preconditions:
* init'ed(this.fileDownload)
*
* Postconditions:
* return_value == this.fileDownload
* init'ed(return_value)
*/
210 return fileDownload;
211 }
212
213 public void setFileDownload(boolean fileDownload) {
/*
P/P * Method: void setFileDownload(bool)
*
* Postconditions:
* this.fileDownload == fileDownload
* init'ed(this.fileDownload)
*/
214 this.fileDownload = fileDownload;
215 }
216
217 }
SofCheck Inspector Build Version : 2.22510
| countedurl.java |
2010-Jun-25 19:40:32 |
| countedurl.class |
2010-Jul-19 20:23:38 |