001 package org.jaga.util;
002
003 import java.util.ArrayList;
004 import org.jaga.definitions.*;
005
006 /**
007 * TODO: Complete these comments.
008 *
009 * <p><u>Project:</u> JAGA - Java API for Genetic Algorithms.</p>
010 *
011 * <p><u>Company:</u> University College London and JAGA.Org
012 * (<a href="http://www.jaga.org" target="_blank">http://www.jaga.org</a>).
013 * </p>
014 *
015 * <p><u>Copyright:</u> (c) 2004 by G. Paperin.<br/>
016 * This program is free software; you can redistribute it and/or modify
017 * it under the terms of the GNU General Public License as published by
018 * the Free Software Foundation, ONLY if you include a note of the original
019 * author(s) in any redistributed/modified copy.<br/>
020 * This program is distributed in the hope that it will be useful,
021 * but WITHOUT ANY WARRANTY; without even the implied warranty of
022 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023 * GNU General Public License for more details.<br/>
024 * You should have received a copy of the GNU General Public License
025 * along with this program; if not, write to the Free Software
026 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
027 * or see http://www.gnu.org/licenses/gpl.html</p>
028 *
029 * @author Greg Paperin (greg@jaga.org)
030 *
031 * @version JAGA public release 1.0 beta
032 */
033
034 public class SimpleCollectionOfIndividuals implements Population {
035
036 private ArrayList individuals = null;
037
038 public SimpleCollectionOfIndividuals() {
039 individuals = new ArrayList();
040 }
041
042 public int getSize() {
043 return individuals.size();
044 }
045
046 public void addAll(Individual [] individuals) {
047 for (int i = 0; i < individuals.length; add(individuals[i++]));
048 }
049
050 public void add(Individual individual) {
051 individuals.add(individual);
052 }
053
054 public Individual [] getAllMembers() {
055 Individual [] members = new Individual[this.individuals.size()];
056 this.individuals.toArray(members);
057 return members;
058 }
059
060 public Individual getMember(int index) {
061 if (index < 0 || individuals.size() <= index)
062 throw new IndexOutOfBoundsException("Member index must be in [0, "
063 + getSize() + "], but is " + index);
064 return (Individual) individuals.get(index);
065 }
066
067 }