Mercurial Hosting > luan
comparison src/luan/LuanCloner.java @ 785:d69d3c51c44e
more work on incremental cloning
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 01 Sep 2016 21:32:28 -0600 |
parents | 6a7c6879158d |
children | e0cf0d108a77 |
comparison
equal
deleted
inserted
replaced
784:6a7c6879158d | 785:d69d3c51c44e |
---|---|
4 import java.util.HashMap; | 4 import java.util.HashMap; |
5 import java.util.IdentityHashMap; | 5 import java.util.IdentityHashMap; |
6 | 6 |
7 | 7 |
8 public final class LuanCloner { | 8 public final class LuanCloner { |
9 public final boolean deep; | 9 public enum Type { COMPLETE, INCREMENTAL } |
10 | |
11 public final Type type; | |
10 private final Map cloned = new IdentityHashMap(); | 12 private final Map cloned = new IdentityHashMap(); |
11 | 13 |
12 public LuanCloner(boolean deep) { | 14 public LuanCloner(Type type) { |
13 this.deep = deep; | 15 this.type = type; |
14 } | 16 } |
15 | 17 |
16 public LuanCloneable clone(LuanCloneable obj) { | 18 public LuanCloneable clone(LuanCloneable obj) { |
17 if( obj==null ) | 19 if( obj==null ) |
18 return null; | 20 return null; |
60 return clone((Object[])obj); | 62 return clone((Object[])obj); |
61 if( obj instanceof Map ) | 63 if( obj instanceof Map ) |
62 return clone((Map)obj); | 64 return clone((Map)obj); |
63 return obj; | 65 return obj; |
64 } | 66 } |
65 /* | |
66 public Object check(Object obj) { | |
67 if( deep ) | |
68 throw new RuntimeException(); | |
69 if( !(obj instanceof LuanCloneable) ) | |
70 return obj; | |
71 LuanCloneable lc = (LuanCloneable)obj; | |
72 return lc.getCloner() == this ? lc : clone(lc); | |
73 } | |
74 */ | |
75 } | 67 } |