Skip to content
This repository was archived by the owner on Feb 10, 2021. It is now read-only.

Commit 17f910c

Browse files
committed
Add new exercise task
1 parent 1be80e1 commit 17f910c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

account-analytics/src/main/java/com.bobocode/AccountAnalytics.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
import java.time.Month;
88
import java.util.*;
99

10+
import static java.util.stream.Collectors.mapping;
11+
import static java.util.stream.Collectors.toMap;
12+
1013
/**
1114
* Implement methods using Stream API
1215
*/
@@ -117,6 +120,17 @@ public Map<Long, Account> collectAccountsById() {
117120
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
118121
}
119122

123+
/**
124+
* Filters accounts by the year when an account was created. Collects account balances by its emails into a {@link Map}.
125+
* The key is {@link Account#email} and the value is {@link Account#balance}
126+
*
127+
* @param year the year of account creation
128+
* @return map of account by its ids the were created in a particular year
129+
*/
130+
public Map<String, BigDecimal> collectBalancesByIdForAccountsCreatedOn(int year) {
131+
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
132+
}
133+
120134
/**
121135
* Returns a {@link Map} where key is {@link Account#lastName} and values is a {@link Set} that contains first names
122136
* of all accounts with a specific last name.

account-analytics/src/test/java/com/bobocode/AccountAnalyticsTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,15 @@ public void testCollectAccountsById() {
155155
assertEquals(accounts.get(3), idToAccountMap.get(4L));
156156
}
157157

158+
@Test
159+
public void testCollectBalancesByIdForAccountsCreatedOn() {
160+
Account account = accounts.get(3);
161+
162+
Map<String, BigDecimal> emailToBalanceMap = analytics.collectBalancesByIdForAccountsCreatedOn(account.getCreationDate().getYear());
163+
164+
assertEquals(Map.of(account.getEmail(), account.getBalance()), emailToBalanceMap);
165+
}
166+
158167
@Test
159168
public void testGroupFirstNamesByLastNames() {
160169
Map<String, Set<String>> lastToFirstNamesMap = analytics.groupFirstNamesByLastNames();

0 commit comments

Comments
 (0)