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

16
LINES

< > BotCompany Repo | #1011185 // highestByField - ignores elements where field = null

JavaX fragment (include)

static <A> A mapMethodLike highestByField(S field, Collection<A> l) {
  A best = null;
  O bestValue = null;
  if (l != null) for(A a : l) {
    O val = getOpt(a, field);
    if (val != null && (bestValue == null || cmp(val, bestValue) > 0)) {
      best = a;
      bestValue = val;
    }
  }
  ret best;
}

static <A> A highestByField(Collection<A> l, S field) {
  ret highestByField(field, l);
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1011185
Snippet name: highestByField - ignores elements where field = null
Eternal ID of this version: #1011185/5
Text MD5: 5fceb15e4c80ebec3229f5c4fc612028
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-06 08:03:21
Source code size: 412 bytes / 16 lines
Pitched / IR pitched: No / No
Views / Downloads: 509 / 519
Version history: 4 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1011867 - smallestByMethod
#1016781 - highestByFunction