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).

static final class NotifyingStringBuffer implements CharSequence, Appendable {
  new StringBuilder builder;
  long changes;
  L onChange;
  
  public synchronized Appendable append(char c) {
    builder.append(c); ret change();
  }
  
  public synchronized Appendable append(CharSequence csq, int start, int end) {
    builder.append(csq, start, end); ret change();
  }
  
  public synchronized Appendable append(CharSequence csq) {
    builder.append(csq); ret change();
  }
  
  public synchronized void setLength(int i) {
    builder.setLength(i); change();
  }
  
  public synchronized void trimToSize() {
    builder.trimToSize();
  }
  
  // internal
  NotifyingStringBuffer change() {
    ++changes;
    pcallFAll(onChange);
    this;
  }
  
  synchronized toString { ret builder.toString(); }
  
  public synchronized char charAt(int index) { ret builder.charAt(index); }
  public synchronized int length() { ret builder.length(); }
  public synchronized CharSequence subSequence(int start, int end) {
    ret builder.subSequence(start, end);
  }
  synchronized S substring(int start) { ret builder.substring(start); }
  
  int capacity() { ret builder.capacity(); }
  
  public synchronized void onChange(Runnable r) {
    onChange = listCreateAndAdd(onChange, r);
  }
}

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: 438 / 1042
Version history: 16 change(s)
Referenced in: [show references]