Repository navigation
Expand file tree
/
Copy pathDestroyable.java
More file actions
56 lines (48 loc) · 1.54 KB
/
Copy pathDestroyable.java
File metadata and controls
56 lines (48 loc) · 1.54 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package act;
import org.osgl.util.IO;
import java.io.Closeable;
import java.util.Collection;
public interface Destroyable {
void destroy();
boolean isDestroyed();
public enum Util {
;
/**
* Helper method to destroy all elements in a in a {@link Destroyable} collection
* @param col the collection contains {@link Destroyable} elements
*/
public static void destroyAll(Collection<? extends Destroyable> col) {
for (Destroyable e : col) {
e.destroy();
}
}
/**
* Helper method to destroy all {@link Destroyable} elements,
* and close all {@link Closeable} elements in the collection specified
* @param col the collection might contains {@link Destroyable} and
* {@link Closeable} elements
*/
public static void tryDestroyAll(Collection<?> col) {
if (null == col) {
return;
}
for (Object o: col) {
if (o instanceof Destroyable) {
((Destroyable) o).destroy();
}
if (o instanceof Closeable) {
IO.close((Closeable) o);
}
}
col.clear();
}
public static void tryDestroy(Object o) {
if (o instanceof Destroyable) {
((Destroyable) o).destroy();
}
if (o instanceof Closeable) {
IO.close((Closeable) o);
}
}
}
}