Mercurial Hosting > luan
comparison core/src/luan/DeepCloner.java @ 195:24ede40ee0aa
make MetatableGetter DeepCloneable, scoped, and secure
git-svn-id: https://luan-java.googlecode.com/svn/trunk@196 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 03 Jul 2014 08:19:48 +0000 |
parents | 3dcb0f9bee82 |
children | c6bcb8859b93 |
comparison
equal
deleted
inserted
replaced
194:08df375e2e5f | 195:24ede40ee0aa |
---|---|
6 | 6 |
7 public final class DeepCloner { | 7 public final class DeepCloner { |
8 private final Map<Object,Object> cloned = new IdentityHashMap<Object,Object>(); | 8 private final Map<Object,Object> cloned = new IdentityHashMap<Object,Object>(); |
9 | 9 |
10 public <T extends DeepCloneable<T>> T deepClone(T obj) { | 10 public <T extends DeepCloneable<T>> T deepClone(T obj) { |
11 if( obj==null ) | |
12 return null; | |
11 @SuppressWarnings("unchecked") | 13 @SuppressWarnings("unchecked") |
12 T rtn = (T)cloned.get(obj); | 14 T rtn = (T)cloned.get(obj); |
13 if( rtn == null ) { | 15 if( rtn == null ) { |
14 rtn = obj.shallowClone(); | 16 rtn = obj.shallowClone(); |
15 cloned.put(obj,rtn); | 17 cloned.put(obj,rtn); |