Advertisement
Guest User

Untitled

a guest
Feb 17th, 2020
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. package model.result;
  2.  
  3. import java.util.*;
  4. import model.result.comparators.IdNumberComparator;
  5. import model.result.comparators.ResultComparator;
  6.  
  7. public class RaceResultList {
  8.   private SortedSet<RaceResult> results;
  9.  
  10.   public RaceResultList() {
  11.     results = new TreeSet<>(new IdNumberComparator());
  12.   }
  13.  
  14.   public RaceResultList(ResultComparator comp) {
  15.     results = new TreeSet<>(comp);
  16.   }
  17.  
  18.   public void setComp(ResultComparator comp) {
  19.     SortedSet<RaceResult> newResults = new TreeSet<>(comp);
  20.     newResults.addAll(results);
  21.     results = newResults;
  22.   }
  23.  
  24.   /**
  25.    * Updates the RaceResultList with a new RaceResult.
  26.    *
  27.    * @param rr the new RaceResult to be added.
  28.    */
  29.   public void update(RaceResult rr) {
  30.     results.add(rr);
  31.   }
  32.  
  33.   /**
  34.    * Locates the RaceResult in the results list.
  35.    *
  36.    * @param startNbr the index for the RaceResult.
  37.    * @return An optional RaceResult, depending on if the startNbr exists or not.
  38.    */
  39.   public Optional<RaceResult> getResultByStartNbr(int startNbr) {
  40.     return results.stream().filter(r -> r.getCompetitorNumber() == startNbr).findAny();
  41.   }
  42.  
  43.   /** Gets a list of all results, in the order specified by the given RaceComparator. */
  44.   public List<RaceResult> getList() {
  45.     return new ArrayList<>(results);
  46.   }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement