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

16
LINES

< > BotCompany Repo | #1031595 // tempSetField_conservativeUndo

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

Libraryless. Click here for Pure Java version (2904L/17K).

1  
static AutoCloseable tempSetField_conservativeUndo(O o, S field, O value) {
2  
  fO oldValue = get(o, field);
3  
  set(o, field, value);
4  
  ret () -> { if (eq(get(o, field), value)) set(o, field, oldValue); };
5  
}
6  
7  
static <A> AutoCloseable tempSetField_conservativeUndo(ISetAndGet<A> gs, A value) {
8  
  if (gs == null) null; // convenient null propagation as always in JavaX!
9  
  A oldValue = gs!;
10  
  gs.set(value);
11  
  ret () -> { if (eq(gs!, value)) gs.set(oldValue); };
12  
}
13  
14  
static <A> AutoCloseable tempSetField_conservativeUndo(A value, ISetAndGet<A> gs) {
15  
  ret tempSetField(gs, value);
16  
}

Author comment

Began life as a copy of #1016243

download  show line numbers  debug dex  old transpilations   

Travelled to 4 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1031595
Snippet name: tempSetField_conservativeUndo
Eternal ID of this version: #1031595/1
Text MD5: ac36ebeb86fdf7a97fc9dcea6b5634ab
Transpilation MD5: cee8da2634f5fa620289e30ce5324ed3
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-22 07:52:21
Source code size: 591 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 146 / 216
Referenced in: [show references]