/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package etomica.box;

import etomica.molecule.IMolecule;
import etomica.molecule.IMoleculeList;

public class AtomSetAllMolecules implements IMoleculeList {

    private static final long serialVersionUID = 1L;
    protected IMoleculeList[] moleculeLists;
    protected int[] moleculeTotals;

    public AtomSetAllMolecules() {
        moleculeTotals = new int[1];
    }

    public IMolecule getMolecule(int i) {
        if (i >= getMoleculeCount() || i < 0)
            throw new IndexOutOfBoundsException("Index: " + i +
                    ", Number of molecules: " + getMoleculeCount());
        int nSpecies = moleculeLists.length;
        if (moleculeTotals[0] > i) {
            return moleculeLists[0].getMolecule(i);
        }
        for (int iSpecies = 1; iSpecies < nSpecies; iSpecies++) {
            if (moleculeTotals[iSpecies] > i) {
                return moleculeLists[iSpecies].getMolecule(i - moleculeTotals[iSpecies - 1]);
            }
        }
        throw new IllegalStateException("how can this be?!?!?!");
    }

    public int getMoleculeCount() {
        return moleculeTotals[moleculeTotals.length - 1];
    }

    public void setMoleculeLists(IMoleculeList[] newMoleculeLists) {
        moleculeLists = newMoleculeLists;
        if (moleculeTotals.length - 1 != moleculeLists.length) {
            moleculeTotals = new int[moleculeLists.length + 1];
        }
        if (moleculeLists.length == 0) {
            return;
        }
        moleculeTotals[0] = moleculeLists[0].getMoleculeCount();
        for (int i = 1; i < moleculeTotals.length - 1; i++) {
            moleculeTotals[i] = moleculeTotals[i - 1] + moleculeLists[i].getMoleculeCount();
        }
        moleculeTotals[moleculeTotals.length - 1] = moleculeTotals[moleculeTotals.length - 2];
    }
}

@@ -296,16 +296,354 @@
 eList;%0A%0A
+/**%0A * Creates a facade that makes a set of molecule lists look like a single list. This class is%0A * configured by calling setMoleculeLists(). This should be called after construction, every time%0A * one of the molecule lists in the set is changed by adding or removing a molecule, and when a%0A * list is added or removed from the set.%0A */%0A
 public c
@@ -699,61 +699,8 @@
  %7B%0A%0A
-    private static final long serialVersionUID = 1L;%0A
     
@@ -785,82 +785,446 @@
     
-public AtomSetAllMolecules() %7B%0A        moleculeTotals = new int%5B1%5D;%0A    %7D%0A
+/**%0A     * Constructs an empty list. Subsequent call to setMoleculeLists() is needed to configure this list.%0A     */%0A    public AtomSetAllMolecules() %7B%0A        moleculeTotals = new int%5B1%5D;%0A    %7D%0A%0A    /**%0A     * @param i specification of the desired molecule.%0A     * @return a molecule as ordered by the species and then the molecules within the species.%0A     * @throws IndexOutOfBoundsException if i %3E= getMoleculeCount() or i %3C 0%0A     */
 %0A   
@@ -1882,32 +1882,102 @@
 !?!?!%22);%0A    %7D%0A%0A
+    /**%0A     * @return total number of molecules in the list.%0A     */%0A
     public int g
@@ -2057,24 +2057,260 @@
  1%5D;%0A    %7D%0A%0A
+    /**%0A     * Configures this list based on the given array of lists. The ordering of this list is obtained by concatenating%0A     * the given lists.%0A     *%0A     * @param newMoleculeLists lists of molecules that form this list.%0A     */%0A
     public v

Add javadoc to AtomSetAllMolecules