Coverage Report - com.mattunderscore.filter.contentnegotiation.parser.HeaderPart
 
Classes in this File Line Coverage Branch Coverage Complexity
HeaderPart
100%
37/37
96%
29/30
3.286
 
 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  
  * A header field element returned as part of the header 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 HeaderPart
 37  
 {
 38  
 
 39  
     private static final int HASH_SEED = 7;
 40  
     private static final int HASH_MULT = 19;
 41  
 
 42  
     protected String name;
 43  
     protected String value;
 44  
 
 45  
     public HeaderPart()
 46  118
     {
 47  118
     }
 48  
     
 49  
     /**
 50  
      * Get the name of the header element
 51  
      * @return The name of the header element
 52  
      * @since 0.0.13
 53  
      */
 54  
     public String getName()
 55  
     {
 56  16
         return name;
 57  
     }
 58  
 
 59  
     /**
 60  
      * Set the name of the header element
 61  
      * @param name The name of the header element
 62  
      * @since 0.0.13
 63  
      */
 64  
     public void setName(final String name)
 65  
     {
 66  82
         this.name = name;
 67  82
     }
 68  
 
 69  
     /**
 70  
      * Get the value of the header element
 71  
      * @return The value of the header element
 72  
      * @since 0.0.13
 73  
      */
 74  
     public String getValue()
 75  
     {
 76  16
         return value;
 77  
     }
 78  
 
 79  
     /**
 80  
      * Set the value of the header element
 81  
      * @param value The value of the header element
 82  
      * @since 0.0.13
 83  
      */
 84  
     public void setValue(final String value)
 85  
     {
 86  70
         this.value = value;
 87  70
     }
 88  
 
 89  
     @Override
 90  
     public int hashCode()
 91  
     {
 92  268
         int hash = HASH_SEED;
 93  268
         if (name != null)
 94  
         {
 95  156
             hash = (hash * HASH_MULT) + name.hashCode();
 96  
         }
 97  
         else
 98  
         {
 99  112
             hash = (hash * HASH_MULT) + 3;
 100  
         }
 101  268
         if (value != null)
 102  
         {
 103  100
             hash = (hash * HASH_MULT) + value.hashCode();
 104  
         }
 105  
         else
 106  
         {
 107  168
             hash = (hash * HASH_MULT) + 7;
 108  
         }
 109  268
         return hash;
 110  
     }
 111  
 
 112  
     @Override
 113  
     public boolean equals(final Object o)
 114  
     {
 115  404
         if (o == null)
 116  
         {
 117  8
             return false;
 118  
         }
 119  396
         else if (o == this)
 120  
         {
 121  82
             return true;
 122  
         }
 123  314
         else if (o.getClass().equals(getClass()))
 124  
         {
 125  252
             final HeaderPart co = (HeaderPart)o;
 126  252
             boolean allEqual = true;
 127  252
             if (this.name != null)
 128  
             {
 129  166
                 if (co.name != null)
 130  
                 {
 131  134
                     allEqual = allEqual && this.name.equals(co.name);
 132  
                 }
 133  
                 else
 134  
                 {
 135  32
                     allEqual = false;
 136  
                 }
 137  
             }
 138  86
             else if (co.name != null)
 139  
             {
 140  48
                 allEqual = false;
 141  
             }
 142  252
             if (this.value != null)
 143  
             {
 144  158
                 if (co.value != null)
 145  
                 {
 146  134
                     allEqual = allEqual && this.value.equals(co.value);
 147  
                 }
 148  
                 else
 149  
                 {
 150  24
                     allEqual = false;
 151  
                 }
 152  
             }
 153  94
             else if (co.value != null)
 154  
             {
 155  56
                 allEqual = false;
 156  
             }
 157  252
             return allEqual;
 158  
         }
 159  
         else
 160  
         {
 161  62
             return false;
 162  
         }
 163  
     }
 164  
 
 165  
 }