Skip to content

Commit

Permalink
Revert "Add a new method atom::getBond(), that allows testing as to w…
Browse files Browse the repository at this point in the history
…hether two atoms are connected outside of the AtomContainer."

This reverts commit c05819d.
  • Loading branch information
egonw committed Feb 18, 2018
1 parent e67ed6a commit 505a588
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 108 deletions.
8 changes: 0 additions & 8 deletions base/core/src/main/java/org/openscience/cdk/AtomRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,14 +402,6 @@ public int getBondCount() {
return atom.getBondCount();
}

/**
* {@inheritDoc}
*/
@Override
public IBond getBond(IAtom atom) {
return this.atom.getBond(atom);
}

/**
* {@inheritDoc}
*/
Expand Down
8 changes: 0 additions & 8 deletions base/data/src/main/java/org/openscience/cdk/Atom.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,14 +269,6 @@ public int getBondCount() {
throw new UnsupportedOperationException();
}

/**
* {@inheritDoc}
*/
@Override
public IBond getBond(IAtom atom) {
throw new UnsupportedOperationException();
}

/**
* Sets the partial charge of this atom.
*
Expand Down
21 changes: 9 additions & 12 deletions base/data/src/main/java/org/openscience/cdk/AtomContainer2.java
Original file line number Diff line number Diff line change
Expand Up @@ -621,8 +621,15 @@ public IElectronContainer getElectronContainer(int number) {
*/
@Override
public IBond getBond(IAtom beg, IAtom end) {
final AtomRef begref = getAtomRefUnsafe(beg);
return begref != null ? begref.getBond(end) : null;
AtomRef begref = getAtomRefUnsafe(beg);
AtomRef endref = getAtomRefUnsafe(end);
if (begref != null && endref != null) {
for (IBond bond : begref.bonds()) {
if (bond.getOther(begref) == endref)
return bond;
}
}
return null;
}

/**
Expand Down Expand Up @@ -1653,16 +1660,6 @@ public final Iterable<IBond> bonds() {
return bonds;
}

@Override
public IBond getBond(IAtom atom) {
for (IBond bond : bonds) {
if (bond.getBegin().equals(atom) ||
bond.getEnd().equals(atom))
return bond;
}
return null;
}

@Override
public int hashCode() {
return deref().hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
import org.openscience.cdk.interfaces.ILonePair;
import org.openscience.cdk.interfaces.ITestObjectBuilder;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

/**
* Checks the functionality of the AtomContainer.
*
Expand Down Expand Up @@ -115,25 +111,4 @@ public void testAtomContainer_IAtomContainer() {
Assert.assertEquals(4, container.getAtomCount());
Assert.assertEquals(3, container.getBondCount());
}

@Test
public void testAtomGetBond() {
IAtomContainer mol = (IAtomContainer) newChemObject();
IAtom a1 = mol.getBuilder().newAtom();
IAtom a2 = mol.getBuilder().newAtom();
IAtom a3 = mol.getBuilder().newAtom();
a1.setSymbol("CH3");
a2.setSymbol("CH2");
a3.setSymbol("OH");
mol.addAtom(a1);
mol.addAtom(a2);
mol.addAtom(a3);
mol.addBond(0, 1, IBond.Order.SINGLE);
mol.addBond(1, 2, IBond.Order.SINGLE);
assertThat(mol.getBond(0),
is(mol.getAtom(0).getBond(mol.getAtom(1))));
assertThat(mol.getBond(1),
is(mol.getAtom(1).getBond(mol.getAtom(2))));
assertNull(mol.getAtom(0).getBond(mol.getAtom(2)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -204,21 +204,8 @@ public interface IAtom extends IAtomType {
*/
Iterable<IBond> bonds();

/**
* Get the number of explicit bonds connected to this atom.
* @return the total bond count
*/
int getBondCount();

/**
* Returns the bond connecting 'this' atom to the provided atom. If the
* atoms are not bonded, null is return
* @param atom the other atom
* @return the bond connecting the atoms
* @throws UnsupportedOperationException thrown if the bonds are not known
*/
IBond getBond(IAtom atom);

/**
* Access whether this atom has been marked as aromatic. The default
* value is false and you must explicitly perceive aromaticity with
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,6 @@ public Iterable<IBond> bonds() {
throw new UnsupportedOperationException();
}

/**
* {@inheritDoc}
*/
@Override
public IBond getBond(IAtom atom) {
throw new UnsupportedOperationException();
}

/**
* Sets the partial charge of this atom.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,15 @@ public IElectronContainer getElectronContainer(int number) {
*/
@Override
public IBond getBond(IAtom beg, IAtom end) {
final AtomRef begref = getAtomRefUnsafe(beg);
return begref != null ? begref.getBond(end) : null;
AtomRef begref = getAtomRefUnsafe(beg);
AtomRef endref = getAtomRefUnsafe(end);
if (begref != null && endref != null) {
for (IBond bond : begref.bonds()) {
if (bond.getOther(begref) == endref)
return bond;
}
}
return null;
}

/**
Expand Down Expand Up @@ -1615,16 +1622,6 @@ public final Iterable<IBond> bonds() {
return bonds;
}

@Override
public IBond getBond(IAtom atom) {
for (IBond bond : bonds) {
if (bond.getBegin().equals(atom) ||
bond.getEnd().equals(atom))
return bond;
}
return null;
}

@Override
public int hashCode() {
return deref().hashCode();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.openscience.cdk.interfaces.ITestObjectBuilder;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;

/**
Expand Down Expand Up @@ -215,25 +214,4 @@ public void testAtomAdjacencyOnClone() throws CloneNotSupportedException {
assertThat(org.getAtom(0).getBondCount(), is(1));
assertThat(org.getAtom(1).getBondCount(), is(1));
}

@Test
public void testAtomGetBond() {
IAtomContainer mol = (IAtomContainer) newChemObject();
IAtom a1 = mol.getBuilder().newAtom();
IAtom a2 = mol.getBuilder().newAtom();
IAtom a3 = mol.getBuilder().newAtom();
a1.setSymbol("CH3");
a2.setSymbol("CH2");
a3.setSymbol("OH");
mol.addAtom(a1);
mol.addAtom(a2);
mol.addAtom(a3);
mol.addBond(0, 1, IBond.Order.SINGLE);
mol.addBond(1, 2, IBond.Order.SINGLE);
assertThat(mol.getBond(0),
is(mol.getAtom(0).getBond(mol.getAtom(1))));
assertThat(mol.getBond(1),
is(mol.getAtom(1).getBond(mol.getAtom(2))));
assertNull(mol.getAtom(0).getBond(mol.getAtom(2)));
}
}

0 comments on commit 505a588

Please sign in to comment.