Clover coverage report - Code Coverage for hivemind-lib release 1.0
Coverage timestamp: Wed Sep 22 2004 08:05:53 EDT
file stats: LOC: 91   Methods: 2
NCLOC: 46   Classes: 1
30 day Evaluation Version distributed via the Maven Jar Repository. Clover is not free. You have 30 days to evaluate it. Please visit http://www.thecortex.net/clover to obtain a licensed version of Clover
 
 Source file Conditionals Statements Methods TOTAL
FilterMethodAnalyzer.java 85% 88.5% 100% 87.5%
coverage coverage
 1   
 //  Copyright 2004 The Apache Software Foundation
 2   
 //
 3   
 // Licensed under the Apache License, Version 2.0 (the "License");
 4   
 // you may not use this file except in compliance with the License.
 5   
 // You may obtain a copy of the License at
 6   
 //
 7   
 //     http://www.apache.org/licenses/LICENSE-2.0
 8   
 //
 9   
 // Unless required by applicable law or agreed to in writing, software
 10   
 // distributed under the License is distributed on an "AS IS" BASIS,
 11   
 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 12   
 // See the License for the specific language governing permissions and
 13   
 // limitations under the License.
 14   
 
 15   
 package org.apache.hivemind.lib.pipeline;
 16   
 
 17   
 import org.apache.hivemind.service.MethodSignature;
 18   
 
 19   
 /**
 20   
  * Used by {@link org.apache.hivemind.lib.pipeline.PipelineAssembler} 
 21   
  * to analyze service interface methods against filter interface methods
 22   
  * to find the position of the extra service parameter (in the filter method).
 23   
  *
 24   
  * @author Howard Lewis Ship
 25   
  */
 26   
 class FilterMethodAnalyzer
 27   
 {
 28   
     private Class _serviceInterface;
 29   
 
 30  15
     FilterMethodAnalyzer(Class serviceInterface)
 31   
     {
 32  15
         _serviceInterface = serviceInterface;
 33   
     }
 34   
 
 35  13
     public int findServiceInterfacePosition(MethodSignature ms, MethodSignature fms)
 36   
     {
 37  13
         if (ms.getReturnType() != fms.getReturnType())
 38  1
             return -1;
 39   
 
 40  12
         if (!ms.getName().equals(fms.getName()))
 41  0
             return -1;
 42   
 
 43  12
         Class[] filterParameters = fms.getParameterTypes();
 44  12
         int filterParameterCount = filterParameters.length;
 45  12
         Class[] serviceParameters = ms.getParameterTypes();
 46   
 
 47  12
         if (filterParameterCount != (serviceParameters.length + 1))
 48  1
             return -1;
 49   
 
 50   
         // TODO: check compatible exceptions!
 51   
 
 52   
         // This needs work; it assumes the first occurance of the service interface
 53   
         // in the filter interface method signature is the right match. That will suit
 54   
         // most of the time.
 55   
 
 56  11
         boolean found = false;
 57  11
         int result = -1;
 58   
 
 59  11
         for (int i = 0; i < filterParameterCount; i++)
 60   
         {
 61  21
             if (filterParameters[i] == _serviceInterface)
 62   
             {
 63  10
                 result = i;
 64  10
                 found = true;
 65  10
                 break;
 66   
             }
 67   
         }
 68   
 
 69  11
         if (!found)
 70  1
             return -1;
 71   
 
 72   
         // Check that all the parameters before and after the service interface still
 73   
         // match.
 74   
 
 75  10
         for (int i = 0; i < result; i++)
 76   
         {
 77  10
             if (filterParameters[i] != serviceParameters[i])
 78  0
                 return -1;
 79   
         }
 80   
 
 81  10
         for (int i = result + 1; i < filterParameterCount; i++)
 82   
         {
 83  2
             if (filterParameters[i] != serviceParameters[i - 1])
 84  0
                 return -1;
 85   
         }
 86   
 
 87  10
         return result;
 88   
     }
 89   
 
 90   
 }
 91