// always keeps a dynamically updated list of the n most probable // results // not synchronized sclass SetOfMostProbable extends TreeSetWithDuplicates> { int maxSize = 10; *() {} *(int *maxSize) {} public bool add(WithProbability a) { if (a == null) ret; super.add(a); truncateTreeSetWithDuplicates(this, maxSize); } selfType run() { action.get(result -> add(WithProbability(ps.currentProbability(), result)); this; } }