Coverage Report - net.sourceforge.pebble.domain.RefererFilter
 
Classes in this File Line Coverage Branch Coverage Complexity
RefererFilter
90%
20/22
100%
4/4
1.3
 
 1  
 /*
 2  
  * Copyright (c) 2003-2011, 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  
 
 52  0
   public RefererFilter() {
 53  0
   }
 54  
 
 55  
   /**
 56  
    * Creates a new category with the specified properties.
 57  
    *
 58  
    * @param expression    the filter expression
 59  
    */
 60  60
   public RefererFilter(String expression) {
 61  60
     setExpression(expression);
 62  60
   }
 63  
 
 64  
   void setId(long id) {
 65  12
     this.id = id;
 66  12
   }
 67  
 
 68  
   public long getId() {
 69  4
     return this.id;
 70  
   }
 71  
 
 72  
   /**
 73  
    * Gets the expression.
 74  
    *
 75  
    * @return    the expression as a String
 76  
    */
 77  
   public String getExpression() {
 78  40
     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) {
 87  60
     if (expression == null) {
 88  4
       this.expression = "";
 89  
     } else {
 90  56
       this.expression = expression;
 91  
     }
 92  60
     this.compiledExpression = Pattern.compile(this.expression);
 93  60
   }
 94  
 
 95  
   /**
 96  
    * Gets the compiled version of the expression.
 97  
    *
 98  
    * @return    the compiled expression as a Pattern
 99  
    */
 100  
   public Pattern getCompiledExpression() {
 101  4
     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() {
 110  36
     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) {
 120  16
     if (!(o instanceof RefererFilter)) {
 121  8
       return false;
 122  
     }
 123  
 
 124  8
     RefererFilter filter = (RefererFilter)o;
 125  8
     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) {
 141  12
     RefererFilter category = (RefererFilter)o;
 142  12
     return getExpression().compareTo(category.getExpression());
 143  
   }
 144  
 
 145  
 }