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

13
LINES

< > BotCompany Repo | #1029791 // putSetElementsFirst - convert collection to LinkedHashSet with specified keys in front

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

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

static <A> Set<A> putSetElementsFirst(Cl<A> cl, Cl<A> elements) {
  Set<A> inputSet = asSet(cl);
  new LinkedHashSet<A> set;
  fOr (A a : elements)
    if (contains(inputSet, a))
      set.add(a);
  addAll(set, cl); // keep order
  ret set;
}

static <A> Set<A> putSetElementsFirst(Cl<A> cl, A... elements) {
  ret putSetElementsFirst(cl, asList(elements));
}

Author comment

Began life as a copy of #1004134

download  show line numbers  debug dex  old transpilations   

Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1029791
Snippet name: putSetElementsFirst - convert collection to LinkedHashSet with specified keys in front
Eternal ID of this version: #1029791/3
Text MD5: 8941b14794f09581b6e7d280405ac8f6
Transpilation MD5: 468292a0fab9343520e7cb58f0b3a9b5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-09-17 12:07:38
Source code size: 371 bytes / 13 lines
Pitched / IR pitched: No / No
Views / Downloads: 122 / 190
Version history: 2 change(s)
Referenced in: [show references]