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

19
LINES

< > BotCompany Repo | #1005184 // limitedSearchCollector

JavaX fragment (include)

// collects into l until max is reached or target element is found
static <A> Collector<A> limitedSearchCollector(final Collection<A> l, final int max, final A target) {
  ret new Collector<A>() {
    bool found;
    
    bool full() {
      ret found || l(l) >= max;
    }
    
    void add(A a) {
      if (!full()) l.add(a);
      if (eq(a, target)) found = true;
    }
    
    bool contains(A a) {
      ret l.contains(a);
    }
  };
}

Author comment

Began life as a copy of #1005183

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1005184
Snippet name: limitedSearchCollector
Eternal ID of this version: #1005184/1
Text MD5: f893179581cff97d323fd98f1963dbfe
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2016-10-19 15:56:21
Source code size: 458 bytes / 19 lines
Pitched / IR pitched: No / No
Views / Downloads: 553 / 532
Referenced in: [show references]