Clover coverage report -
Coverage timestamp: Sun Feb 29 2004 21:42:04 CET
file stats: LOC: 98   Methods: 5
NCLOC: 56   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ClassSelector.java 91.7% 95.5% 100% 94.9%
coverage coverage
 1   
 /* ====================================================================
 2   
  The Jicarilla Software License
 3   
 
 4   
  Copyright (c) 2003 Leo Simons.
 5   
  All rights reserved.
 6   
 
 7   
  Permission is hereby granted, free of charge, to any person obtaining
 8   
  a copy of this software and associated documentation files (the
 9   
  "Software"), to deal in the Software without restriction, including
 10   
  without limitation the rights to use, copy, modify, merge, publish,
 11   
  distribute, sublicense, and/or sell copies of the Software, and to
 12   
  permit persons to whom the Software is furnished to do so, subject to
 13   
  the following conditions:
 14   
 
 15   
  The above copyright notice and this permission notice shall be
 16   
  included in all copies or substantial portions of the Software.
 17   
 
 18   
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 19   
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 20   
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 21   
  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 22   
  CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 23   
  TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 24   
  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 25   
 ==================================================================== */
 26   
 package org.jicarilla.container.selectors;
 27   
 
 28   
 import org.jicarilla.container.util.ReflectionUtil;
 29   
 import org.jicarilla.framework.Assert;
 30   
 import org.jicarilla.framework.CriterionExposingSelector;
 31   
 
 32   
 /**
 33   
  * @author <a href="lsimons at jicarilla dot org">Leo Simons</a>
 34   
  * @version $Id: ClassSelector.java,v 1.5 2004/01/10 10:14:11 lsimons Exp $
 35   
  */
 36   
 public class ClassSelector implements CriterionExposingSelector
 37   
 {
 38   
     protected final Class m_class;
 39   
 
 40  466
     public ClassSelector( final Class clazz )
 41   
     {
 42  466
         Assert.assertNotNull( "clazz argument may not be null", clazz );
 43  463
         m_class = clazz;
 44   
     }
 45   
 
 46  5714
     public boolean select( final Object object )
 47   
     {
 48  5714
         if( object == null )
 49  1
             return false;
 50   
 
 51  5713
         if( object instanceof Class )
 52   
         {
 53  3968
             final Class clazz = (Class)object;
 54  3968
             return clazz.isAssignableFrom( m_class );
 55   
         }
 56   
 
 57  1745
         if( object instanceof String )
 58   
         {
 59  774
             try
 60   
             {
 61  774
                 final Class clazz = ReflectionUtil.loadClass( (String)object );
 62  618
                 return clazz.isAssignableFrom( m_class );
 63   
             }
 64   
             catch( ClassNotFoundException e )
 65   
             {
 66  156
                 return String.class.isAssignableFrom( m_class );
 67   
             }
 68   
         }
 69   
 
 70  971
         return false;
 71   
     }
 72   
 
 73  217
     public Object getCriterion()
 74   
     {
 75  217
         return m_class;
 76   
     }
 77   
 
 78  51
     public boolean equals( final Object o )
 79   
     {
 80  51
         if( o == this )
 81  6
             return true;
 82   
 
 83  45
         if( !(o instanceof ClassSelector) )
 84  21
             return false;
 85   
 
 86  24
         return getCriterion().equals(
 87   
                 ((ClassSelector)o).getCriterion() );
 88   
     }
 89   
 
 90  83
     public int hashCode()
 91   
     {
 92  83
         if( getCriterion() == null )
 93  0
             return 50;
 94   
         else
 95  83
             return getCriterion().hashCode() + 50;
 96   
     }
 97   
 }
 98