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

Commit 9e8112f

Browse files
committed
Implement new methods in AccountAnalytics.java
1 parent 1598f60 commit 9e8112f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.stream.Stream;
1212

1313
import static java.util.Comparator.comparing;
14+
import static java.util.function.Function.identity;
1415
import static java.util.stream.Collectors.*;
1516

1617
/**
@@ -125,7 +126,11 @@ public boolean containsAccountWithEmailDomain(String emailDomain) {
125126
* @return account balance
126127
*/
127128
public BigDecimal getBalanceByEmail(String email) {
128-
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
129+
return accounts.stream()
130+
.filter(account -> account.getEmail().equals(email))
131+
.findFirst()
132+
.map(Account::getBalance)
133+
.orElseThrow(() -> new EntityNotFoundException(String.format("Cannot find Account by email=%s", email)));
129134
}
130135

131136
/**
@@ -134,7 +139,8 @@ public BigDecimal getBalanceByEmail(String email) {
134139
* @return map of accounts by its ids
135140
*/
136141
public Map<Long, Account> collectAccountsById() {
137-
throw new UnsupportedOperationException("It's your job to implement this method"); // todo
142+
return accounts.stream()
143+
.collect(toMap(Account::getId, identity()));
138144
}
139145

140146
/**
@@ -184,7 +190,7 @@ public Map<Character, Long> getCharacterFrequencyInFirstNames() {
184190
.map(Account::getFirstName)
185191
.flatMapToInt(String::chars)
186192
.mapToObj(c -> (char) c)
187-
.collect(groupingBy(Function.identity(), counting()));
193+
.collect(groupingBy(identity(), counting()));
188194
}
189195

190196
/**
@@ -199,7 +205,7 @@ public Map<Character, Long> getCharacterFrequencyIgnoreCaseInFirstAndLastNames()
199205
.map(String::toLowerCase)
200206
.flatMapToInt(String::chars)
201207
.mapToObj(c -> (char) c)
202-
.collect(groupingBy(Function.identity(), counting()));
208+
.collect(groupingBy(identity(), counting()));
203209
}
204210

205211
}

0 commit comments

Comments
 (0)