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

37
LINES

< > BotCompany Repo | #1001715 // shallowClone

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

Libraryless. Click here for Pure Java version (9276L/51K).

1  
static <A> A shallowClone(A o) {
2  
  ret (A) shallowClone_impl(o);
3  
}
4  
5  
static <A> A shallowClone(A o, A emptyClone) {
6  
  ret copyFields(o, emptyClone);
7  
}
8  
9  
static O shallowClone_impl(O o) {
10  
  if (o == null)
11  
    return o;
12  
    
13  
  if (o instanceof List)
14  
    ret cloneList((List) o);
15  
16  
  if (o cast Map) ret cloneMap(o);
17  
18  
  if (o instanceof String || o instanceof Number || o instanceof Boolean)
19  
    return o;
20  
    
21  
  if (o instanceof Object[]) {
22  
    Object[] l = (Object[]) o;
23  
    ret l.clone();
24  
  }
25  
  
26  
  // clone an arbitrary custom object
27  
  
28  
  O clone;
29  
  if (o cast IMakeEmptyClone)
30  
    clone = o.makeEmptyClone();
31  
  else
32  
    clone = nuEmptyObject(o.getClass());
33  
34  
  //print("Cloning custom: " + o);
35  
  copyFields(o, clone);
36  
  ret clone;
37  
}

Author comment

Began life as a copy of #1001032

download  show line numbers  debug dex  old transpilations   

Travelled to 15 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv

No comments. add comment

Snippet ID: #1001715
Snippet name: shallowClone
Eternal ID of this version: #1001715/9
Text MD5: 3af8208ba9e7acbd681332a6009343f6
Transpilation MD5: 37b252e7be3803c1fdea1ab79147fce3
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-05-05 17:34:01
Source code size: 767 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 809 / 1099
Version history: 8 change(s)
Referenced in: [show references]