Skip to content

Instantly share code, notes, and snippets.

@johnmay
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save johnmay/c95a443392816ea9b15a to your computer and use it in GitHub Desktop.

Select an option

Save johnmay/c95a443392816ea9b15a to your computer and use it in GitHub Desktop.
Map<AtomPair,IBond> bondMap = new HashMap<>();
for (IBond bond : container.bonds())
bondMap.put(new AtomPair(bond.getAtom(0), bond.getAtom(1)),
bond);
class AtomPair {
IAtom a, b;
AtomPair(IAtom a, IAtom b) {
this.a = a, this.b = b;
}
public int hashCode() {
return a.hashCode() ^ b.hashCode();
}
public boolean equals(Object obj) {
// null check etc
AtomPair that = (AtomPair) obj;
return this.a.equals(that.a) && this.b.equal(that.b) || this.a.equals(that.b) && this.b.equal(that.a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment