GeometricCumulativeDoubleBondFactory implements StereoEncoderFactory { @Override public StereoEncoder create(IAtomContainer container, int[][] graph) { int n = container.getAtomCount(); BondMap map = new BondMap(n); List<StereoEncoder> encoders = new ArrayList<StereoEncoder>(1); for (IBond bond : container.bonds()) { if (isDoubleBond(bond)) map.add(bond); } Set<IAtom> visited = new HashSet<IAtom>(n); for (IAtom a : map.atoms()) { List<IBond> bonds = map.bonds(a); if (bonds.size() == 2) { IAtom s = bonds.get(0).getOther(a); IAtom e = bonds.get(1).getOther(a); IAtom sParent = a; IAtom eParent = a; visited.add(a); visited.add(s); visited.add(e); int size = 2; while (s != null && map.cumulated(s)) { IAtom p = map.bonds(s).get(0).getOther(s); IAtom q = map.bonds(s).get(1).getOther(s); sParent = s; s = visited.add(p) ? p : visited.add(q) ? q : null; size++; } while (e != null && map.cumulated(e)) { IAtom p = map.bonds(e).get(0).getOther(e); IAtom q = map.bonds(e).get(1).getOther(e); eParent = e; e = visited.add(p) ? p : visited.add(q) ? q : null; size++; } if (s != null && e != null) { if (isOdd(size)) { StereoEncoder encoder = GeometricDoubleBondEncoderFactory.newEncoder(container, s, sParent, e, eParent, graph); if (encoder != null) { encoders.add(encoder); } } else { StereoEncoder encoder = axialEncoder(container, s, e); if (encoder != null) { encoders.add(encoder); } } } } } return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders); }  @Override StereoEncoder create(IAtomContainer container, int[][] graph);  }
@Test public void testCreate() throws Exception { IAtomContainer m = new AtomContainer(); m.addAtom(carbonAt(-0.2994, 3.2084)); m.addAtom(carbonAt(-1.1244, 3.2084)); m.addAtom(carbonAt(-1.9494, 3.2084)); m.addAtom(carbonAt(-2.3619, 2.4939)); m.addAtom(carbonAt(0.1131, 3.9228)); m.addBond(new Bond(m.getAtom(0), m.getAtom(1), IBond.Order.DOUBLE)); m.addBond(new Bond(m.getAtom(1), m.getAtom(2), IBond.Order.DOUBLE)); m.addBond(new Bond(m.getAtom(2), m.getAtom(3))); m.addBond(new Bond(m.getAtom(0), m.getAtom(4))); StereoEncoderFactory factory = new GeometricCumulativeDoubleBondFactory(); StereoEncoder encoder = factory.create(m, null); assertThat(encoder, is(instanceOf(MultiStereoEncoder.class))); }