File Source: refererfilter.java
/*
P/P * Method: net.sourceforge.pebble.domain.RefererFilter__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.domain;
33
34 import java.util.regex.Pattern;
35
36 /**
37 * Represents a blog category.
38 *
39 * @author Simon Brown
40 */
41 public class RefererFilter implements Comparable {
42
43 // the internal ID for this filter
44 private long id;
45
46 /** the underlying filter expression */
47 private String expression;
48
49 /** the compiled version of the expression */
50 private Pattern compiledExpression;
51
/*
P/P * Method: void net.sourceforge.pebble.domain.RefererFilter()
*/
52 public RefererFilter() {
53 }
54
55 /**
56 * Creates a new category with the specified properties.
57 *
58 * @param expression the filter expression
59 */
/*
P/P * Method: void net.sourceforge.pebble.domain.RefererFilter(String)
*
* Postconditions:
* init'ed(this.compiledExpression)
* this.expression == One-of{&"", expression}
* this.expression != null
*/
60 public RefererFilter(String expression) {
61 setExpression(expression);
62 }
63
64 void setId(long id) {
/*
P/P * Method: void setId(long)
*
* Postconditions:
* this.id == id
* init'ed(this.id)
*/
65 this.id = id;
66 }
67
68 public long getId() {
/*
P/P * Method: long getId()
*
* Preconditions:
* init'ed(this.id)
*
* Postconditions:
* return_value == this.id
* init'ed(return_value)
*/
69 return this.id;
70 }
71
72 /**
73 * Gets the expression.
74 *
75 * @return the expression as a String
76 */
77 public String getExpression() {
/*
P/P * Method: String getExpression()
*
* Preconditions:
* init'ed(this.expression)
*
* Postconditions:
* return_value == this.expression
* init'ed(return_value)
*/
78 return this.expression;
79 }
80
81 /**
82 * Sets the expression.
83 *
84 * @param expression the expression as a String
85 */
86 public void setExpression(String expression) {
/*
P/P * Method: void setExpression(String)
*
* Postconditions:
* init'ed(this.compiledExpression)
* this.expression == One-of{&"", expression}
* this.expression != null
*
* Test Vectors:
* expression: Inverse{null}, Addr_Set{null}
*/
87 if (expression == null) {
88 this.expression = "";
89 } else {
90 this.expression = expression;
91 }
92 this.compiledExpression = Pattern.compile(this.expression);
93 }
94
95 /**
96 * Gets the compiled version of the expression.
97 *
98 * @return the compiled expression as a Pattern
99 */
100 public Pattern getCompiledExpression() {
/*
P/P * Method: Pattern getCompiledExpression()
*
* Preconditions:
* init'ed(this.compiledExpression)
*
* Postconditions:
* return_value == this.compiledExpression
* init'ed(return_value)
*/
101 return this.compiledExpression;
102 }
103
104 /**
105 * Gets the hashcode of this object.
106 *
107 * @return the hashcode as an int
108 */
109 public int hashCode() {
/*
P/P * Method: int hashCode()
*
* Preconditions:
* this.expression != null
*
* Postconditions:
* init'ed(return_value)
*/
110 return expression.hashCode();
111 }
112
113 /**
114 * Determines whether the specified object is equal to this one.
115 *
116 * @param o the object to compare against
117 * @return true if Object o represents the same category, false otherwise
118 */
119 public boolean equals(Object o) {
/*
P/P * Method: bool equals(Object)
*
* Preconditions:
* (soft) o.expression != null
* (soft) init'ed(this.expression)
*
* Postconditions:
* init'ed(return_value)
*/
120 if (!(o instanceof RefererFilter)) {
121 return false;
122 }
123
124 RefererFilter filter = (RefererFilter)o;
125 return (filter.getExpression().equals(expression));
126 }
127
128 /**
129 * Compares this object with the specified object for order. Returns a
130 * negative integer, zero, or a positive integer if this object is less
131 * than, equal to, or greater than the specified object.
132 *
133 * @param o the Object to be compared.
134 * @return a negative integer, zero, or a positive integer if this object
135 * is less than, equal to, or greater than the specified object.
136 *
137 * @throws ClassCastException if the specified object's type prevents it
138 * from being compared to this Object.
139 */
140 public int compareTo(Object o) {
/*
P/P * Method: int compareTo(Object)
*
* Preconditions:
* o != null
* init'ed(o.expression)
* this.expression != null
*
* Postconditions:
* init'ed(return_value)
*/
141 RefererFilter category = (RefererFilter)o;
142 return getExpression().compareTo(category.getExpression());
143 }
144
145 }
SofCheck Inspector Build Version : 2.22510
| refererfilter.java |
2010-Jun-25 19:40:32 |
| refererfilter.class |
2010-Jul-19 20:23:40 |