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-2011 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  
  * @version $Revision: 974 $ $Date: 2011-01-04 21:40:23 -0600 (Tue, 04 Jan 2011) $
 36  
  */
 37  
 final class IconBundleKey
 38  
 {
 39  
     /** Hash start. */
 40  
     private static final int HASH_START = 17;
 41  
 
 42  
     /** Hash factor. */
 43  
     private static final int HASH_FACTOR = 37;
 44  
 
 45  
     /** Icon text direction. */
 46  
     private final IconTextDirection direction;
 47  
 
 48  
     /** Icon state. */
 49  
     private final IconState state;
 50  
 
 51  
     /** Icon size. */
 52  
     private final IconSize size;
 53  
 
 54  
 
 55  
     /**
 56  
      * Create a new compound key with the specified
 57  
      * icon text direction, icon state, and icon size.
 58  
      *
 59  
      * @param direction icon text direction, must not be null
 60  
      * @param state icon state, must not be null
 61  
      * @param size icon size, must not be null
 62  
      */
 63  
     public IconBundleKey(final IconTextDirection direction,
 64  
                          final IconState state,
 65  
                          final IconSize size)
 66  2657
     {
 67  2657
         if (direction == null)
 68  
         {
 69  2
             throw new IllegalArgumentException("direction must not be null");
 70  
         }
 71  2655
         if (state == null)
 72  
         {
 73  2
             throw new IllegalArgumentException("state must not be null");
 74  
         }
 75  2653
         if (size == null)
 76  
         {
 77  2
             throw new IllegalArgumentException("size must not be null");
 78  
         }
 79  
 
 80  2651
         this.direction = direction;
 81  2651
         this.state = state;
 82  2651
         this.size = size;
 83  2651
     }
 84  
 
 85  
 
 86  
     /**
 87  
      * Return the icon text direction of this key.
 88  
      *
 89  
      * @return the icon text direction
 90  
      */
 91  
     public IconTextDirection getDirection()
 92  
     {
 93  2776
         return direction;
 94  
     }
 95  
 
 96  
     /**
 97  
      * Return the icon size of this key.
 98  
      *
 99  
      * @return the icon size
 100  
      */
 101  
     public IconSize getSize()
 102  
     {
 103  2762
         return size;
 104  
     }
 105  
 
 106  
     /**
 107  
      * Return the icon state of this key.
 108  
      *
 109  
      * @return the icon state
 110  
      */
 111  
     public IconState getState()
 112  
     {
 113  2768
         return state;
 114  
     }
 115  
 
 116  
     /** {@inheritDoc} */
 117  
     public int hashCode()
 118  
     {
 119  5118
         int result = HASH_START;
 120  5118
         result = HASH_FACTOR * result + direction.hashCode();
 121  5118
         result = HASH_FACTOR * result + state.hashCode();
 122  5118
         result = HASH_FACTOR * result + size.hashCode();
 123  5118
         return result;
 124  
     }
 125  
 
 126  
     /** {@inheritDoc} */
 127  
     public boolean equals(final Object o)
 128  
     {
 129  2571
         if (this == o)
 130  
         {
 131  1
             return true;
 132  
         }
 133  2570
         if (!(o instanceof IconBundleKey))
 134  
         {
 135  2
             return false;
 136  
         }
 137  
 
 138  2568
         IconBundleKey key = (IconBundleKey) o;
 139  
 
 140  2568
         return (direction.equals(key.getDirection()))
 141  
             && (state.equals(key.getState()))
 142  
             && (size.equals(key.getSize()));
 143  
     }
 144  
 
 145  
     /** {@inheritDoc} */
 146  
     public String toString()
 147  
     {
 148  42
         StringBuffer sb = new StringBuffer();
 149  42
         sb.append("key(");
 150  42
         sb.append(direction);
 151  42
         sb.append(", ");
 152  42
         sb.append(state);
 153  42
         sb.append(", ");
 154  42
         sb.append(size);
 155  42
         sb.append(")");
 156  42
         return sb.toString();
 157  
     }
 158  
 }