-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reservations are now shown in event details discord message
- Loading branch information
1 parent
463785a
commit 72cc227
Showing
4 changed files
with
74 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package de.webalf.slotbot.util; | ||
|
||
import de.webalf.slotbot.model.Guild; | ||
import de.webalf.slotbot.model.Squad; | ||
import de.webalf.slotbot.model.dtos.GuildDto; | ||
import de.webalf.slotbot.model.dtos.referenceless.SlotReferencelessDto; | ||
import lombok.NonNull; | ||
import lombok.experimental.UtilityClass; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author Alf | ||
* @since 07.02.2022 | ||
*/ | ||
@UtilityClass | ||
public final class SlotUtils { | ||
/** | ||
* Evaluates the reservation for a slot. Slot reservation or if empty the squad reservation. | ||
* Doesn't return {@code reservedFor} if the whole squad is reserved for the {@link Guild} the squad is reserved for | ||
* | ||
* @param reservedFor reservation of slot | ||
* @param squad the slot is in | ||
* @return effective reservation for display | ||
* @see #getEffectiveReservedForDisplay(GuildDto, GuildDto, List) | ||
*/ | ||
public Guild getEffectiveReservedForDisplay(Guild reservedFor, @NonNull Squad squad) { | ||
final Guild effectiveReservedFor = reservedFor != null ? reservedFor : squad.getReservedFor(); | ||
if (squad.getReservedFor() != null && squad.getReservedFor().equals(effectiveReservedFor) && | ||
squad.getSlotList().stream().allMatch(slot -> effectiveReservedFor.equals(slot.getEffectiveReservedFor()))) { | ||
return null; | ||
} | ||
return effectiveReservedFor; | ||
} | ||
|
||
/** | ||
* Evaluates the reservation for a slot. Slot reservation or if empty the squad reservation. | ||
* Doesn't return {@code squadReservedFor} if the whole squad is reserved for the {@link GuildDto} the squad is reserved for | ||
* | ||
* @param reservedFor reservation of slot | ||
* @param squadReservedFor reservation of slots squad | ||
* @param slotList of slots squad | ||
* @return effective reservation for display | ||
* @see #getEffectiveReservedForDisplay(Guild, Squad) | ||
*/ | ||
public GuildDto getEffectiveReservedForDisplay(GuildDto reservedFor, GuildDto squadReservedFor, List<? extends SlotReferencelessDto> slotList) { | ||
final GuildDto effectiveReservedFor = reservedFor != null ? reservedFor : squadReservedFor; | ||
if (squadReservedFor != null && squadReservedFor.equals(effectiveReservedFor) && | ||
slotList.stream().allMatch(slot -> effectiveReservedFor.equals(slot.getReservedFor() != null ? slot.getReservedFor() : squadReservedFor))) { | ||
return null; | ||
} | ||
return effectiveReservedFor; | ||
} | ||
} |