blob: b208cc3c80b9d25d6cbcba51317721c38b070d5f (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
package uk.ac.ox.cs.pagoda.util.disposable;
/**
* Every public method of a subclass of this class,
* as first instruction, should check if the object has already been disposed
* and, if so, should throw a <tt>DisposedException</tt>.
*/
public abstract class Disposable {
private boolean disposed = false;
/**
* This method must be called after the use of the object.
* <p>
* Every overriding method must call <tt>super.dispose()</tt> as first instruction.
*/
public void dispose() {
if(isDisposed()) throw new AlreadyDisposedException();
disposed = true;
}
public final boolean isDisposed() {
return disposed;
}
private class AlreadyDisposedException extends RuntimeException {
public AlreadyDisposedException() {
super();
}
public AlreadyDisposedException(String msg) {
super(msg);
}
}
}
|