sclass Lowest is IBest { 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; } public 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 void clear() { best = null; score = 0; } synchronized A get() { ret best; } synchronized bool has() { ret best != null; } synchronized Pair pair() { ret best == null ? null : Pair(best, bestScore()); } toString { ret "Score " + formatDouble_significant2(score, 4) + ": " + best; } }