package etomica.atom;

import etomica.Atom;
import etomica.AtomSet;


/**
 * AtomSet formed by wrapping an Atom array.
 */

/*
 * History
 * Created on Feb 18, 2005 by kofke
 */
public class AtomsetArray implements AtomSet {

    /**
     * Wraps a new atom array of the given length.
     */
    public AtomsetArray(int nAtoms) {
        atoms = new Atom[nAtoms];
    }
    
    /**
     * Wraps the given atom array.  Subsequent call to getArray
     * will return the array instance given here.
     */
    public AtomsetArray(Atom[] atoms) {
        this.atoms = atoms;
    }

    /**
     * Part of implementation of AtomSet interface.
     */
    public Atom getAtom(int i) {
        return atoms[i];
    }
    
    /**
     * @return the wrapped array of atoms, which is declared final in the class.
     */
    public Atom[] getArray() {
        return atoms;
    }
    
    /**
     * Copies the atoms in the given array to the wrapped, final array of atoms.
     */
    public void setAtoms(Atom[] newAtoms) {
        if(newAtoms.length != atoms.length) throw new IllegalArgumentException("Wrong size array");
        System.arraycopy(newAtoms, 0, this.atoms, 0, atoms.length);
    }

    /**
     * Returns the length of the wrapped array.
     */
    public int count() {
        return atoms.length;
    }

    /**
     * Returns true if elements of the wrapped array are equal
     * to those in the given atom set, with the comparison
     * performed element-by-element.
     */
    public boolean equals(AtomSet atoms) {
        if(atoms.count() != count()) return false;
        for(int i=0; i<this.atoms.length; i++) {
            if(this.atoms[i] != atoms.getAtom(i)) return false;
        }
        return true;
    }

    private final Atom[] atoms;
}

@@ -358,16 +358,531 @@
 Atoms%5D;%0A
+    %7D%0A    %0A    /**%0A     * Makes a new instance holding the atoms in the given atom set.%0A     */%0A    public AtomsetArray(AtomSet atomSet) %7B%0A        this(atomSet.count());%0A        for(int i=0; i%3Catoms.length; i++) %7B%0A            atoms%5Bi%5D = atomSet.getAtom(i);%0A        %7D%0A    %7D%0A    %0A    /**%0A     * Copy constructor, wrapping a new array unique to this instance%0A     * but holding the same atoms as the given atom set.%0A     */%0A    public AtomsetArray(AtomsetArray atomSet) %7B%0A        this((Atom%5B%5D)atomSet.atoms.clone());%0A%0A
     %7D%0A  
@@ -956,16 +956,16 @@
 etArray%0A
-
      * w
@@ -1476,16 +1476,127 @@
  atoms.%0A
+     * Throws IllegalArgumentException if length of array is not equal to count%0A     * field of this instance.%0A
      */%0A
@@ -1806,32 +1806,494 @@
 length);%0A    %7D%0A%0A
+    /**%0A     * Copies the atoms in the given atom set to the wrapped array of atoms.%0A     * Throws IllegalArgumentException if length of array is not equal to count%0A     * field of this instance.%0A     */%0A    public void setAtoms(AtomSet atomSet) %7B%0A        if(atomSet.count() != atoms.length) throw new IllegalArgumentException(%22Wrong size for atomSet%22);%0A        for(int i=0; i%3Catoms.length; i++) %7B%0A            atoms%5Bi%5D = atomSet.getAtom(i);%0A        %7D%0A    %7D%0A    %0A
     /**%0A     * R

add some new constructors, method to set atoms given an atomSet