Mercurial Hosting > luan
annotate src/luan/impl/Pointer.java @ 1561:e1a13e707bf3
start immutable
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 05 Nov 2020 20:24:09 -0700 |
parents | 6a7c6879158d |
children | c922446f53aa |
rev | line source |
---|---|
670 | 1 package luan.impl; |
2 | |
781
fbbdd369a13a
rename DeepCloner to LuanCloner
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
3 import luan.LuanCloneable; |
fbbdd369a13a
rename DeepCloner to LuanCloner
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
4 import luan.LuanCloner; |
1561 | 5 import luan.LuanImmutabler; |
6 import luan.LuanException; | |
670 | 7 |
8 | |
781
fbbdd369a13a
rename DeepCloner to LuanCloner
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
9 public final class Pointer implements LuanCloneable { |
1561 | 10 private Object o; |
11 private boolean immutable = false; | |
670 | 12 |
671 | 13 public Pointer() {} |
14 | |
15 public Pointer(Object o) { | |
16 this.o = o; | |
17 } | |
18 | |
784
6a7c6879158d
revert shallowClone()
Franklin Schmidt <fschmidt@gmail.com>
parents:
782
diff
changeset
|
19 @Override public Pointer shallowClone() { |
670 | 20 return new Pointer(); |
21 } | |
22 | |
781
fbbdd369a13a
rename DeepCloner to LuanCloner
Franklin Schmidt <fschmidt@gmail.com>
parents:
775
diff
changeset
|
23 @Override public void deepenClone(LuanCloneable clone,LuanCloner cloner) { |
670 | 24 ((Pointer)clone).o = cloner.get(o); |
25 } | |
1561 | 26 |
27 @Override public void makeImmutable(LuanImmutabler immutabler) throws LuanException { | |
28 immutabler.makeImmutable(o); | |
29 immutable = true; | |
30 } | |
31 | |
32 public Object get() { | |
33 return o; | |
34 } | |
35 | |
36 public void set(Object o) throws LuanException { | |
37 if( immutable ) | |
38 throw new LuanException("variable is immutable"); | |
39 this.o = o; | |
40 } | |
670 | 41 } |