-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyCalendar.java
122 lines (108 loc) · 3.96 KB
/
MyCalendar.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright 2022 The Bank of New York Mellon.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package bnymellon.codekatas.calendarkata;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.Month;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.TimeZone;
import org.eclipse.collections.api.RichIterable;
import org.eclipse.collections.api.block.function.Function2;
import org.eclipse.collections.api.block.predicate.Predicate2;
import org.eclipse.collections.api.list.MutableList;
import org.eclipse.collections.api.multimap.sortedset.MutableSortedSetMultimap;
import org.eclipse.collections.api.set.sorted.SortedSetIterable;
import org.eclipse.collections.impl.factory.Lists;
import org.eclipse.collections.impl.factory.Multimaps;
import org.threeten.extra.Interval;
public class MyCalendar
{
private TimeZone timezone = TimeZone.getDefault();
private MutableSortedSetMultimap<LocalDate, Meeting> meetings;
public MyCalendar(TimeZone timezone)
{
this.timezone = timezone;
this.meetings = Multimaps.mutable.sortedSet.with(Meeting.COMPARATOR);
}
public ZoneId getZoneId()
{
return this.timezone.toZoneId();
}
public FullMonth getMeetingsForYearMonth(int year, Month month)
{
return new FullMonth(LocalDate.of(year, month, 1), this.meetings);
}
public SortedSetIterable<Meeting> getMeetingsForDate(LocalDate date)
{
SortedSetIterable<Meeting> set = this.meetings.get(date);
return set;
}
public WorkWeek getMeetingsForWorkWeekOf(LocalDate value)
{
return new WorkWeek(value, this.meetings);
}
public FullWeek getMeetingsForFullWeekOf(LocalDate value)
{
return new FullWeek(value, this.meetings);
}
public boolean addMeeting(String subject, LocalDate date, LocalTime startTime, Duration duration)
{
if (!this.hasOverlappingMeeting(date, startTime, duration))
{
Meeting meeting = new Meeting(subject, date, startTime, duration, this.getZoneId());
return this.meetings.put(date, meeting);
}
return false;
}
/**
* TODO Implement this method.
*
* Hint: Look at {@link Meeting#getInterval()}
* Hint: Look at {@link Interval#overlaps(Interval)}
* Hint: Look at {@link MyCalendar#getMeetingsForDate(LocalDate)}
* Hint: Look at {@link RichIterable#anySatisfyWith(Predicate2, Object)}
*/
public boolean hasOverlappingMeeting(LocalDate date, LocalTime startTime, Duration duration)
{
return false;
}
/**
* TODO Implement this method. Available timeslots include all times from {@link LocalTime#MIN}
* and between meetings and up to {@link LocalTime#MAX}
*
* Hint: Look at {@link MyCalendar#getMeetingsForDate(LocalDate)}
* Hint: Look at {@link RichIterable#injectInto(Object, Function2)}
* Hint: Look at {@link LocalDate#atTime(LocalTime)}
* Hint: Look at {@link LocalDateTime#atZone(ZoneId)}
* Hint: Look at {@link ZonedDateTime#toInstant()}
* Hint: Look at {@link Interval#of(Instant, Duration)}
*/
public MutableList<Interval> getAvailableTimeslots(LocalDate date)
{
return Lists.mutable.empty();
}
@Override
public String toString()
{
return "MyCalendar(" +
"meetings=" + this.meetings +
')';
}
}