Clover coverage report - JGAP 3.1
Coverage timestamp: Mo Dez 11 2006 21:16:18 CET
file stats: LOC: 103   Methods: 7
NCLOC: 49   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
PopulationHistory.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.eval;
 11   
 12    import java.util.*;
 13    import org.jgap.*;
 14   
 15    /**
 16    * Container for holding a given number of populations. Serves as a history
 17    * object for later evaluation
 18    *
 19    * @author Klaus Meffert
 20    * @since 2.0
 21    */
 22    public class PopulationHistory {
 23    /** String containing the CVS revision. Read out via reflection!*/
 24    private final static String CVS_REVISION = "$Revision: 1.4 $";
 25   
 26    private List m_populations;
 27   
 28    private int m_maxSize;
 29   
 30    /**
 31    * Constructor.
 32    * @param a_maxSize the maximum number of Population objects to hold, or
 33    * zero if there is no limit.
 34    * @author Klaus Meffert
 35    * @since 2.0
 36    */
 37  14 public PopulationHistory(final int a_maxSize) {
 38  14 m_populations = new Vector();
 39  14 if (a_maxSize < 0) {
 40  1 throw new IllegalArgumentException("Maximum size must be greater"
 41    + " or equal to zero!");
 42    }
 43  13 m_maxSize = a_maxSize;
 44    }
 45   
 46  8 public Population getPopulation(final int a_count) {
 47  8 if (a_count >= m_populations.size()) {
 48  1 return null;
 49    }
 50    else {
 51  7 return (Population) m_populations.get(a_count);
 52    }
 53    }
 54   
 55    /**
 56    * Adds a population to the history. If the maximum size of this container
 57    * is exceeded after that then the oldest population added is removed
 58    * @param a_population the population to be added
 59    *
 60    * @author Klaus Meffert
 61    * @since 2.0
 62    */
 63  18 public void addPopulation(final Population a_population) {
 64  18 m_populations.add(0, a_population);
 65  18 int popSize = m_populations.size();
 66  18 if (m_maxSize != 0 && popSize > m_maxSize) {
 67  2 m_populations.remove(popSize - 1);
 68    }
 69    }
 70   
 71    /**
 72    * @author Klaus Meffert
 73    * @since 2.0
 74    */
 75  2 public void removeAllPopulations() {
 76  2 m_populations.removeAll(m_populations);
 77    }
 78   
 79  16 public int size() {
 80  16 return m_populations.size();
 81    }
 82   
 83  2 public List getPopulations() {
 84  2 return m_populations;
 85    }
 86   
 87    /**
 88    * Sets the list of populations to the list provided.
 89    * @param a_populations list of populations to be set
 90    *
 91    * @author Klaus Meffert
 92    * @since 2.0
 93    */
 94  2 public void setPopulations(final List a_populations) {
 95  2 m_populations = a_populations;
 96  2 int popSize = m_populations.size();
 97  2 if (m_maxSize != 0 && popSize > m_maxSize) {
 98  1 for (int i = m_maxSize; i < popSize; i++) {
 99  1 m_populations.remove(m_maxSize);
 100    }
 101    }
 102    }
 103    }