Mercurial Hosting > luan
comparison src/luan/DeepCloner.java @ 78:7c08b611125d
better deep cloning
git-svn-id: https://luan-java.googlecode.com/svn/trunk@79 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 15 Feb 2013 22:29:16 +0000 |
parents | 4bf3d0c0b6b9 |
children | 0149bdf98fd8 |
comparison
equal
deleted
inserted
replaced
77:4bf3d0c0b6b9 | 78:7c08b611125d |
---|---|
16 obj.deepenClone(rtn,this); | 16 obj.deepenClone(rtn,this); |
17 } | 17 } |
18 return rtn; | 18 return rtn; |
19 } | 19 } |
20 | 20 |
21 public void deepenClone(Object[] a) { | 21 public <T> T[] deepClone(T[] obj) { |
22 for( int i=0; i<a.length; i++ ) { | 22 if( obj.length == 0 ) |
23 a[i] = get(a[i]); | 23 return obj; |
24 @SuppressWarnings("unchecked") | |
25 T[] rtn = (T[])cloned.get(obj); | |
26 if( rtn == null ) { | |
27 rtn = obj.clone(); | |
28 cloned.put(obj,rtn); | |
29 for( int i=0; i<rtn.length; i++ ) { | |
30 @SuppressWarnings("unchecked") | |
31 T t = (T)get(rtn[i]); | |
32 rtn[i] = t; | |
33 } | |
24 } | 34 } |
35 return rtn; | |
25 } | 36 } |
26 | 37 |
27 public Object get(Object obj) { | 38 public Object get(Object obj) { |
28 if( !(obj instanceof DeepCloneable) ) | 39 if( !(obj instanceof DeepCloneable) ) |
29 return obj; | 40 return obj; |