Mercurial Hosting > luan
comparison src/luan/impl/Pointer.java @ 1578:c922446f53aa
immutable threading
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 08 Feb 2021 14:16:19 -0700 |
parents | e1a13e707bf3 |
children |
comparison
equal
deleted
inserted
replaced
1577:60e5c324adf9 | 1578:c922446f53aa |
---|---|
1 package luan.impl; | 1 package luan.impl; |
2 | 2 |
3 import luan.LuanCloneable; | 3 import luan.LuanMutable; |
4 import luan.LuanCloner; | |
5 import luan.LuanImmutabler; | |
6 import luan.LuanException; | 4 import luan.LuanException; |
7 | 5 |
8 | 6 |
9 public final class Pointer implements LuanCloneable { | 7 public final class Pointer implements LuanMutable { |
10 private Object o; | 8 private Object o; |
11 private boolean immutable = false; | 9 private boolean immutable = false; |
12 | 10 |
13 public Pointer() {} | 11 public Pointer() {} |
14 | 12 |
15 public Pointer(Object o) { | 13 public Pointer(Object o) { |
16 this.o = o; | 14 this.o = o; |
17 } | 15 } |
18 | 16 |
19 @Override public Pointer shallowClone() { | 17 @Override public boolean isImmutable() { |
20 return new Pointer(); | 18 return immutable; |
21 } | 19 } |
22 | 20 |
23 @Override public void deepenClone(LuanCloneable clone,LuanCloner cloner) { | 21 @Override public void makeImmutable() { |
24 ((Pointer)clone).o = cloner.get(o); | 22 if(immutable) |
25 } | 23 return; |
26 | |
27 @Override public void makeImmutable(LuanImmutabler immutabler) throws LuanException { | |
28 immutabler.makeImmutable(o); | |
29 immutable = true; | 24 immutable = true; |
25 LuanMutable.makeImmutable(o); | |
30 } | 26 } |
31 | 27 |
32 public Object get() { | 28 public Object get() { |
33 return o; | 29 return o; |
34 } | 30 } |