Libraryless. Click here for Pure Java version (2212L/14K).
1 | sbool makeNotifyingStringBufferRotate_verbose; |
2 | |
3 | sclass NotifyingStringBufferRotator implements Runnable {
|
4 | NotifyingStringBuffer buf; |
5 | IF0<Int> getMaxChars; |
6 | bool processing; // avoid endless loop |
7 | |
8 | *(NotifyingStringBuffer *buf, IF0<Int> *getMaxChars) {}
|
9 | |
10 | run {
|
11 | if (processing) ret; |
12 | temp tempSet(this, processing := true); |
13 | Int max = callF(getMaxChars); |
14 | //if (makeNotifyingStringBufferRotate_verbose) System.out.println("XX " + max + " " + buf.length());
|
15 | if (max == null || buf.length() <= max) ret; |
16 | if (makeNotifyingStringBufferRotate_verbose) print("Rotating NotifyingStringBuffer (" + buf.length() + "/" + max + ")");
|
17 | |
18 | try {
|
19 | int newLength = max/2; |
20 | int ofs = buf.length()-newLength; |
21 | S newString = buf.substring(ofs); |
22 | buf.setLength(0); |
23 | buf.append("[...] ").append(newString);
|
24 | } catch (Exception e) {
|
25 | buf.setLength(0); |
26 | } |
27 | buf.trimToSize(); |
28 | } |
29 | } |
30 | |
31 | svoid makeNotifyingStringBufferRotate(NotifyingStringBuffer buf, IF0<Int> getMaxChars) {
|
32 | if (hasElementWithClassShortNamed('NotifyingStringBufferRotator, buf.onChange)) ret;
|
33 | buf.onChange(new NotifyingStringBufferRotator(buf, getMaxChars)); |
34 | } |
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1024230 |
| Snippet name: | makeNotifyingStringBufferRotate |
| Eternal ID of this version: | #1024230/9 |
| Text MD5: | 02f6f584f8cd479f19f9afd82a622cbc |
| Transpilation MD5: | cb2ec6030c10ba3f40b0b62a856b4311 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2019-07-28 14:06:47 |
| Source code size: | 1214 bytes / 34 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 919 / 2021 |
| Version history: | 8 change(s) |
| Referenced in: | [show references] |