Skip to content

Commit 565de4a

Browse files
committed
First open source commit for BNY Mellon Code Katas
0 parents  commit 565de4a

File tree

78 files changed

+7951
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+7951
-0
lines changed

CalendarKata/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# **What is the Calendar Kata?**
2+
3+
The Calendar Kata is an advanced kata which can help developers
4+
become familiar with the [Java 8 Date/Time](https://docs.oracle.com/javase/8/docs/api/java/time/package-summary.html)
5+
and [ThreeTen-Extra](http://www.threeten.org/threeten-extra/) libraries.
6+
7+
The domain for the Calendar kata is an object representation of an Outlook Calendar.
8+
There are several domain classes that are shared by all of the exercises. These are
9+
[`MyCalendar`](./src/main/java/bnymellon/codekatas/calendarkata/MyCalendar.java),
10+
[`Meeting`](./src/main/java/bnymellon/codekatas/calendarkata/Meeting.java),
11+
[`WorkWeek`](./src/main/java/bnymellon/codekatas/calendarkata/WorkWeek.java),
12+
[`FullWeek`](./src/main/java/bnymellon/codekatas/calendarkata/FullWeek.java),
13+
[`FullMonth`](./src/main/java/bnymellon/codekatas/calendarkata/FullMonth.java) and
14+
15+
![Diagram](mycalendar.png)
16+
</p>
17+
18+
### How to get started
19+
20+
* There are failing tests in [`MyCalendarTest`](./src/test/java/bnymellon/codekatas/calendarkata/MyCalendarTest.java)
21+
* Make the tests pass by following and completing the TODOs in MyCalendar, WorkWeek, FullMonth and FullWeek.

CalendarKata/mycalendar.png

205 KB
Loading

CalendarKata/pom.xml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright 2017 BNY Mellon.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License");
6+
~ you may not use this file except in compliance with the License.
7+
~ You may obtain a copy of the License at
8+
~
9+
~ http://www.apache.org/licenses/LICENSE-2.0
10+
~
11+
~ Unless required by applicable law or agreed to in writing, software
12+
~ distributed under the License is distributed on an "AS IS" BASIS,
13+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
~ See the License for the specific language governing permissions and
15+
~ limitations under the License.
16+
-->
17+
18+
<project xmlns="http://maven.apache.org/POM/4.0.0"
19+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
20+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>bnymellon.codekatas</groupId>
24+
<artifactId>calendarkata</artifactId>
25+
<version>1.0.0-SNAPSHOT</version>
26+
27+
<properties>
28+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
29+
30+
<java.version>1.8</java.version>
31+
<maven.compiler.source>1.8</maven.compiler.source>
32+
<maven.compiler.target>1.8</maven.compiler.target>
33+
34+
<eclipse-collections.version>9.0.0</eclipse-collections.version>
35+
<threeten-extra.version>1.2</threeten-extra.version>
36+
<junit.version>4.12</junit.version>
37+
</properties>
38+
39+
<dependencies>
40+
41+
<dependency>
42+
<groupId>org.eclipse.collections</groupId>
43+
<artifactId>eclipse-collections-api</artifactId>
44+
<version>${eclipse-collections.version}</version>
45+
</dependency>
46+
47+
<dependency>
48+
<groupId>org.eclipse.collections</groupId>
49+
<artifactId>eclipse-collections</artifactId>
50+
<version>${eclipse-collections.version}</version>
51+
</dependency>
52+
53+
<dependency>
54+
<groupId>org.eclipse.collections</groupId>
55+
<artifactId>eclipse-collections-testutils</artifactId>
56+
<version>${eclipse-collections.version}</version>
57+
<scope>test</scope>
58+
</dependency>
59+
60+
<dependency>
61+
<groupId>org.threeten</groupId>
62+
<artifactId>threeten-extra</artifactId>
63+
<version>${threeten-extra.version}</version>
64+
</dependency>
65+
66+
<dependency>
67+
<groupId>junit</groupId>
68+
<artifactId>junit</artifactId>
69+
<version>${junit.version}</version>
70+
<scope>test</scope>
71+
</dependency>
72+
</dependencies>
73+
74+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2017 BNY Mellon.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bnymellon.codekatas.calendarkata;
18+
19+
import java.time.LocalDate;
20+
21+
import org.eclipse.collections.api.multimap.Multimap;
22+
import org.threeten.extra.LocalDateRange;
23+
24+
public class CalendarWindow
25+
{
26+
LocalDateRange range;
27+
Multimap<LocalDate, Meeting> meetings;
28+
29+
public LocalDate getStart()
30+
{
31+
return this.range.getStart();
32+
}
33+
34+
public LocalDate getEnd()
35+
{
36+
return this.range.getEnd().minusDays(1);
37+
}
38+
39+
public int getNumberOfMeetings()
40+
{
41+
return this.meetings.size();
42+
}
43+
44+
protected String iterateMeetings()
45+
{
46+
StringBuilder builder = new StringBuilder();
47+
this.range.stream().forEach(date -> {
48+
builder.append("Date=" + date);
49+
builder.append(" {Meetings= ");
50+
builder.append(this.meetings.get(date));
51+
builder.append("} ");
52+
});
53+
return builder.toString();
54+
}
55+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2017 BNY Mellon.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bnymellon.codekatas.calendarkata;
18+
19+
import java.time.LocalDate;
20+
21+
import org.eclipse.collections.api.multimap.sortedset.SortedSetMultimap;
22+
import org.threeten.extra.LocalDateRange;
23+
24+
public class FullMonth extends CalendarWindow
25+
{
26+
/**
27+
* TODO Calculate the start, end and range of dates for the full month including the specified date.
28+
*
29+
* Hint: Look at {@link LocalDate#withDayOfMonth(int)}
30+
* Hint: Look at {@link LocalDate#lengthOfMonth()}
31+
* Hint: Look at {@link LocalDateRange#of(LocalDate, LocalDate)}
32+
* Hint: The end date is exclusive in LocalDateRange
33+
*/
34+
public FullMonth(LocalDate forDate, SortedSetMultimap<LocalDate, Meeting> calendarMeetings)
35+
{
36+
LocalDate start = null;
37+
LocalDate end = null;
38+
this.range = null;
39+
this.meetings = calendarMeetings.selectKeysValues(
40+
(date, meeting) ->
41+
date.getMonth().equals(start.getMonth()) &&
42+
date.getYear() == start.getYear());
43+
}
44+
45+
@Override
46+
public String toString()
47+
{
48+
return "FullMonth(" +
49+
"start=" + this.getStart() +
50+
", end=" + this.getEnd() +
51+
", meetings=" + this.iterateMeetings() +
52+
')';
53+
}
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2017 BNY Mellon.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bnymellon.codekatas.calendarkata;
18+
19+
import java.time.DayOfWeek;
20+
import java.time.LocalDate;
21+
import java.time.temporal.TemporalAdjuster;
22+
import java.time.temporal.TemporalAdjusters;
23+
24+
import org.eclipse.collections.api.multimap.sortedset.SortedSetMultimap;
25+
import org.threeten.extra.LocalDateRange;
26+
27+
public class FullWeek extends CalendarWindow
28+
{
29+
/**
30+
* TODO Calculate the start date and range of dates for the full seven day week from Sunday to Saturday.
31+
*
32+
* Hint: Look at {@link LocalDate#with(TemporalAdjuster)}
33+
* Hint: Look at {@link TemporalAdjusters#previousOrSame(DayOfWeek)}
34+
* Hint: Look at {@link LocalDate#plusDays(long)}
35+
* Hint: Look at {@link LocalDateRange#of(LocalDate, LocalDate)}
36+
* Hint: The end date is exclusive in LocalDateRange
37+
*/
38+
public FullWeek(LocalDate forDate, SortedSetMultimap<LocalDate, Meeting> calendarMeetings)
39+
{
40+
LocalDate start = null;
41+
this.range = null;
42+
this.meetings = calendarMeetings.selectKeysValues((date, meeting) -> this.range.contains(date));
43+
}
44+
45+
@Override
46+
public String toString()
47+
{
48+
return "FullWeek(" +
49+
"start=" + this.getStart() +
50+
", end=" + this.getEnd() +
51+
", meetings=" + this.iterateMeetings() +
52+
')';
53+
}
54+
}
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright 2017 BNY Mellon.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package bnymellon.codekatas.calendarkata;
18+
19+
import java.time.Duration;
20+
import java.time.LocalDate;
21+
import java.time.LocalDateTime;
22+
import java.time.LocalTime;
23+
import java.time.ZoneId;
24+
import java.util.Comparator;
25+
import java.util.Objects;
26+
27+
import org.threeten.extra.Interval;
28+
29+
public class Meeting implements Comparable<Meeting>
30+
{
31+
public static final Comparator<Meeting> COMPARATOR = Comparator.comparing(Meeting::getDate).thenComparing(Meeting::getStartTime);
32+
private String subject;
33+
private LocalDate date;
34+
private LocalTime startTime;
35+
private Duration duration;
36+
private ZoneId zoneId;
37+
38+
public Meeting(String subject, LocalDate date, LocalTime startTime, Duration duration, ZoneId zoneId)
39+
{
40+
this.subject = subject;
41+
this.date = date;
42+
this.startTime = startTime;
43+
this.duration = duration;
44+
this.zoneId = zoneId;
45+
}
46+
47+
public String getSubject()
48+
{
49+
return this.subject;
50+
}
51+
52+
public LocalDate getDate()
53+
{
54+
return this.date;
55+
}
56+
57+
public LocalTime getStartTime()
58+
{
59+
return this.startTime;
60+
}
61+
62+
public Duration getDuration()
63+
{
64+
return this.duration;
65+
}
66+
67+
public ZoneId getZoneId()
68+
{
69+
return this.zoneId;
70+
}
71+
72+
public LocalTime getEndTime()
73+
{
74+
return this.getStartTime().plus(this.getDuration());
75+
}
76+
77+
public Interval getInterval()
78+
{
79+
return Interval.of(
80+
LocalDateTime.of(this.date,this.startTime)
81+
.atZone(this.zoneId)
82+
.toInstant(),
83+
this.duration);
84+
}
85+
86+
@Override
87+
public boolean equals(Object o)
88+
{
89+
if (this == o)
90+
{
91+
return true;
92+
}
93+
if (o == null || this.getClass() != o.getClass())
94+
{
95+
return false;
96+
}
97+
Meeting meeting = (Meeting) o;
98+
return Objects.equals(this.getSubject(), meeting.getSubject()) &&
99+
Objects.equals(this.getDate(), meeting.getDate()) &&
100+
Objects.equals(this.getStartTime(), meeting.getStartTime()) &&
101+
Objects.equals(this.getDuration(), meeting.getDuration()) &&
102+
Objects.equals(this.getZoneId(), meeting.getZoneId());
103+
}
104+
105+
@Override
106+
public int hashCode()
107+
{
108+
int result = this.getSubject().hashCode();
109+
result = 31 * result + this.getDate().hashCode();
110+
result = 31 * result + this.getStartTime().hashCode();
111+
result = 31 * result + this.getDuration().hashCode();
112+
result = 31 * result + this.getZoneId().hashCode();
113+
return result;
114+
}
115+
116+
@Override
117+
public String toString()
118+
{
119+
return "Meeting(" +
120+
"subject='" + this.getSubject() + '\'' +
121+
", date=" + this.getDate() +
122+
", startTime=" + this.getStartTime() +
123+
", duration=" + this.getDuration() +
124+
", endTime=" + this.getEndTime() +
125+
')';
126+
}
127+
128+
@Override
129+
public int compareTo(Meeting that)
130+
{
131+
return COMPARATOR.compare(this, that);
132+
}
133+
}

0 commit comments

Comments
 (0)