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

41
LINES

< > BotCompany Repo | #1006448 - class Lowest - like Best, but collects item with lowest score

JavaX fragment (include)

sclass Lowest<A> {
  A best;
  double score;
  transient O onChange;
  
  synchronized bool isNewBest(double score) {
    ret best == null || score < this.score;
  }
  
  synchronized double bestScore() {
    ret best == null ? Double.NaN : score;
  }
  
  double score() { ret bestScore(); }
  
  synchronized float floatScore() {
    ret best == null ? Float.NaN : (float) score;
  }
  
  synchronized float floatScoreOr(float defaultValue) {
    ret best == null ? defaultValue : (float) score;
  }
  
  bool put(A a, double score) {
    bool change = false;
    synchronized(this) {
      if (a != null && isNewBest(score)) {
        best = a;
        this.score = score;
        change = true;
      }
    }
    if (change)
      pcallF(onChange);
    ret change;
  }
  
  synchronized A get() { ret best; }
  synchronized bool has() { ret best != null; }
  synchronized Pair<A, Double> pair() { ret best == null ? null : Pair(best, bestScore()); }
}

Author comment

Began life as a copy of #1006090

download  show line numbers  debug dex   

Travelled to 13 computer(s): aoiabmzegqzx, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, jtubtzbbkimh, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, ppjhyzlbdabe, tslmcundralx, tvejysmllsmz

No comments. add comment

Snippet ID: #1006448
Snippet name: class Lowest - like Best, but collects item with lowest score
Eternal ID of this version: #1006448/8
Text MD5: 7f2bf9d27ce20d898639eb35f8259f0c
Author: stefan
Category: javax / genetic optimization
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-08-30 12:02:19
Source code size: 995 bytes / 41 lines
Pitched / IR pitched: No / No
Views / Downloads: 326 / 3588
Version history: 7 change(s)
Referenced in: [show references]

Formerly at http://tinybrain.de/1006448 & http://1006448.tinybrain.de