Package de.xima.fc.appointment
Class BaseAppointmentHelper
- java.lang.Object
-
- de.xima.fc.appointment.BaseAppointmentHelper
-
- Direct Known Subclasses:
AppointmentHelper
public class BaseAppointmentHelper extends Object
Helper methods for the appointment module.- Since:
- 6.5.0
- Author:
- XIMA MEDIA GmbH
-
-
Field Summary
Fields Modifier and Type Field Description static LocalDate
WEEK_START
The week to use for the UI that lets the user configure the availableAppointmentSlot
s.
-
Constructor Summary
Constructors Constructor Description BaseAppointmentHelper()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static List<AppointmentSlot>
applySlotConstraints(List<AppointmentSlot> slots, AppointmentTemplate template)
Sanitizes the given slots so that they conform the restrictions imposed by the given appointment template.static com.google.common.collect.ImmutableRangeSet<Instant>
createClosedDateTimeRanges(List<AppointmentClosingTime> closingTimes, com.google.common.collect.BoundType boundType, ZoneId sourceZone)
Creates the temporal disjoint intervals corresponding the given closing times.static List<AppointmentSlot>
createDefaultSlots()
Creates the defaultAppointmentTemplate.getSlots()
when none are set yet.static AppointmentSlot
createSlot(LocalDateTime dateTime)
Creates a new slot starting at the given date.static com.google.common.collect.Range<LocalDateTime>
getSlotDateTime(AppointmentSlot slot)
static com.google.common.collect.Range<LocalDateTime>
getSlotDateTimeRange(AppointmentSlot slot)
Returns the date time range of the given slot.static LocalDateTime
getSlotFromDateTime(AppointmentSlot slot)
static LocalDateTime
getSlotToDateTime(AppointmentSlot slot)
static LocalTime
getTimeOnGrid(LocalTime time, Duration duration)
Adjusts the given time to a time that lies on the grid defined by the appointment type.static boolean
isSlotOverlapping(AppointmentTemplate template, AppointmentSlot slot)
Checks whether the given slot is overlapping any slot of the given template.static AppointmentSlot
mergeOverlappingSlots(AppointmentSlot lhs, AppointmentSlot rhs)
Takes two overlapping slots and creates a new slot with the start and end time set to the overlapping interval.static List<AppointmentSlot>
mergeOverlappingSlots(List<AppointmentSlot> slots)
Merges all overlapping slots.
-
-
-
Field Detail
-
WEEK_START
public static final LocalDate WEEK_START
The week to use for the UI that lets the user configure the availableAppointmentSlot
s.
-
-
Method Detail
-
applySlotConstraints
public static List<AppointmentSlot> applySlotConstraints(List<AppointmentSlot> slots, AppointmentTemplate template)
Sanitizes the given slots so that they conform the restrictions imposed by the given appointment template.- Parameters:
slots
- Slots to constrain.template
- Template to which the slots must adhere.- Returns:
- A list of slots that is identical to the given list if all slots meet the constraints of the given template. Otherwise, slots may be modified or deleted to meet those constraints.
-
createClosedDateTimeRanges
public static com.google.common.collect.ImmutableRangeSet<Instant> createClosedDateTimeRanges(List<AppointmentClosingTime> closingTimes, com.google.common.collect.BoundType boundType, ZoneId sourceZone)
Creates the temporal disjoint intervals corresponding the given closing times. Closing times are interpreted in the given source time zone and converted to the given target time zone.- Parameters:
closingTimes
- List of closing times to process.boundType
- Whether to create closed or open ranges from the closing times.sourceZone
- The source time zone in which the given closing times are interpreted. Should usually be theAppointmentTemplate.getZoneId()
of theAppointmentClosingTime.getAppointmentTemplate()
.- Returns:
- The disjoint ranges corresponding to the given closing times, converted to the given target time zone.
-
createDefaultSlots
public static List<AppointmentSlot> createDefaultSlots()
Creates the defaultAppointmentTemplate.getSlots()
when none are set yet.- Returns:
- The default slots.
-
createSlot
public static AppointmentSlot createSlot(LocalDateTime dateTime)
Creates a new slot starting at the given date.- Parameters:
dateTime
- Starting date for the new slot.- Returns:
- A new slot that starts at the given date.
-
getSlotDateTime
public static com.google.common.collect.Range<LocalDateTime> getSlotDateTime(AppointmentSlot slot)
- Parameters:
slot
- A slot to process.- Returns:
- The date time range for the given slot that lies in the
WEEK_START
.
-
getSlotDateTimeRange
public static com.google.common.collect.Range<LocalDateTime> getSlotDateTimeRange(AppointmentSlot slot)
Returns the date time range of the given slot.- Parameters:
slot
- A slot to process.- Returns:
- The date time range of the given slot.
-
getSlotFromDateTime
public static LocalDateTime getSlotFromDateTime(AppointmentSlot slot)
- Parameters:
slot
- A slot to use.- Returns:
- The date time for the start of the given slot that lies in the
WEEK_START
.
-
getSlotToDateTime
public static LocalDateTime getSlotToDateTime(AppointmentSlot slot)
- Parameters:
slot
- A slot to use.- Returns:
- The date time for the end of the given slot that lies in the
WEEK_START
.
-
getTimeOnGrid
public static LocalTime getTimeOnGrid(LocalTime time, Duration duration)
Adjusts the given time to a time that lies on the grid defined by the appointment type.- Parameters:
time
- A local time to process.duration
- Duration of the grid.- Returns:
- The given time, adjusted so that is lies on the grid given by the appointment type.
-
isSlotOverlapping
public static boolean isSlotOverlapping(AppointmentTemplate template, AppointmentSlot slot)
Checks whether the given slot is overlapping any slot of the given template.- Parameters:
template
- AnAppointmentTemplate
with slots.slot
- A slot to check.- Returns:
true
if the given slot has any overlap with any slot of the given template.
-
mergeOverlappingSlots
public static AppointmentSlot mergeOverlappingSlots(AppointmentSlot lhs, AppointmentSlot rhs)
Takes two overlapping slots and creates a new slot with the start and end time set to the overlapping interval.- Parameters:
lhs
- First slot to merge.rhs
- Seconds slot to merge.- Returns:
- The merged appointment slot.
-
mergeOverlappingSlots
public static List<AppointmentSlot> mergeOverlappingSlots(List<AppointmentSlot> slots)
Merges all overlapping slots.- Parameters:
slots
- List of slots to merge.- Returns:
- A list of merged slots.
-
-