Libraryless. Click here for Pure Java version (4439L/24K).
1 | sclass Borrowable<A> implements AutoCloseable { |
2 | A object; |
3 | bool borrowed; |
4 | |
5 | *(A *object) {} |
6 | *() {} |
7 | |
8 | synchronized void set(A object) { |
9 | this.object = object; |
10 | borrowed = false; |
11 | } |
12 | |
13 | synchronized bool canBorrow() { ret object != null && !borrowed; } |
14 | |
15 | synchronized bool isBorrowed() { ret borrowed; } |
16 | |
17 | // returns null if object is borrowed |
18 | synchronized IAutoCloseableF0<A> tempBorrow() { |
19 | bool canBorrow = canBorrow(); |
20 | A o = canBorrow ? object : null; |
21 | if (canBorrow) borrowed = true; |
22 | |
23 | ret new IAutoCloseableF0<A> { |
24 | public A get() { ret o; } |
25 | public void close { unborrow(o); } |
26 | }; |
27 | } |
28 | |
29 | synchronized void unborrow(A o) { |
30 | if (o == object) borrowed = false; |
31 | } |
32 | |
33 | public void close() { |
34 | O o; |
35 | synchronized(this) { |
36 | o = object; |
37 | object = null; |
38 | } |
39 | dispose o; |
40 | } |
41 | } |
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx
No comments. add comment
Snippet ID: | #1032349 |
Snippet name: | Borrowable |
Eternal ID of this version: | #1032349/7 |
Text MD5: | c810dce629b89e498390413454488c3e |
Transpilation MD5: | 9206b2856386b3c3cae79e977809eb9d |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-08-30 04:26:43 |
Source code size: | 893 bytes / 41 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 213 / 373 |
Version history: | 6 change(s) |
Referenced in: | [show references] |