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

Commit b9baf56

Browse files
committed
Merge branch 'master' into exercise/completed
2 parents 9e8112f + 17f910c commit b9baf56

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
@@ -14,6 +14,9 @@
1414
import static java.util.function.Function.identity;
1515
import static java.util.stream.Collectors.*;
1616

17+
import static java.util.stream.Collectors.mapping;
18+
import static java.util.stream.Collectors.toMap;
19+
1720
/**
1821
* Implement methods using Stream API
1922
*/
@@ -143,6 +146,17 @@ public Map<Long, Account> collectAccountsById() {
143146
.collect(toMap(Account::getId, identity()));
144147
}
145148

149+
/**
150+
* Filters accounts by the year when an account was created. Collects account balances by its emails into a {@link Map}.
151+
* The key is {@link Account#email} and the value is {@link Account#balance}
152+
*
153+
* @param year the year of account creation
154+
* @return map of account by its ids the were created in a particular year
155+
*/
156+
public Map<String, BigDecimal> collectBalancesByIdForAccountsCreatedOn(int year) {
157+
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
158+
}
159+
146160
/**
147161
* Returns a {@link Map} where key is {@link Account#lastName} and values is a {@link Set} that contains first names
148162
* 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)