From aed0dd321963c3a351cab2ee40a43312e3084f83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Lamy?= Date: Wed, 21 Aug 2024 09:16:24 -0400 Subject: [PATCH] added group range --- .../java/app/owlcms/data/group/Group.java | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/owlcms/src/main/java/app/owlcms/data/group/Group.java b/owlcms/src/main/java/app/owlcms/data/group/Group.java index 23f782afd..f568dd8c0 100644 --- a/owlcms/src/main/java/app/owlcms/data/group/Group.java +++ b/owlcms/src/main/java/app/owlcms/data/group/Group.java @@ -62,6 +62,34 @@ @JsonIdentityInfo(generator = ObjectIdGenerators.PropertyGenerator.class, property = "id", scope = Group.class) @JsonIgnoreProperties(ignoreUnknown = true, value = { "hibernateLazyInitializer", "logger", "athletes" }) public class Group implements Comparable { + + public record Range (Integer min, Integer max) { + public String getFormattedRange() { + if (min == Integer.MAX_VALUE && max == 0) { + return ""; + } else if (min == max) { + return min.toString(); + } else { + return min.toString()+" - "+max.toString(); + } + } + }; + + @Transient + @JsonIgnore + public Range getStartingRange() { + int min = Integer.MAX_VALUE; + int max = 0; + for (Athlete a : getAthletes()) { + Integer q = a.getQualifyingTotal(); + if (q == null) { + continue; + } + min = q < min ? q : min; + max = q > max ? q : max; + } + return new Range(min, max); + } private final static Logger logger = (Logger) LoggerFactory.getLogger(Group.class); private final static NaturalOrderComparator c = new NaturalOrderComparator<>();