Coverage Report - com.mattunderscore.http.headers.useragent.details.BaseUserAgentDetail
 
Classes in this File Line Coverage Branch Coverage Complexity
BaseUserAgentDetail
75%
18/24
41%
5/12
2.125
 
 1  
 /* Copyright © 2013 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.http.headers.useragent.details;
 27  
 
 28  
 /**
 29  
  * Provide a default implementation of a user agent detail. This provides basic get functionality
 30  
  * and equals and hashCode methods.
 31  
  * @author Matt Champion
 32  
  * @since 0.2.6
 33  
  */
 34  
 public abstract class BaseUserAgentDetail implements UserAgentDetail
 35  
 {
 36  
     private static final int HASH_SEED = 11;
 37  
     private static final int HASH_MULT = 3;
 38  
 
 39  
     protected final String name;
 40  
     protected final String version;
 41  
 
 42  
     /**
 43  
      * Constructor for a detail with a name and version.
 44  
      * @param name
 45  
      * @param version
 46  
      */
 47  
     protected BaseUserAgentDetail(String name, String version)
 48  438
     {
 49  438
         this.name = name;
 50  438
         this.version = version;
 51  438
     }
 52  
 
 53  
     /**
 54  
      * Constructor for a detail with a name.
 55  
      * @param name
 56  
      */
 57  
     protected BaseUserAgentDetail(String name)
 58  
     {
 59  130
         this(name,"");
 60  130
     }
 61  
 
 62  
     @Override
 63  
     public final String name()
 64  
     {
 65  250
         return name;
 66  
     }
 67  
 
 68  
     @Override
 69  
     public final String version()
 70  
     {
 71  150
         return version;
 72  
     }
 73  
 
 74  
     @Override
 75  
     public abstract String detailType();
 76  
 
 77  
     @Override
 78  
     public String toString()
 79  
     {
 80  0
         if ("".equals(version))
 81  
         {
 82  0
             return detailType() + ": " + name;
 83  
         }
 84  
         else
 85  
         {
 86  0
             return detailType() + ": " + name + " " + version;
 87  
         }
 88  
     }
 89  
 
 90  
     @Override
 91  
     public int hashCode()
 92  
     {
 93  438
         int hashCode = HASH_SEED;
 94  438
         hashCode = (hashCode * HASH_MULT) + name.hashCode();
 95  438
         hashCode = (hashCode * HASH_MULT) + version.hashCode();
 96  438
         return hashCode;
 97  
     }
 98  
 
 99  
     @Override
 100  
     public boolean equals(Object o)
 101  
     {
 102  18
         if (o == null)
 103  
         {
 104  0
             return false;
 105  
         }
 106  18
         else if (o ==this)
 107  
         {
 108  0
             return true;
 109  
         }
 110  18
         else if (this.getClass().equals(o.getClass()))
 111  
         {
 112  18
             final BaseUserAgentDetail detail = (BaseUserAgentDetail)o;
 113  18
             return name.equals(detail.name)
 114  18
                     && version.equals(detail.version);
 115  
         }
 116  
         else
 117  
         {
 118  0
             return false;
 119  
         }
 120  
     }
 121  
 }