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

19
LINES

< > BotCompany Repo | #1005184 // limitedSearchCollector

JavaX fragment (include)

1  
// collects into l until max is reached or target element is found
2  
static <A> Collector<A> limitedSearchCollector(final Collection<A> l, final int max, final A target) {
3  
  ret new Collector<A>() {
4  
    bool found;
5  
    
6  
    bool full() {
7  
      ret found || l(l) >= max;
8  
    }
9  
    
10  
    void add(A a) {
11  
      if (!full()) l.add(a);
12  
      if (eq(a, target)) found = true;
13  
    }
14  
    
15  
    bool contains(A a) {
16  
      ret l.contains(a);
17  
    }
18  
  };
19  
}

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: 495 / 475
Referenced in: [show references]