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

Commit 6df6c7c

Browse files
author
Taras
committed
- added one case to AccountAnalytics.java
- extended Account.java with Sex
1 parent 36506ff commit 6df6c7c

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

account-analytics/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

12-
<artifactId>account-statistics</artifactId>
12+
<artifactId>account-analytics</artifactId>
1313

1414
<dependencies>
1515
<dependency>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,17 @@
77
import java.util.List;
88
import java.util.Map;
99

10+
/**
11+
* Implement methods using Stream API
12+
*/
1013
public class AccountAnalytics {
1114
private Collection<Account> accounts;
1215

1316
public static AccountAnalytics of(Collection<Account> accounts) {
1417
return new AccountAnalytics(accounts);
1518
}
1619

17-
public AccountAnalytics(Collection<Account> accounts) {
20+
private AccountAnalytics(Collection<Account> accounts) {
1821
this.accounts = accounts;
1922
}
2023

@@ -26,8 +29,13 @@ public List<Account> findAccountsByBirthdayMonth(Month birthdayMonth) {
2629
throw new UnsupportedOperationException("It's your job to make it work!"); // todo
2730
}
2831

32+
public Map<Boolean, List<Account>> partitionMaleAccounts() {
33+
throw new UnsupportedOperationException("It's your job to make it work!"); // todo
34+
}
35+
2936
public Map<String, List<Account>> groupAccountsByEmailDomain() {
3037
throw new UnsupportedOperationException("It's your job to make it work!"); // todo
3138
}
3239

40+
3341
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.bobocode.data.Accounts;
44
import com.bobocode.model.Account;
5+
import com.bobocode.model.Sex;
56
import org.junit.Before;
67
import org.junit.Test;
78
import org.junit.runner.RunWith;
@@ -45,6 +46,34 @@ private Account getRichestPerson() {
4546
return richestPerson;
4647
}
4748

49+
@Test
50+
public void testSeparateMaleAccounts() {
51+
Map<Boolean, List<Account>> maleToAccountsMap = analytics.partitionMaleAccounts();
52+
53+
assertEquals(partitionMaleAccounts(), maleToAccountsMap);
54+
}
55+
56+
private Map<Boolean, List<Account>> partitionMaleAccounts() {
57+
Map<Boolean, List<Account>> maleToAccountsMap = initializePartitionMap();
58+
59+
for (Account account : accounts) {
60+
if (account.getSex().equals(Sex.MALE)) {
61+
maleToAccountsMap.get(true).add(account);
62+
} else {
63+
maleToAccountsMap.get(false).add(account);
64+
}
65+
}
66+
67+
return maleToAccountsMap;
68+
}
69+
70+
private Map<Boolean, List<Account>> initializePartitionMap() {
71+
Map<Boolean, List<Account>> partitionMap = new HashMap<>();
72+
partitionMap.put(true, new ArrayList<>());
73+
partitionMap.put(false, new ArrayList<>());
74+
return partitionMap;
75+
}
76+
4877
@Test
4978
public void testFindAccountsByBirthdayMonth() {
5079
List<Account> aprilAccounts = analytics.findAccountsByBirthdayMonth(Month.APRIL);

account-data/src/main/java/com/bobocode/data/Accounts.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.bobocode.data;
22

33
import com.bobocode.model.Account;
4+
import com.bobocode.model.Sex;
45
import io.codearte.jfairy.Fairy;
56
import io.codearte.jfairy.producer.person.Person;
67

@@ -29,6 +30,7 @@ static Account getAccount(){
2930
person.getDateOfBirth().getYear(),
3031
person.getDateOfBirth().getMonthOfYear(),
3132
person.getDateOfBirth().getDayOfMonth()));
33+
fakeAccount.setSex(Sex.valueOf(person.getSex().name()));
3234
fakeAccount.setBalance(BigDecimal.valueOf(random.nextInt(200_000)));
3335
fakeAccount.setCreationDate(LocalDateTime.now());
3436

account-data/src/main/java/com/bobocode/model/Account.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class Account {
1818
private String lastName;
1919
private String email;
2020
private LocalDate birthday;
21+
private Sex sex;
2122
private LocalDateTime creationDate;
2223
private BigDecimal balance = BigDecimal.ZERO;
2324
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.bobocode.model;
2+
3+
public enum Sex {
4+
MALE,
5+
FEMALE
6+
}

0 commit comments

Comments
 (0)