diff options
| author | RncLsn <rnc.lsn@gmail.com> | 2015-05-29 18:35:51 +0100 |
|---|---|---|
| committer | RncLsn <rnc.lsn@gmail.com> | 2015-05-29 18:35:51 +0100 |
| commit | 4b7253559c290b6fdd1c4122830f153fda85dd62 (patch) | |
| tree | 37c1487e4682be719dec532ca3d7e1af353fb9a1 /src/uk/ac/ox/cs/pagoda/util | |
| parent | 6a559a415b3bdb3048021839e5bcf5bbf5aa4bbd (diff) | |
| download | ACQuA-4b7253559c290b6fdd1c4122830f153fda85dd62.tar.gz ACQuA-4b7253559c290b6fdd1c4122830f153fda85dd62.zip | |
Disposable.
Diffstat (limited to 'src/uk/ac/ox/cs/pagoda/util')
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java | 39 | ||||
| -rw-r--r-- | src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java | 12 |
2 files changed, 51 insertions, 0 deletions
diff --git a/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java b/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java new file mode 100644 index 0000000..b208cc3 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/util/disposable/Disposable.java | |||
| @@ -0,0 +1,39 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util.disposable; | ||
| 2 | |||
| 3 | |||
| 4 | /** | ||
| 5 | * Every public method of a subclass of this class, | ||
| 6 | * as first instruction, should check if the object has already been disposed | ||
| 7 | * and, if so, should throw a <tt>DisposedException</tt>. | ||
| 8 | */ | ||
| 9 | public abstract class Disposable { | ||
| 10 | |||
| 11 | private boolean disposed = false; | ||
| 12 | |||
| 13 | /** | ||
| 14 | * This method must be called after the use of the object. | ||
| 15 | * <p> | ||
| 16 | * Every overriding method must call <tt>super.dispose()</tt> as first instruction. | ||
| 17 | */ | ||
| 18 | public void dispose() { | ||
| 19 | if(isDisposed()) throw new AlreadyDisposedException(); | ||
| 20 | disposed = true; | ||
| 21 | } | ||
| 22 | |||
| 23 | public final boolean isDisposed() { | ||
| 24 | return disposed; | ||
| 25 | } | ||
| 26 | |||
| 27 | private class AlreadyDisposedException extends RuntimeException { | ||
| 28 | |||
| 29 | public AlreadyDisposedException() { | ||
| 30 | super(); | ||
| 31 | } | ||
| 32 | |||
| 33 | public AlreadyDisposedException(String msg) { | ||
| 34 | super(msg); | ||
| 35 | } | ||
| 36 | } | ||
| 37 | |||
| 38 | |||
| 39 | } | ||
diff --git a/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java b/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java new file mode 100644 index 0000000..eb8c039 --- /dev/null +++ b/src/uk/ac/ox/cs/pagoda/util/disposable/DisposedException.java | |||
| @@ -0,0 +1,12 @@ | |||
| 1 | package uk.ac.ox.cs.pagoda.util.disposable; | ||
| 2 | |||
| 3 | public class DisposedException extends RuntimeException { | ||
| 4 | |||
| 5 | public DisposedException() { | ||
| 6 | super(); | ||
| 7 | } | ||
| 8 | |||
| 9 | public DisposedException(String msg) { | ||
| 10 | super(msg); | ||
| 11 | } | ||
| 12 | } | ||
