Clover coverage report - JGAP 3.1
Coverage timestamp: Mo Dez 11 2006 21:16:18 CET
file stats: LOC: 151   Methods: 10
NCLOC: 58   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ChainOfSelectors.java 100% 100% 100% 100%
coverage
 1    /*
 2    * This file is part of JGAP.
 3    *
 4    * JGAP offers a dual license model containing the LGPL as well as the MPL.
 5    *
 6    * For licencing information please see the file license.txt included with JGAP
 7    * or have a look at the top of class org.jgap.Chromosome which representatively
 8    * includes the JGAP license policy applicable for any file delivered with JGAP.
 9    */
 10    package org.jgap.impl;
 11   
 12    import java.util.*;
 13    import org.jgap.*;
 14   
 15    /**
 16    * Ordered chain of NaturalSelectors. With this container you can plugin
 17    * NaturalSelector implementations which will be performed either before (pre-)
 18    * or after (post-selectors) registered genetic operations have been applied.
 19    * @see Genotype
 20    * @see Configuration
 21    *
 22    * @author Klaus Meffert
 23    * @since 1.1
 24    */
 25    public class ChainOfSelectors
 26    implements java.io.Serializable {
 27    /** String containing the CVS revision. Read out via reflection!*/
 28    private final static String CVS_REVISION = "$Revision: 1.11 $";
 29   
 30    /**
 31    * Ordered list holding the NaturalSelector's.
 32    * Intentionally used as a decorator and not via inheritance!
 33    */
 34    private List m_selectors;
 35   
 36  7373 public ChainOfSelectors() {
 37  7373 m_selectors = new Vector();
 38    }
 39   
 40    /**
 41    * Adds a natural selector to the chain
 42    * @param a_selector the selector to be added
 43    * @throws InvalidConfigurationException
 44    *
 45    * @author Klaus Meffert
 46    * @since 1.1 (previously part of class Configuration)
 47    */
 48  3547 public void addNaturalSelector(NaturalSelector a_selector)
 49    throws InvalidConfigurationException {
 50  3547 if (a_selector == null) {
 51  1 throw new InvalidConfigurationException(
 52    "This Configuration object is locked. Settings may not be " +
 53    "altered.");
 54    }
 55  3546 m_selectors.add(a_selector);
 56    }
 57   
 58    /**
 59    *
 60    * @param a_c Collection to add all elements from
 61    * @throws InvalidConfigurationException
 62    *
 63    * @author Klaus Meffert
 64    * @since 1.1
 65    */
 66  2 public void addAll(Collection a_c)
 67    throws InvalidConfigurationException {
 68  2 Iterator it = a_c.iterator();
 69  2 while (it.hasNext()) {
 70  4 NaturalSelector selector = (NaturalSelector) it.next();
 71  4 addNaturalSelector(selector);
 72    }
 73    }
 74   
 75    /**
 76    * @return number of selectors in list
 77    *
 78    * @author Klaus Meffert
 79    * @since 1.1 (previously part of class Configuration)
 80    */
 81  4648 public int size() {
 82  4648 return m_selectors.size();
 83    }
 84   
 85    /**
 86    * @return true if number of selectors is zero
 87    *
 88    * @author Klaus Meffert
 89    * @since 1.1
 90    */
 91  5 public boolean isEmpty() {
 92  5 return size() == 0;
 93    }
 94   
 95  8 public int hashCode() {
 96  8 return m_selectors.hashCode();
 97    }
 98   
 99    /**
 100    *
 101    * @param a_obj Object
 102    * @return boolean
 103    *
 104    * @author Klaus Meffert
 105    * @since 1.1
 106    */
 107  6 public boolean equals(final Object a_obj) {
 108  6 try {
 109  6 ChainOfSelectors c2 = (ChainOfSelectors) a_obj;
 110  5 if (c2 == null) {
 111  1 return false;
 112    }
 113  4 return m_selectors.equals(c2.m_selectors);
 114    }
 115    catch (ClassCastException cex) {
 116  1 return false;
 117    }
 118    }
 119   
 120    /**
 121    * Returns a Selector with specific index in the list
 122    * @param a_index the index of the Selector to read from the list
 123    * @return NaturalSelector
 124    *
 125    * @author Klaus Meffert
 126    * @since 1.1
 127    */
 128  74 public NaturalSelector get(final int a_index) {
 129  74 return (NaturalSelector) m_selectors.get(a_index);
 130    }
 131   
 132    /**
 133    *
 134    * @author Klaus Meffert
 135    * @since 1.1
 136    *
 137    */
 138  8 public void clear() {
 139  8 m_selectors.clear();
 140    }
 141   
 142    /**
 143    * @return Iterator for iterating over list of selectors
 144    *
 145    * @author Klaus Meffert
 146    * @since 1.1
 147    */
 148  1 public Iterator iterator() {
 149  1 return m_selectors.iterator();
 150    }
 151    }