Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

47
LINES

< > BotCompany Repo | #1019844 // NotifyingStringBuffer - StringBuffer with notification + change count

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (2017L/13K).

1  
static final class NotifyingStringBuffer implements CharSequence, Appendable {
2  
  new StringBuilder builder;
3  
  long changes;
4  
  L onChange;
5  
  
6  
  public synchronized Appendable append(char c) {
7  
    builder.append(c); ret change();
8  
  }
9  
  
10  
  public synchronized Appendable append(CharSequence csq, int start, int end) {
11  
    builder.append(csq, start, end); ret change();
12  
  }
13  
  
14  
  public synchronized Appendable append(CharSequence csq) {
15  
    builder.append(csq); ret change();
16  
  }
17  
  
18  
  public synchronized void setLength(int i) {
19  
    builder.setLength(i); change();
20  
  }
21  
  
22  
  public synchronized void trimToSize() {
23  
    builder.trimToSize();
24  
  }
25  
  
26  
  // internal
27  
  NotifyingStringBuffer change() {
28  
    ++changes;
29  
    pcallFAll(onChange);
30  
    this;
31  
  }
32  
  
33  
  synchronized toString { ret builder.toString(); }
34  
  
35  
  public synchronized char charAt(int index) { ret builder.charAt(index); }
36  
  public synchronized int length() { ret builder.length(); }
37  
  public synchronized CharSequence subSequence(int start, int end) {
38  
    ret builder.subSequence(start, end);
39  
  }
40  
  synchronized S substring(int start) { ret builder.substring(start); }
41  
  
42  
  int capacity() { ret builder.capacity(); }
43  
  
44  
  public synchronized void onChange(Runnable r) {
45  
    onChange = listCreateAndAdd(onChange, r);
46  
  }
47  
}

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1019844
Snippet name: NotifyingStringBuffer - StringBuffer with notification + change count
Eternal ID of this version: #1019844/17
Text MD5: 80de9251ef4cc677d5f0dc03611c23ff
Transpilation MD5: 5463f41d9799ef1725e85c1a9a4c0a9c
Author: stefan
Category: javax / stefan's os
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-28 13:54:32
Source code size: 1327 bytes / 47 lines
Pitched / IR pitched: No / No
Views / Downloads: 439 / 1044
Version history: 16 change(s)
Referenced in: [show references]