Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Removed redundant code from ChemObj clone - the existing code did exa…

…ctly what the copy constructor of HashMap does and thus provides a cleaner implementation
  • Loading branch information...
commit 83f0f891eee875ea628bde799bb7138decfe872b 1 parent 7fe738c
John May authored
19 src/main/org/openscience/cdk/ChemObject.java
@@ -300,20 +300,17 @@ public Object getProperty(Object description)
300 300 public Object clone() throws CloneNotSupportedException
301 301 {
302 302 ChemObject clone = (ChemObject)super.clone();
  303 +
303 304 // clone the flags
304 305 clone.flags = new boolean[CDKConstants.MAX_FLAG_INDEX + 1];
305 306 System.arraycopy(flags, 0, clone.flags, 0, flags.length);
306   - // clone the properties
307   - if (properties != null) {
308   - Map<Object, Object> clonedHashtable = new HashMap<Object, Object>();
309   - Iterator<Object> keys = properties.keySet().iterator();
310   - while (keys.hasNext()) {
311   - Object key = keys.next();
312   - Object value = properties.get(key);
313   - clonedHashtable.put(key, value);
314   - }
315   - clone.properties = clonedHashtable;
316   - }
  307 +
  308 + // clone the properties - using the HashMap copy constructor
  309 + // this doesn't deep clone the keys/values but this wasn't happening
  310 + // already
  311 + if (properties != null)
  312 + clone.properties = new HashMap<Object, Object>(getProperties());
  313 +
317 314 // delete all listeners
318 315 clone.chemObjectListeners = null;
319 316 return clone;
15 src/main/org/openscience/cdk/silent/ChemObject.java
@@ -237,17 +237,14 @@ public Object clone() throws CloneNotSupportedException
237 237 // clone the flags
238 238 clone.flags = new boolean[CDKConstants.MAX_FLAG_INDEX + 1];
239 239 System.arraycopy(flags, 0, clone.flags, 0, flags.length);
240   - // clone the properties
  240 +
  241 + // clone the properties - using the HashMap copy constructor
  242 + // this does not deep copy all objects but this was not done
  243 + // originally
241 244 if (properties != null) {
242   - Map<Object, Object> clonedHashtable = new HashMap<Object, Object>();
243   - Iterator<Object> keys = properties.keySet().iterator();
244   - while (keys.hasNext()) {
245   - Object key = keys.next();
246   - Object value = properties.get(key);
247   - clonedHashtable.put(key, value);
248   - }
249   - clone.properties = clonedHashtable;
  245 + clone.properties = new HashMap<Object, Object>(getProperties());
250 246 }
  247 +
251 248 return clone;
252 249 }
253 250

0 comments on commit 83f0f89

Please sign in to comment.
Something went wrong with that request. Please try again.