/**

  • Represents the activity subsystem.

  • This class manages a list of activities and provides various operations for adding, removing, and retrieving activities.

  • @since GPT-3.5-Turbo */ public class ActivitySubSystem { ArrayList activities = new ArrayList<>();

    /**

    • Adds the specified activity to the activity subsystem.
    • @param activity the activity to be added */ public void addActivity(Activity activity){ activities.add(activity); }

    /**

    • Removes the activity with the specified id from the activity subsystem.
    • @param id the id of the activity to be removed */ public void removeActivityById(String id) { activities.removeIf(a -> a.id.equals(id)); }

    /**

    • Retrieves the activity with the specified id from the activity subsystem.
    • @param id the id of the activity to be retrieved
    • @return the activity with the specified id, or null if not found */ public Activity getActivityById(String id) { for (Activity a:activities) { if(a.id.equals(id)) return a; } return null; }

    /**

    • Retrieves a list of activities that occur on the specified date.
    • @param date the date for which to retrieve activities
    • @return a list of activities on the specified date */ public ArrayList getActivitiesByDate(Date date) { ArrayList result = new ArrayList<>(); for (Activity activity : activities) { if (activity.getStartTime().before(date) && activity.getEndTime().after(date)) { result.add(activity); } } return result; }

    /**

    • Retrieves the list of all activities in the activity subsystem.
    • @return the list of all activities */ public List getActivityList() { return activities; }

    /**

    • Returns the number of activities associated with the specified team.

    • @param teamId the id of the team

    • @return the number of activities associated with the team */ public int checkActivityNumOfTeam(String teamId) { int count = 0; for (Activity activity:activities) { for(Team team: activity.teams) { if(team.teamId.equals(teamId)) count++; } }

      return count; } }

Java Activity Subsystem: Manage and Retrieve Activities Efficiently

原文地址: https://www.cveoy.top/t/topic/UNG 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录