Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
1560:33a53c43e2f7 | 1561:e1a13e707bf3 |
---|---|
1 package luan.impl; | 1 package luan.impl; |
2 | 2 |
3 import luan.LuanCloneable; | 3 import luan.LuanCloneable; |
4 import luan.LuanCloner; | 4 import luan.LuanCloner; |
5 import luan.LuanImmutabler; | |
6 import luan.LuanException; | |
5 | 7 |
6 | 8 |
7 public final class Pointer implements LuanCloneable { | 9 public final class Pointer implements LuanCloneable { |
8 public Object o; | 10 private Object o; |
11 private boolean immutable = false; | |
9 | 12 |
10 public Pointer() {} | 13 public Pointer() {} |
11 | 14 |
12 public Pointer(Object o) { | 15 public Pointer(Object o) { |
13 this.o = o; | 16 this.o = o; |
18 } | 21 } |
19 | 22 |
20 @Override public void deepenClone(LuanCloneable clone,LuanCloner cloner) { | 23 @Override public void deepenClone(LuanCloneable clone,LuanCloner cloner) { |
21 ((Pointer)clone).o = cloner.get(o); | 24 ((Pointer)clone).o = cloner.get(o); |
22 } | 25 } |
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 } | |
23 } | 41 } |