public static IChemObject newChemObject() { try { return (IChemObject) object.clone(); } catch (CloneNotSupportedException e) { return null; } }
/** * {@inheritDoc} */ @Override public Object clone() throws CloneNotSupportedException { return new ChemObjectRef((IChemObject) chemobj.clone()); } }
/** * {@inheritDoc} */ @Override public Object clone() throws CloneNotSupportedException { return new ChemObjectRef((IChemObject) chemobj.clone()); } }
/** * Clones this <code>Mapping</code> and the mapped <code>IChemObject</code>s. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Mapping clone = (Mapping) super.clone(); // clone the related IChemObject's if (relation != null) { clone.relation = new IChemObject[relation.length]; for (int f = 0; f < relation.length; f++) { if (relation[f] != null) { clone.relation[f] = (IChemObject) relation[f].clone(); } } } return clone; } }
/** * Clones this <code>Mapping</code> and the mapped <code>IChemObject</code>s. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Mapping clone = (Mapping) super.clone(); // clone the related IChemObject's if (relation != null) { clone.relation = new IChemObject[relation.length]; for (int f = 0; f < relation.length; f++) { if (relation[f] != null) { clone.relation[f] = (IChemObject) relation[f].clone(); } } } return clone; } }
/** * Clones this <code>Mapping</code> and the mapped <code>IChemObject</code>s. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Mapping clone = (Mapping) super.clone(); // clone the related IChemObject's if (relation != null) { clone.relation = new IChemObject[relation.length]; for (int f = 0; f < relation.length; f++) { if (relation[f] != null) { clone.relation[f] = (IChemObject) relation[f].clone(); } } } return clone; } }
/** * Clones this <code>Mapping</code> and the mapped <code>IChemObject</code>s. * * @return The cloned object */ @Override public Object clone() throws CloneNotSupportedException { Mapping clone = (Mapping) super.clone(); // clone the related IChemObject's if (relation != null) { clone.relation = new IChemObject[relation.length]; for (int f = 0; f < relation.length; f++) { if (relation[f] != null) { clone.relation[f] = (IChemObject) relation[f].clone(); } } } return clone; } }
/** * @cdk.bug 2975800 */ @Test public void testClone_PropertyNull() throws Exception { IChemObject chemObject = newChemObject(); final String key = "NullProperty"; chemObject.setProperty(key, null); chemObject.clone(); }
@Test public void testClone_Properties() throws Exception { IChemObject chemObject1 = newChemObject(); Map<Object, Object> props1 = new Hashtable<Object, Object>(); chemObject1.addProperties(props1); IChemObject chemObject2 = (IChemObject) chemObject1.clone(); // test cloning of properties field Map<Object, Object> props2 = new Hashtable<Object, Object>(); props2.put("key", "value"); chemObject2.addProperties(props2); Assert.assertEquals(props1, chemObject1.getProperties()); Assert.assertEquals(1, chemObject2.getProperties().size()); Assert.assertEquals(0, chemObject1.getProperties().size()); }
@Test public void testShallowCopy() throws Exception { IChemObject chemObject = newChemObject(); Object clone = chemObject.clone(); Assert.assertNotNull(clone); Assert.assertTrue(clone instanceof IChemObject); }
@Test public void testClone() throws Exception { IChemObject chemObject = newChemObject(); chemObject.setFlag(CDKConstants.ISALIPHATIC, true); // test cloning of itself Object clone = chemObject.clone(); Assert.assertTrue(clone instanceof IChemObject); // test that everything has been cloned properly String diff = ChemObjectDiff.diff(chemObject, (IChemObject) clone); Assert.assertNotNull(diff); Assert.assertEquals(0, diff.length()); }
/** @cdk.bug 1838820 */ @Test(timeout = 100) public void testDontCloneIChemObjectProperties() throws Exception { IChemObject chemObject1 = newChemObject(); chemObject1.setProperty("RecursiveBastard", chemObject1); Object clone = chemObject1.clone(); Assert.assertNotNull(clone); Assert.assertTrue(clone instanceof IChemObject); }
@Test public void testClone_Properties2() throws Exception { IChemObject chemObject1 = newChemObject(); Map<Object, Object> props1 = new Hashtable<Object, Object>(); IAtom atom = chemObject1.getBuilder().newInstance(IAtom.class, "C"); props1.put("atom", atom); chemObject1.addProperties(props1); IChemObject chemObject2 = (IChemObject) chemObject1.clone(); // test cloning of properties field Map<Object, Object> props2 = new Hashtable<Object, Object>(); chemObject2.addProperties(props2); Assert.assertEquals(props1, chemObject1.getProperties()); Assert.assertEquals(1, chemObject2.getProperties().size()); Assert.assertEquals(1, chemObject1.getProperties().size()); // ok, copied hashtable item, but this item should be cloned Assert.assertEquals(atom, chemObject2.getProperties().get("atom")); }
public static void testClone_ChemObjectListeners(IChemObject chemObject) throws Exception { ChemObjectListener listener = new ChemObjectListener(); chemObject.addListener(listener); IChemObject chemObject2 = (IChemObject) chemObject.clone(); // test lack of cloning of listeners Assert.assertEquals(0, chemObject.getListenerCount()); Assert.assertEquals(0, chemObject2.getListenerCount()); }
@Test public void testClone_Identifier() throws Exception { IChemObject chemObject1 = newChemObject(); chemObject1.setID("co1"); IChemObject chemObject2 = (IChemObject) chemObject1.clone(); // test cloning of identifier field chemObject2.setID("co2"); Assert.assertEquals("co1", chemObject1.getID()); }
@Test public void testClone_Flags() throws Exception { IChemObject chemObject1 = newChemObject(); chemObject1.setFlag(CDKConstants.ISALIPHATIC, true); IChemObject chemObject2 = (IChemObject) chemObject1.clone(); // test cloning of flags field chemObject2.setFlag(CDKConstants.ISALIPHATIC, false); Assert.assertTrue(chemObject1.getFlag(CDKConstants.ISALIPHATIC)); }
@Test public void testClone_ChemObjectListeners() throws Exception { IChemObject chemObject1 = newChemObject(); DummyChemObjectListener listener = new DummyChemObjectListener(); chemObject1.addListener(listener); IChemObject chemObject2 = (IChemObject) chemObject1.clone(); // test lack of cloning of listeners Assert.assertEquals(1, chemObject1.getListenerCount()); Assert.assertEquals(0, chemObject2.getListenerCount()); }