/* 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.nbr;

import etomica.atom.IAtom;

/**
 * @author andrew
 * Used for bonding potentials. The accept method returns true if the atoms are
 * adjacent in the list of atoms and they have the same parent. 
 */
public class CriterionBondedSimple extends CriterionAdapter {

    public CriterionBondedSimple(NeighborCriterion criterion) {
        super(criterion);
    }
    
    public void setBonded(boolean b) {
        isBonded = b;
    }
    public boolean isBonded() {
        return isBonded;
    }
    
    // always enforce intramolecularity
    public boolean accept(IAtom atom1, IAtom atom2) {
        int diff = atom1.getIndex() - atom2.getIndex();
        if (isBonded != (diff == 1 || diff == -1) 
                || (atom1.getParentGroup() != atom2.getParentGroup())) {
            return false;
        }
        return subCriterion.accept(atom1, atom2);
    }
    
    private static final long serialVersionUID = 1L;
    private boolean isBonded;
}

@@ -893,16 +893,17 @@
 nded != 
+(
 (diff ==
@@ -924,27 +924,10 @@
 -1) 
-%0A                %7C%7C
+&&
  (at
@@ -947,17 +947,17 @@
 Group() 
-!
+=
 = atom2.
@@ -974,16 +974,17 @@
 roup()))
+)
  %7B%0A     

Fix CriterionBondedSimple to be not broken