diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 59d2f13..c5ebe16 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -10,11 +10,11 @@ jobs: build: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK - uses: actions/setup-java@v3 + uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' cache: maven - name: Make sure that the API can compile diff --git a/pom.xml b/pom.xml index 10a3f34..67fa1f5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,11 +6,11 @@ io.github.fontysvenlo informaticspom - 1.3.3 + 1.3 io.github.fontysvenlo.alda appointmentplanner_api - 1.2.2 + 1.3 jar ALDA AppointmentPlanner API diff --git a/src/main/java/appointmentplanner/api/AbstractAPFactory.java b/src/main/java/appointmentplanner/api/AbstractAPFactory.java index cd91802..81127bb 100644 --- a/src/main/java/appointmentplanner/api/AbstractAPFactory.java +++ b/src/main/java/appointmentplanner/api/AbstractAPFactory.java @@ -20,8 +20,8 @@ public interface AbstractAPFactory { * @param endTime no appointments end after this time * @return LocalDayPlan object. */ - default LocalDayPlan createLocalDayPlan( LocalDay day, LocalTime startTime, LocalTime endTime ) { - return createLocalDayPlan( day, day.ofLocalTime( startTime ), day.ofLocalTime( endTime ) ); + default LocalDayPlan createLocalDayPlan(LocalDay day, LocalTime startTime, LocalTime endTime) { + return createLocalDayPlan(day, day.ofLocalTime(startTime), day.ofLocalTime(endTime)); } /** @@ -32,37 +32,21 @@ default LocalDayPlan createLocalDayPlan( LocalDay day, LocalTime startTime, Loca * @param end no appointments end after this time * @return LocalDayPlan object. */ - LocalDayPlan createLocalDayPlan( LocalDay day, Instant start, Instant end ); + LocalDayPlan createLocalDayPlan(LocalDay day, Instant start, Instant end); /** * Factory method to create an AppointmentData object without specified - * startTime. The start time will be set (in an Appointment) as soon as the + * startTime. The start time will be set (in an Appointment) as soon as the * appointment is added to the Day schedule. * * @param description of the appointment * @param duration of the appointment - * @param priority of the appointment * @return AppointmentData object. * @throws NullPointerException if any of the parameters are null */ - AppointmentData createAppointmentData( String description, - Duration duration, - Priority priority ); - - /** - * Factory method to create an AppointmentData object without specified - * startTime. The start time will be set (in an Appointment) as soon as the - * appointment is added to the Day schedule. The priority is set as LOW by default. - * - * @param description of the appointment - * @param duration of the appointment - * @return Appointment object. - * @throws NullPointerException if any of the parameters are null - */ - default AppointmentData createAppointmentData( String description, Duration duration ) { - return createAppointmentData( description, duration, Priority.LOW ); - } + AppointmentData createAppointmentData(String description, + Duration duration); /** * Create an appointmentRequest with a required start time. @@ -71,8 +55,8 @@ default AppointmentData createAppointmentData( String description, Duration dura * @param startTime time of the request * @return the request. */ - default AppointmentRequest createAppointmentRequest( AppointmentData data, LocalTime startTime ) { - return createAppointmentRequest( data, startTime, TimePreference.UNSPECIFIED ); + default AppointmentRequest createAppointmentRequest(AppointmentData data, LocalTime startTime) { + return createAppointmentRequest(data, startTime, TimePreference.UNSPECIFIED); } /** @@ -82,8 +66,8 @@ default AppointmentRequest createAppointmentRequest( AppointmentData data, Local * @param preference for time, early or late * @return the request */ - default AppointmentRequest createAppointmentRequest( AppointmentData appData, TimePreference preference ) { - return createAppointmentRequest( appData, null, preference ); + default AppointmentRequest createAppointmentRequest(AppointmentData appData, TimePreference preference) { + return createAppointmentRequest(appData, null, preference); } /** @@ -95,9 +79,9 @@ default AppointmentRequest createAppointmentRequest( AppointmentData appData, Ti * @param fallBack when time not available, use fallback TimePreference * @return the request */ - AppointmentRequest createAppointmentRequest( AppointmentData appointmentData, + AppointmentRequest createAppointmentRequest(AppointmentData appointmentData, LocalTime preferredStart, - TimePreference fallBack ); + TimePreference fallBack); /** * Create a time slot between two times. @@ -106,7 +90,7 @@ AppointmentRequest createAppointmentRequest( AppointmentData appointmentData, * @param end date+time * @return the time slot */ - TimeSlot between( Instant start, Instant end ); + TimeSlot between(Instant start, Instant end); /** * Compute time slot on a date between given start- and endTime. @@ -119,10 +103,10 @@ AppointmentRequest createAppointmentRequest( AppointmentData appointmentData, * @param endTime end time * @return the timeslot */ - default TimeSlot between( LocalDay day, LocalTime startTime, LocalTime endTime ) { + default TimeSlot between(LocalDay day, LocalTime startTime, LocalTime endTime) { boolean endBeforeOrAtStart = !endTime.isAfter(startTime); - Instant start = day.ofLocalTime( startTime ); - Instant end = (endBeforeOrAtStart) ? day.plusDays( 1 ).ofLocalTime( endTime ) : day.ofLocalTime( endTime ); - return between( start, end ); + Instant start = day.ofLocalTime(startTime); + Instant end = (endBeforeOrAtStart) ? day.plusDays(1).ofLocalTime(endTime) : day.ofLocalTime(endTime); + return between(start, end); } } diff --git a/src/main/java/appointmentplanner/api/Appointment.java b/src/main/java/appointmentplanner/api/Appointment.java index f0eaf08..bd8da72 100644 --- a/src/main/java/appointmentplanner/api/Appointment.java +++ b/src/main/java/appointmentplanner/api/Appointment.java @@ -18,54 +18,22 @@ * @author Richard van den Ham {@code r.vandenham@fontys.nl} * @author Pieter van den Hombergh {@code p.vandenhombergh@fontys.nl} */ -public interface Appointment extends TimeSlot, AppointmentData { - - /** - * Get the priority of this appointment. - * - * @return Priority. - */ - @Override - Priority getPriority(); - - /** - * Get the appointment data for this appointment. - * - * @return the data - */ - AppointmentData getAppointmentData(); +public interface Appointment extends TimeSlot { /** * Get the request that led to this appointment. * * @return the request. */ - AppointmentRequest getRequest(); + AppointmentRequest request(); /** - * Override the default toString. toString() returns startTime, endTime, - * description and priority like: "2020-09-12 14:00 - 15:55 ALDA Lesson - * (HIGH)" This will make your testing and debugging life so much easier. + * Override the default toString. toString() returns startTime, endTime and description + * like: "2020-09-12 14:00 - 15:55 ALDA Lesson" + * This will make your testing and debugging life so much easier. * * @return String representation of Appointment. */ @Override String toString(); - - /** - * Defines equality. Must be based on all fields of this class. - * - * @param obj the other object to check equality with - * @return true if the two appointments are equal - */ - @Override - public boolean equals(Object obj); - - /** - * Calculate a hash code value for the object. - * - * @return hashCode for this object - */ - @Override - public int hashCode(); } diff --git a/src/main/java/appointmentplanner/api/AppointmentData.java b/src/main/java/appointmentplanner/api/AppointmentData.java index 5676c36..2572242 100644 --- a/src/main/java/appointmentplanner/api/AppointmentData.java +++ b/src/main/java/appointmentplanner/api/AppointmentData.java @@ -9,7 +9,7 @@ * taking 45 minutes. * * Another example is having a treatment at a dentist or a beauty parlor. The - * duration, priority, and description are known, but there is no time or date + * duration and description are known, but there is no time or date * allocated yet. * * @author Pieter van den Hombergh {@code p.vandenhombergh@fontys.nl} @@ -21,45 +21,20 @@ public interface AppointmentData { * * @return the duration of the appointment. */ - Duration getDuration(); + Duration duration(); /** * The description of the appointment. * * @return non-empty string describing the appointment. */ - String getDescription(); + String description(); /** - * Get the priority for the appointment. - * - * @return the priority - */ - Priority getPriority(); - - /** - * Get the textual representation of AppointmentData. Contains description, - * duration and priority. + * Get the textual representation of AppointmentData. Contains description and duration. * * @return AppointmentData text. */ @Override String toString(); - - /** - * Defines equality. Must be based on all fields of this class. - * - * @param obj the other object to check equality with - * @return true if the two appointments are equal - */ - @Override - public boolean equals(Object obj); - - /** - * Calculate a hash code value for the object. - * - * @return hashCode for this object - */ - @Override - public int hashCode(); } diff --git a/src/main/java/appointmentplanner/api/AppointmentRequest.java b/src/main/java/appointmentplanner/api/AppointmentRequest.java index 83c268e..e640c99 100644 --- a/src/main/java/appointmentplanner/api/AppointmentRequest.java +++ b/src/main/java/appointmentplanner/api/AppointmentRequest.java @@ -28,7 +28,7 @@ * @author Pieter van den Hombergh * @author Richard van den Ham */ -public interface AppointmentRequest extends AppointmentData { +public interface AppointmentRequest { //TODO Specify how to deal with TimePreferences EARLIEST_AFTER and LATEST_BEFORE together with startTime null @@ -36,11 +36,12 @@ public interface AppointmentRequest extends AppointmentData { /** * Get the start time of the intended appointment. * If the time is not specified, this method may return null. + * * @param onDay the LocalDay the time is on. * @return the start time as instant, potentially null. */ - default Instant getStart( LocalDay onDay ) { - return onDay.ofLocalTime( getStartTime() ); + default Instant start(LocalDay onDay) { + return onDay.ofLocalTime(startTime()); } /** @@ -48,14 +49,14 @@ default Instant getStart( LocalDay onDay ) { * * @return the start time */ - LocalTime getStartTime(); + LocalTime startTime(); /** * Get the appointment details of this appointment. * * @return the data */ - AppointmentData getAppointmentData(); + AppointmentData appointmentData(); /** * Time preference given with this appointment request. @@ -63,7 +64,7 @@ default Instant getStart( LocalDay onDay ) { * * @return the time preference */ - default TimePreference getTimePreference() { + default TimePreference timePreference() { return TimePreference.UNSPECIFIED; } @@ -71,25 +72,7 @@ default TimePreference getTimePreference() { * Get the duration of the appointment request. * @return the duration of the request */ - @Override - default Duration getDuration() { - return getAppointmentData().getDuration(); + default Duration duration() { + return appointmentData().duration(); } - - /** - * Defines equality, must be based on all fields of this class. - * @param obj the other object to check equality with - * @return true if the two appointments are equal - */ - @Override - public boolean equals( Object obj ); - - /** - * Calculate a hash code value for the object. - * @return hashCode for this object. - */ - @Override - public int hashCode(); - - } diff --git a/src/main/java/appointmentplanner/api/LocalDay.java b/src/main/java/appointmentplanner/api/LocalDay.java index 49d7c95..cea67c1 100644 --- a/src/main/java/appointmentplanner/api/LocalDay.java +++ b/src/main/java/appointmentplanner/api/LocalDay.java @@ -11,44 +11,23 @@ * * @author Pieter van den Hombergh {@code p.vandenhombergh@fontys.nl} */ -public class LocalDay { - - private final ZoneId zone; - private final LocalDate date; +public record LocalDay(ZoneId zone, LocalDate date) { /** - * Create a local day in the given timezone at the given date. - * - * @param zone the timezone to use - * @param date the LocalDate to use + * Default constructor. Make sure zone and date are not null. + * @param zone the zoneId + * @param date the date */ - public LocalDay( ZoneId zone, LocalDate date ) { - this.zone = zone; - this.date = date; + public LocalDay { + Objects.requireNonNull(zone, "zone cannot be null"); + Objects.requireNonNull(date, "date cannot be null"); } /** * Create a LocalDay based on the system default timezone and the current date. */ public LocalDay() { - this( ZoneId.systemDefault(), LocalDate.now() ); - } - - /** - * Get the date. - * @return the date - */ - public LocalDate getDate() { - return date; - } - - /** - * Get the timezone identifier. - * - * @return timezone identifier - */ - public ZoneId getZone() { - return zone; + this(ZoneId.systemDefault(), LocalDate.now()); } /** @@ -57,8 +36,8 @@ public ZoneId getZone() { * @param localTime the local time * @return the time as an instant at this date and timezone */ - public Instant ofLocalTime( LocalTime localTime ) { - return localTime.atDate( date ).atZone( zone ).toInstant(); + public Instant ofLocalTime(LocalTime localTime) { + return localTime.atDate(date).atZone(zone).toInstant(); } /** @@ -67,8 +46,8 @@ public Instant ofLocalTime( LocalTime localTime ) { * @param instant to convert to LocalTime * @return the LocalTime of the given instant */ - public LocalTime timeOfInstant( Instant instant ) { - return instant.atZone( zone ).toLocalTime(); + public LocalTime timeOfInstant(Instant instant) { + return instant.atZone(zone).toLocalTime(); } /** @@ -77,8 +56,8 @@ public LocalTime timeOfInstant( Instant instant ) { * @param instant to convert to LocalDate * @return the LocalDate of the given instant */ - public LocalDate dateOfInstant( Instant instant ) { - return instant.atZone( zone ).toLocalDate(); + public LocalDate dateOfInstant(Instant instant) { + return instant.atZone(zone).toLocalDate(); } /** @@ -87,8 +66,8 @@ public LocalDate dateOfInstant( Instant instant ) { * @param days to add * @return the new LocalDay shifted forward or backward in time. */ - public LocalDay plusDays( int days ) { - return new LocalDay( zone, date.plusDays( days ) ); + public LocalDay plusDays(int days) { + return new LocalDay(zone, date.plusDays(days)); } /** @@ -98,8 +77,8 @@ public LocalDay plusDays( int days ) { * @param m the minutes * @return Instant at the given ours and minutes */ - public Instant at( int hm, int m ) { - return ofLocalTime( LocalTime.of( hm, m, 0 ) ); + public Instant at(int hm, int m) { + return ofLocalTime(LocalTime.of(hm, m, 0)); } /** @@ -110,35 +89,4 @@ public Instant at( int hm, int m ) { public static LocalDay now() { return new LocalDay(); } - - @Override - public String toString() { - return "LocalDay{" + "zone=" + zone + ", date=" + date + '}'; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 73 * hash + Objects.hashCode( this.zone ); - hash = 73 * hash + Objects.hashCode( this.date ); - return hash; - } - - @Override - public boolean equals( Object obj ) { - if ( this == obj ) { - return true; - } - if ( obj == null ) { - return false; - } - if ( getClass() != obj.getClass() ) { - return false; - } - final LocalDay other = (LocalDay) obj; - if ( !Objects.equals( this.zone, other.zone ) ) { - return false; - } - return Objects.equals( this.date, other.date ); - } } diff --git a/src/main/java/appointmentplanner/api/LocalDayPlan.java b/src/main/java/appointmentplanner/api/LocalDayPlan.java index c446c47..5bedc23 100644 --- a/src/main/java/appointmentplanner/api/LocalDayPlan.java +++ b/src/main/java/appointmentplanner/api/LocalDayPlan.java @@ -29,7 +29,7 @@ public interface LocalDayPlan { * * @return the day */ - LocalDay getDay(); + LocalDay day(); /** * Start time of the day, inclusive. @@ -51,15 +51,15 @@ public interface LocalDayPlan { * * @return the timeline used by this LocalDayPlan */ - Timeline getTimeline(); + Timeline timeline(); /** * Get the allowed first time for this day. * * @return the start time of this plan */ - default LocalTime getStartTime() { - return getDay().timeOfInstant(startOfDay() ); + default LocalTime startTime() { + return day().timeOfInstant(startOfDay()); } /** @@ -67,8 +67,8 @@ default LocalTime getStartTime() { * * @return the end time in this plan */ - default LocalTime getEndTime() { - return getDay().timeOfInstant(endOfDay() ); + default LocalTime endTime() { + return day().timeOfInstant(endOfDay()); } /** @@ -80,10 +80,10 @@ default LocalTime getEndTime() { * @return an optional of Appointment, which is present when the appointment * was created successfully, or empty when not successful. */ - default Optional addAppointment( AppointmentData appointmentData, + default Optional addAppointment(AppointmentData appointmentData, LocalTime start, - TimePreference fallback ) { - return getTimeline().addAppointment( getDay(), appointmentData, start, fallback ); + TimePreference fallback) { + return timeline().addAppointment(day(), appointmentData, start, fallback); } /** @@ -94,21 +94,22 @@ default Optional addAppointment( AppointmentData appointmentData, * @param startTime fixed time * @return Optional Appointment */ - default Optional addAppointment( AppointmentData appointmentData, LocalTime startTime ) { - return getTimeline().addAppointment( getDay(), appointmentData, startTime ); + default Optional addAppointment(AppointmentData appointmentData, LocalTime startTime) { + return timeline().addAppointment(day(), appointmentData, startTime); } /** - * Add and appointment with time preference. This request can fail (Optional - * is not present) if the data's duration does not fit in the (already - * planned day). + * Add and appointment with time preference. This request can fail (Optional is not present) + * if the data's duration does not fit in the (already planned day). + * + * This method only supports TimePreferences EARLIEST or LATEST; Other values are defaulted to EARLIEST * * @param appointmentData data * @param preference time preference * @return Optional Appointment */ - default Optional addAppointment( AppointmentData appointmentData, TimePreference preference ) { - return getTimeline().addAppointment( getDay(), appointmentData, preference ); + default Optional addAppointment(AppointmentData appointmentData, TimePreference preference) { + return timeline().addAppointment(day(), appointmentData, preference); } /** @@ -117,8 +118,8 @@ default Optional addAppointment( AppointmentData appointmentData, T * @param appointment the appointment to remove * @return AppointmentRequest, the original appointment request */ - default AppointmentRequest removeAppointment( Appointment appointment ) { - return getTimeline().removeAppointment( appointment ); + default AppointmentRequest removeAppointment(Appointment appointment) { + return timeline().removeAppointment(appointment); } /** @@ -127,69 +128,69 @@ default AppointmentRequest removeAppointment( Appointment appointment ) { * @param filter to remove all appointments that match * @return all appointment requests of removed appointments */ - default List removeAppointments( Predicate filter ) { - return getTimeline().removeAppointments( filter ); + default List removeAppointments(Predicate filter) { + return timeline().removeAppointments(filter); } /** - * {@link Timeline#getAppointments()}. + * {@link Timeline#appointments()}. * * @return all appointments */ default List getAppointments() { - return getTimeline().getAppointments(); + return timeline().appointments(); } /** - * See {@link Timeline#getMatchingFreeSlotsOfDuration(Duration, List)}. + * See {@link Timeline#findMatchingFreeSlotsOfDuration(Duration, List)}. * * @param duration Minimum duration of the slots * @param plans that could have common gaps * @return the list of gaps this and each of the other plans have in common * with a minimum length of duration. */ - default List getMatchingFreeSlotsOfDuration( Duration duration, List plans ) { - return getTimeline().getMatchingFreeSlotsOfDuration( duration, plans.stream().map( LocalDayPlan::getTimeline ).collect( toList() ) ); + default List getMatchingFreeSlotsOfDuration(Duration duration, List plans) { + return timeline().findMatchingFreeSlotsOfDuration(duration, plans.stream().map(LocalDayPlan::timeline).collect(toList())); } /** - * See {@link Timeline#getGapsFitting(Duration)}. + * See {@link Timeline#findGapsFitting(Duration)}. * * @param duration the minimum duration that should fit * @return list of timeslots that fit the duration */ - default List getGapsFitting( Duration duration ) { - return getTimeline().getGapsFitting( duration ); + default List getGapsFitting(Duration duration) { + return timeline().findGapsFitting(duration); } /** - * {@link Timeline#getGapsFittingReversed(Duration)}. + * {@link Timeline#findGapsFittingReversed(Duration)}. * * @param duration the minimum duration that should fit * @return list of timeslots that fit the duration */ - default List getGapsFittingReversed( Duration duration ) { - return getTimeline().getGapsFittingReversed( duration ); + default List getGapsFittingReversed(Duration duration) { + return timeline().findGapsFittingReversed(duration); } /** - * See{@link Timeline#getGapsFittingLargestFirst(Duration)}. + * See{@link Timeline#findGapsFittingLargestFirst(Duration)}. * * @param duration the minimum duration * @return list of gaps fitting the duration */ - default List getGapsFittingLargestFirst( Duration duration ) { - return getTimeline().getGapsFittingLargestFirst( duration ); + default List getGapsFittingLargestFirst(Duration duration) { + return timeline().findGapsFittingLargestFirst(duration); } /** - * {@link Timeline#getGapsFittingSmallestFirst(Duration)}. + * {@link Timeline#findGapsFittingSmallestFirst(Duration)}. * * @param duration the minimum duration * @return list of timeslots fitting the duration */ - default List getGapsFittingSmallestFirst( Duration duration ) { - return getTimeline().getGapsFittingSmallestFirst( duration ); + default List getGapsFittingSmallestFirst(Duration duration) { + return timeline().findGapsFittingSmallestFirst(duration); } /** @@ -198,8 +199,8 @@ default List getGapsFittingSmallestFirst( Duration duration ) { * @param duration the minimum duration * @return true of a gap is available, false otherwise */ - default boolean canAddAppointmentOfDuration( Duration duration ) { - return getTimeline().canAddAppointmentOfDuration( duration ); + default boolean canAddAppointmentOfDuration(Duration duration) { + return timeline().canAddAppointmentOfDuration(duration); } /** @@ -208,8 +209,8 @@ default boolean canAddAppointmentOfDuration( Duration duration ) { * @param filter to find appointments * @return list of appointments that fit the filter */ - default List findAppointments( Predicate filter ) { - return getTimeline().findAppointments( filter ); + default List findAppointments(Predicate filter) { + return timeline().findAppointments(filter); } /** @@ -227,8 +228,8 @@ default List findAppointments( Predicate filter ) { * @param appointment the appointment to check * @return true if present, false otherwise */ - default boolean contains( Appointment appointment ) { - return getTimeline().contains( appointment ); + default boolean contains(Appointment appointment) { + return timeline().contains(appointment); } /** @@ -236,17 +237,17 @@ default boolean contains( Appointment appointment ) { * * @return the date according to this LocalDayPlan's time zone */ - default LocalDate getDate() { - return getDay().getDate(); + default LocalDate date() { + return day().date(); } /** - * {@link Timeline#getNrOfAppointments()}. + * {@link Timeline#nrOfAppointments()}. * * @return number of appointments */ - default int getNrOfAppointments() { - return getTimeline().getNrOfAppointments(); + default int nrOfAppointments() { + return timeline().nrOfAppointments(); } /** @@ -256,8 +257,8 @@ default int getNrOfAppointments() { * @param minute sic * @return the point in time as Instant */ - default Instant at( int hour, int minute ) { - return getDay().at( hour, minute ); + default Instant at(int hour, int minute) { + return day().at(hour, minute); } } diff --git a/src/main/java/appointmentplanner/api/Priority.java b/src/main/java/appointmentplanner/api/Priority.java deleted file mode 100644 index de5ad90..0000000 --- a/src/main/java/appointmentplanner/api/Priority.java +++ /dev/null @@ -1,24 +0,0 @@ -/* - * Copyright (c) 2019 Informatics Fontys FHTenL University of Applied Science Venlo - */ -package appointmentplanner.api; - -/** - * Priority of appointments (not used as part of scheduling). - * - * @author Pieter van den Hombergh {@code p.vandenhombergh@fontys.nl} - */ -public enum Priority { - /** - * Low priority. - */ - LOW, - /** - * Medium priority. - */ - MEDIUM, - /** - * High priority. - */ - HIGH -} diff --git a/src/main/java/appointmentplanner/api/TimeSlot.java b/src/main/java/appointmentplanner/api/TimeSlot.java index 53ad474..8b49a07 100644 --- a/src/main/java/appointmentplanner/api/TimeSlot.java +++ b/src/main/java/appointmentplanner/api/TimeSlot.java @@ -33,7 +33,7 @@ public interface TimeSlot extends Comparable { * * @return the start time */ - Instant getStart(); + Instant start(); /** * Get the end of the TimeSlot. The end time is NOT included in the @@ -41,7 +41,7 @@ public interface TimeSlot extends Comparable { * * @return the end time */ - Instant getEnd(); + Instant end(); /** * Get the duration of this slot. @@ -51,7 +51,7 @@ public interface TimeSlot extends Comparable { * @return the duration as Duration */ default Duration duration() { - return Duration.between( getStart(), getEnd() ); + return Duration.between(start(), end()); } /** @@ -61,8 +61,8 @@ default Duration duration() { * @return comparison result, less than 0, 0 or greater 0. */ @Override - public default int compareTo( TimeSlot other ) { - return this.duration().compareTo( other.duration() ); + public default int compareTo(TimeSlot other) { + return this.duration().compareTo(other.duration()); } /** @@ -72,8 +72,8 @@ public default int compareTo( TimeSlot other ) { * @return true if start and end are sufficiently apart to fit the given * duration. */ - default boolean fits( Duration duration ) { - return this.duration().compareTo( duration ) >= 0; + default boolean fits(Duration duration) { + return this.duration().compareTo(duration) >= 0; } /** @@ -83,9 +83,9 @@ default boolean fits( Duration duration ) { * @return true if other does not start earlier nor ends earlier than this * time slot. */ - default boolean fits( TimeSlot other ) { - return this.getStart().compareTo( other.getStart() ) <= 0 - && this.getEnd().compareTo( other.getEnd() ) >= 0; + default boolean fits(TimeSlot other) { + return this.start().compareTo(other.start()) <= 0 + && this.end().compareTo(other.end()) >= 0; } /** @@ -94,8 +94,8 @@ default boolean fits( TimeSlot other ) { * @param day for the time * @return end Time. */ - default LocalTime getEndTime( LocalDay day ) { - return day.timeOfInstant( getEnd() ); + default LocalTime endTime(LocalDay day) { + return day.timeOfInstant(end()); } /** @@ -104,8 +104,8 @@ default LocalTime getEndTime( LocalDay day ) { * @param day for the time * @return start Time */ - default LocalTime getStartTime( LocalDay day ) { - return day.timeOfInstant( getStart() ); + default LocalTime startTime(LocalDay day) { + return day.timeOfInstant(start()); } /** @@ -114,8 +114,8 @@ default LocalTime getStartTime( LocalDay day ) { * @param day provides time zone * @return the date on which the TimeSlot starts. */ - default LocalDate getStartDate( LocalDay day ) { - return day.dateOfInstant( getStart() ); + default LocalDate startDate(LocalDay day) { + return day.dateOfInstant(start()); } /** @@ -124,7 +124,7 @@ default LocalDate getStartDate( LocalDay day ) { * @param day provides time zone * @return the date on which the TimeSlot ends. */ - default LocalDate getEndDate( LocalDay day ) { - return day.dateOfInstant( getEnd() ); + default LocalDate endDate(LocalDay day) { + return day.dateOfInstant(end()); } } diff --git a/src/main/java/appointmentplanner/api/Timeline.java b/src/main/java/appointmentplanner/api/Timeline.java index fe8c7b7..ca1f562 100644 --- a/src/main/java/appointmentplanner/api/Timeline.java +++ b/src/main/java/appointmentplanner/api/Timeline.java @@ -34,7 +34,7 @@ public interface Timeline { * * @return Number of appointments on this timeline. */ - int getNrOfAppointments(); + int nrOfAppointments(); /** * Get the number of gaps between start and en of day and between the @@ -87,7 +87,7 @@ public interface Timeline { * appointment can't be met. * @throws NullPointerException If the appointmentData is null */ - Optional addAppointment( LocalDay forDay, AppointmentData appointment, TimePreference timePreference ); + Optional addAppointment(LocalDay forDay, AppointmentData appointment, TimePreference timePreference); /** * Add appointment with a fixed time. If the requested slot is available, @@ -99,7 +99,7 @@ public interface Timeline { * @param startTime preferred start time of the appointment * @return the added appointment or an empty Optional on failure. */ - Optional addAppointment( LocalDay forDay, AppointmentData appointment, LocalTime startTime ); + Optional addAppointment(LocalDay forDay, AppointmentData appointment, LocalTime startTime); /** * Create an appointment based on previous appointmentRequest. @@ -108,10 +108,10 @@ public interface Timeline { * @param appointmentRequest for this appointment. * @return the added appointment or an empty Optional on failure. */ - default Optional addAppointment( LocalDay forDay, - AppointmentRequest appointmentRequest ) { - return addAppointment( forDay, appointmentRequest.getAppointmentData(), - appointmentRequest.getStartTime() ); + default Optional addAppointment(LocalDay forDay, + AppointmentRequest appointmentRequest) { + return addAppointment(forDay, appointmentRequest.appointmentData(), + appointmentRequest.startTime()); } /** @@ -126,8 +126,8 @@ default Optional addAppointment( LocalDay forDay, * apply. * @return the added appointment or an empty Optional on failure. */ - Optional addAppointment( LocalDay forDay, AppointmentData appointment, - LocalTime startTime, TimePreference fallback ); + Optional addAppointment(LocalDay forDay, AppointmentData appointment, + LocalTime startTime, TimePreference fallback); /** * Removes the given appointment, returning the AppointmentRequest of that appointment, if @@ -138,7 +138,7 @@ Optional addAppointment( LocalDay forDay, AppointmentData appointme * @return the AppointmentRequest of the removed appointment or null * if the appointment is not found. */ - AppointmentRequest removeAppointment( Appointment appointment ); + AppointmentRequest removeAppointment(Appointment appointment); /** * Removes appointments with description that matches a filter. @@ -146,7 +146,7 @@ Optional addAppointment( LocalDay forDay, AppointmentData appointme * @param filter to determine which items to remove. * @return the list of AppointmentRequests of removed appointments. */ - List removeAppointments( Predicate filter ); + List removeAppointments(Predicate filter); /** * Finds all appointments matching given filter. @@ -154,15 +154,15 @@ Optional addAppointment( LocalDay forDay, AppointmentData appointme * @param filter to determine which items to select. * @return list of matching appointments. */ - List findAppointments( Predicate filter ); + List findAppointments(Predicate filter); /** * Finds all appointments for this TimeLine. * * @return list of all appointments. */ - default List getAppointments() { - return appointmentStream().collect( Collectors.toList() ); + default List appointments() { + return appointmentStream().collect(Collectors.toList()); } /** @@ -178,7 +178,7 @@ default List getAppointments() { * @param appointment to search for. * @return true if the Appointment is part of the Timeline, false otherwise. */ - boolean contains( Appointment appointment ); + boolean contains(Appointment appointment); /** @@ -188,7 +188,7 @@ default List getAppointments() { * @param duration the requested duration for an appointment * @return a list of gaps in which the appointment can be scheduled. */ - List getGapsFitting( Duration duration ); + List findGapsFitting(Duration duration); /** * Check if an appointment of the given duration can be scheduled. @@ -196,7 +196,7 @@ default List getAppointments() { * @param duration of the appointment * @return true is there is a sufficiently big gap, false otherwise */ - boolean canAddAppointmentOfDuration( Duration duration ); + boolean canAddAppointmentOfDuration(Duration duration); /** * This method finds all time gaps that can accommodate an appointment of @@ -205,7 +205,7 @@ default List getAppointments() { * @param duration the requested duration for an appointment * @return a list of start times on which an appointment can be scheduled */ - List getGapsFittingReversed( Duration duration ); + List findGapsFittingReversed(Duration duration); /** * Get the gaps matching the given duration, smallest fitting first. @@ -213,7 +213,7 @@ default List getAppointments() { * @param duration required * @return list of all gaps fitting, ordered, smallest gap first. */ - List getGapsFittingSmallestFirst( Duration duration ); + List findGapsFittingSmallestFirst(Duration duration); /** * Get the gaps matching the given duration, largest fitting first. @@ -221,7 +221,7 @@ default List getAppointments() { * @param duration required * @return list of all gaps fitting, ordered, largest gap first. */ - List getGapsFittingLargestFirst( Duration duration ); + List findGapsFittingLargestFirst(Duration duration); /** * Find matching free time slots in this and other TimeLines. To facilitate @@ -231,5 +231,5 @@ default List getAppointments() { * @param other day plans * @return the list of free slots that all DayPlans share. */ - List getMatchingFreeSlotsOfDuration( Duration minLength, List other ); + List findMatchingFreeSlotsOfDuration(Duration minLength, List other); }