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

9
LINES

< > BotCompany Repo | #1005270 // cloneSet - safely clone a set, try to match original type

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

Libraryless. Click here for Pure Java version (2768L/16K).

// TODO: does not detect set type (hash/tree) when it's synchronized
static <A> Set<A> cloneSet(Cl<A> set) {
  if (set == null) ret new HashSet;
  synchronized(collectionMutex(set)) {
    Set<A> s = similarEmptySet(set);
    s.addAll(set);
    ret s;
  }
}

Author comment

Began life as a copy of #1002559

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005270
Snippet name: cloneSet - safely clone a set, try to match original type
Eternal ID of this version: #1005270/6
Text MD5: fd10209283de6c3d7082bfe8cf6d73d4
Transpilation MD5: 2c4ac828c3fa4e111ceaed69811112a2
Author: stefan
Category:
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-06-07 17:10:18
Source code size: 264 bytes / 9 lines
Pitched / IR pitched: No / No
Views / Downloads: 569 / 633
Version history: 5 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1020655 - cloneHashSet - safely clone a collection to HashSet
#1028070 - cloneTreeSet