Coverage Report - org.dishevelled.iconbundle.impl.IconBundleKey
 
Classes in this File Line Coverage Branch Coverage Complexity
IconBundleKey
100%
34/34
100%
16/16
2.714
 
 1  
 /*
 2  
 
 3  
     dsh-iconbundle  Bundles of variants for icon images.
 4  
     Copyright (c) 2003-2013 held jointly by the individual authors.
 5  
 
 6  
     This library is free software; you can redistribute it and/or modify it
 7  
     under the terms of the GNU Lesser General Public License as published
 8  
     by the Free Software Foundation; either version 3 of the License, or (at
 9  
     your option) any later version.
 10  
 
 11  
     This library is distributed in the hope that it will be useful, but WITHOUT
 12  
     ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
 13  
     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
 14  
     License for more details.
 15  
 
 16  
     You should have received a copy of the GNU Lesser General Public License
 17  
     along with this library;  if not, write to the Free Software Foundation,
 18  
     Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
 19  
 
 20  
     > http://www.fsf.org/licensing/licenses/lgpl.html
 21  
     > http://www.opensource.org/licenses/lgpl-license.php
 22  
 
 23  
 */
 24  
 package org.dishevelled.iconbundle.impl;
 25  
 
 26  
 import org.dishevelled.iconbundle.IconSize;
 27  
 import org.dishevelled.iconbundle.IconState;
 28  
 import org.dishevelled.iconbundle.IconTextDirection;
 29  
 
 30  
 /**
 31  
  * A compound key of icon text direction, icon state,
 32  
  * and icon size.
 33  
  *
 34  
  * @author  Michael Heuer
 35  
  */
 36  
 final class IconBundleKey
 37  
 {
 38  
     /** Hash start. */
 39  
     private static final int HASH_START = 17;
 40  
 
 41  
     /** Hash factor. */
 42  
     private static final int HASH_FACTOR = 37;
 43  
 
 44  
     /** Icon text direction. */
 45  
     private final IconTextDirection direction;
 46  
 
 47  
     /** Icon state. */
 48  
     private final IconState state;
 49  
 
 50  
     /** Icon size. */
 51  
     private final IconSize size;
 52  
 
 53  
 
 54  
     /**
 55  
      * Create a new compound key with the specified
 56  
      * icon text direction, icon state, and icon size.
 57  
      *
 58  
      * @param direction icon text direction, must not be null
 59  
      * @param state icon state, must not be null
 60  
      * @param size icon size, must not be null
 61  
      */
 62  
     public IconBundleKey(final IconTextDirection direction,
 63  
                          final IconState state,
 64  
                          final IconSize size)
 65  2657
     {
 66  2657
         if (direction == null)
 67  
         {
 68  2
             throw new IllegalArgumentException("direction must not be null");
 69  
         }
 70  2655
         if (state == null)
 71  
         {
 72  2
             throw new IllegalArgumentException("state must not be null");
 73  
         }
 74  2653
         if (size == null)
 75  
         {
 76  2
             throw new IllegalArgumentException("size must not be null");
 77  
         }
 78  
 
 79  2651
         this.direction = direction;
 80  2651
         this.state = state;
 81  2651
         this.size = size;
 82  2651
     }
 83  
 
 84  
 
 85  
     /**
 86  
      * Return the icon text direction of this key.
 87  
      *
 88  
      * @return the icon text direction
 89  
      */
 90  
     public IconTextDirection getDirection()
 91  
     {
 92  2776
         return direction;
 93  
     }
 94  
 
 95  
     /**
 96  
      * Return the icon size of this key.
 97  
      *
 98  
      * @return the icon size
 99  
      */
 100  
     public IconSize getSize()
 101  
     {
 102  2762
         return size;
 103  
     }
 104  
 
 105  
     /**
 106  
      * Return the icon state of this key.
 107  
      *
 108  
      * @return the icon state
 109  
      */
 110  
     public IconState getState()
 111  
     {
 112  2768
         return state;
 113  
     }
 114  
 
 115  
     /** {@inheritDoc} */
 116  
     public int hashCode()
 117  
     {
 118  5165
         int result = HASH_START;
 119  5165
         result = HASH_FACTOR * result + direction.hashCode();
 120  5165
         result = HASH_FACTOR * result + state.hashCode();
 121  5165
         result = HASH_FACTOR * result + size.hashCode();
 122  5165
         return result;
 123  
     }
 124  
 
 125  
     /** {@inheritDoc} */
 126  
     public boolean equals(final Object o)
 127  
     {
 128  2571
         if (this == o)
 129  
         {
 130  1
             return true;
 131  
         }
 132  2570
         if (!(o instanceof IconBundleKey))
 133  
         {
 134  2
             return false;
 135  
         }
 136  
 
 137  2568
         IconBundleKey key = (IconBundleKey) o;
 138  
 
 139  2568
         return (direction.equals(key.getDirection()))
 140  
             && (state.equals(key.getState()))
 141  
             && (size.equals(key.getSize()));
 142  
     }
 143  
 
 144  
     /** {@inheritDoc} */
 145  
     public String toString()
 146  
     {
 147  42
         StringBuffer sb = new StringBuffer();
 148  42
         sb.append("key(");
 149  42
         sb.append(direction);
 150  42
         sb.append(", ");
 151  42
         sb.append(state);
 152  42
         sb.append(", ");
 153  42
         sb.append(size);
 154  42
         sb.append(")");
 155  42
         return sb.toString();
 156  
     }
 157  
 }