package com.google.sps.utilities;

import com.google.common.collect.Sets;
import com.google.sps.data.Event;
import com.google.sps.data.User;
import com.google.sps.data.VolunteeringOpportunity;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class EventRanker {
  /**
   * Sorts events based on each event's score.
   * Breaks ties with the event's date; the more recent event will be
   * ranked higher.
   * Makes the assumption that all events are NOT in the past.
   * 
   * @param user The user for whom the events are ranked
   * @param unrankedEvents A {@link Set} of events that need to be ranked
   * @return A {@link List} of events that is ranked according to
   * each element's score
   */
  public static List<Event> rankEvents(User user, Set<Event> unrankedEvents) {
    List<Event> rankedEvents = new ArrayList<>(unrankedEvents);
    Collections.sort(rankedEvents,
        (Event event1, Event event2) -> {
          int comparison = getEventScore(user, event1).compareTo(getEventScore(user, event2));
          if (comparison == 0) {
            comparison = event2.getDate().compareTo(event1.getDate());
          }
          return comparison;
        }
    );
    Collections.reverse(rankedEvents);
    return rankedEvents;
  }

  private static Integer getEventScore(User user, Event event) {
    Set<String> interestsAndSkills = user.getInterests();
    interestsAndSkills.addAll(user.getSkills());
    Set<String> labelsAndSkills = event.getLabels();
    for (VolunteeringOpportunity opportunity : event.getOpportunities()) {
      labelsAndSkills.addAll(opportunity.getRequiredSkills());
    }
    return Sets.intersection(interestsAndSkills, labelsAndSkills).size();
  }
}

@@ -248,63 +248,8 @@
 ns;%0A
-import java.util.Comparator;%0Aimport java.util.HashSet;%0A
 impo
@@ -369,21 +369,16 @@
 s score.
-%0A   *
  Breaks 
@@ -420,16 +420,21 @@
 e recent
+%0A   *
  event w
@@ -439,21 +439,16 @@
  will be
-%0A   *
  ranked 
@@ -454,21 +454,16 @@
  higher.
-%0A   *
  Makes t
@@ -715,21 +715,16 @@
 rding to
-%0A   *
  each el
@@ -907,16 +907,25 @@
 ns.sort(
+%0A        
 rankedEv
@@ -1221,21 +1221,16 @@
        %7D
-%0A    
 );%0A    C

Fix EventRanker presubmit failures