Coverage Report - org.apache.commons.betwixt.strategy.impl.OverrideCollectiveTypeStategy

Classes in this File Line Coverage Branch Coverage Complexity
OverrideCollectiveTypeStategy
0% 
0% 
1.4

 1  
 /*
 2  
  * Copyright 2005 The Apache Software Foundation.
 3  
  * 
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  * 
 8  
  *      http://www.apache.org/licenses/LICENSE-2.0
 9  
  * 
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */ 
 16  
 package org.apache.commons.betwixt.strategy.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collection;
 20  
 
 21  
 import org.apache.commons.betwixt.strategy.CollectiveTypeStrategy;
 22  
 
 23  
 /**
 24  
  * Strategy that allows specific classes to be marked as 
 25  
  * collective ({@link #overrideCollective(Class)})
 26  
  * or not collective ({@link #overrideNotCollective(Class)})
 27  
  */
 28  
 public class OverrideCollectiveTypeStategy extends CollectiveTypeStrategy {
 29  
 
 30  
     private final CollectiveTypeStrategy delegate;
 31  
     
 32  
     private final Collection collectiveClasses;
 33  
     private final Collection notCollectiveClasses;
 34  
     
 35  
     /**
 36  
      * Constructs a strategy which delegates to CollectiveTypeStrategy#DEFAULT
 37  
      *
 38  
      */
 39  
     public OverrideCollectiveTypeStategy() {
 40  0
         this(CollectiveTypeStrategy.DEFAULT);
 41  0
     }
 42  
     
 43  
     /**
 44  
      * Constructs a strategy which delegates all those that it does not override.
 45  
      * @param delegate
 46  
      */
 47  
     public OverrideCollectiveTypeStategy(CollectiveTypeStrategy delegate) {
 48  0
         super();
 49  0
         this.delegate = delegate;
 50  0
         collectiveClasses = new ArrayList();
 51  0
         notCollectiveClasses = new ArrayList();
 52  0
     }
 53  
 
 54  
     /**
 55  
      * Marks the given type to be treated as collective.
 56  
      * @param type <code>Class</code>, not null
 57  
      */
 58  
     public void overrideCollective(Class type) {
 59  0
         collectiveClasses.add(type);
 60  0
     }
 61  
 
 62  
     /**
 63  
      * Marks the given type to be treated as not collective
 64  
      * @param type
 65  
      */
 66  
     public void overrideNotCollective(Class type) {
 67  0
         notCollectiveClasses.add(type);
 68  0
     }
 69  
     
 70  
     /**
 71  
      * @see CollectiveTypeStrategy#isCollective(Class)
 72  
      */
 73  
     public boolean isCollective(Class type) {
 74  0
         boolean result = delegate.isCollective(type);
 75  0
         if (collectiveClasses.contains(type)) {
 76  0
             result = true;
 77  0
         } else if (notCollectiveClasses.contains(type)) {
 78  0
             result = false;
 79  
         }
 80  0
         return result;
 81  
     }
 82  
 
 83  
 }