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

22
LINES

< > BotCompany Repo | #1034091 // VarWithNotify

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

Libraryless. Click here for Pure Java version (9985L/56K).

sclass VarWithNotify<A> extends Var<A> is IVarWithNotify<A> {
  event fireChange;
  
  *() {}
  *(A a) { super(a); }
  
  // clever way (I hope) to do eq() outside of synchronization block
  public void set(A a) {
    A v = get();
    if (eq(v, a)) {
      print ifdef VarWithNotify_debug("VarWithNotify.set no change " + a);
      ret;
    }
    
    print ifdef VarWithNotify_debug("VarWithNotify.set change " + a);
    synchronized {
      this.v = a;
      notifyAll();
    }
    fireChange();
  }
}

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1034091
Snippet name: VarWithNotify
Eternal ID of this version: #1034091/12
Text MD5: 046988ea1a2e2c74040126ff9f7256c3
Transpilation MD5: c210b900b873e3f8050719020cd74b16
Author: stefan
Category: javax / gui
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-03-08 09:21:00
Source code size: 524 bytes / 22 lines
Pitched / IR pitched: No / No
Views / Downloads: 205 / 343
Version history: 11 change(s)
Referenced in: #1034167 - Standard Classes + Interfaces (LIVE, continuation of #1003674)
#1034280 - BoolVarWithNotify
#1034433 - FieldVar - variable representing a field