Coverage Report - com.mattunderscore.filter.contentnegotiation.parser.Redirect
 
Classes in this File Line Coverage Branch Coverage Complexity
Redirect
100%
24/24
100%
18/18
2.571
 
 1  
 /* Copyright © 2012 Matthew Champion
 2  
 All rights reserved.
 3  
 
 4  
 Redistribution and use in source and binary forms, with or without
 5  
 modification, are permitted provided that the following conditions are met:
 6  
     * Redistributions of source code must retain the above copyright
 7  
       notice, this list of conditions and the following disclaimer.
 8  
     * Redistributions in binary form must reproduce the above copyright
 9  
       notice, this list of conditions and the following disclaimer in the
 10  
       documentation and/or other materials provided with the distribution.
 11  
     * Neither the name of mattunderscore.com nor the
 12  
       names of its contributors may be used to endorse or promote products
 13  
       derived from this software without specific prior written permission.
 14  
 
 15  
 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 16  
 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 17  
 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 18  
 DISCLAIMED. IN NO EVENT SHALL MATTHEW CHAMPION BE LIABLE FOR ANY
 19  
 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 20  
 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 21  
 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 22  
 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 23  
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 24  
 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
 25  
 
 26  
 package com.mattunderscore.filter.contentnegotiation.parser;
 27  
 
 28  
 /**
 29  
  * The description of a redirect header returned by the content negotiation filter.
 30  
  * <P>
 31  
  * Used to configure responses.
 32  
  * 
 33  
  * @author Matt Champion
 34  
  * @since 0.0.13
 35  
  */
 36  
 public class Redirect
 37  
 {
 38  
 
 39  
     private static final int HASH_SEED = 13;
 40  
     private static final int HASH_MULT = 19;
 41  
 
 42  
     protected int code;
 43  
     protected String location;
 44  
 
 45  
     public Redirect()
 46  100
     {
 47  100
     }
 48  
 
 49  
     /**
 50  
      * Get the code of the redirect.
 51  
      * @return The code of the redirect
 52  
      * @since 0.0.13
 53  
      */
 54  
     public int getCode()
 55  
     {
 56  18
         return code;
 57  
     }
 58  
 
 59  
     /**
 60  
      * Set the code of the redirect.
 61  
      * @param value The code of the redirect
 62  
      * @since 0.0.13
 63  
      */
 64  
     public void setCode(int value)
 65  
     {
 66  64
         this.code = value;
 67  64
     }
 68  
 
 69  
     /**
 70  
      * Get the location of the redirect.
 71  
      * @return The location of the redirect
 72  
      * @since 0.0.13
 73  
      */
 74  
     public String getLocation()
 75  
     {
 76  18
         return location;
 77  
     }
 78  
 
 79  
     /**
 80  
      * Set the location of the redirect.
 81  
      * @param value The location of the redirect
 82  
      * @since 0.0.13
 83  
      */
 84  
     public void setLocation(String value)
 85  
     {
 86  64
         this.location = value;
 87  64
     }
 88  
 
 89  
     @Override
 90  
     public int hashCode()
 91  
     {
 92  208
         int hash = HASH_SEED;
 93  208
         hash = (hash * HASH_MULT) + code;
 94  208
         if (location != null)
 95  
         {
 96  80
             hash = (hash * HASH_MULT) + location.hashCode();
 97  
         }
 98  
         else
 99  
         {
 100  128
             hash = (hash * HASH_MULT) + 5;
 101  
         }
 102  208
         return hash;
 103  
     }
 104  
 
 105  
     @Override
 106  
     public boolean equals(Object o)
 107  
     {
 108  218
         if (o == null)
 109  
         {
 110  16
             return false;
 111  
         }
 112  202
         else if (o == this)
 113  
         {
 114  48
             return true;
 115  
         }
 116  154
         else if (o.getClass().equals(getClass()))
 117  
         {
 118  112
             final Redirect co = (Redirect)o;
 119  112
             if (this.location != null)
 120  
             {
 121  52
                 return this.code == co.code && this.location.equals(co.location);
 122  
             }
 123  
             else
 124  
             {
 125  60
                 return this.code == co.code && co.location == null;
 126  
             }
 127  
         }
 128  
         else
 129  
         {
 130  42
             return false;
 131  
         }
 132  
     }
 133  
 }