-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9202b4b
commit fb3d780
Showing
2 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.example.banking.domain; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import com.example.banking.domain.exception.CustomerNotFoundException; | ||
|
||
public final class Bank { | ||
private final Long id; | ||
private String name; | ||
private final Map<String, Customer> customers = new HashMap<>(); | ||
|
||
// Constructor(id,name) | ||
public Bank(Long id, String name) { | ||
this.id = id; | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public Collection<Customer> getCustomers() { | ||
return customers.values(); | ||
} | ||
|
||
public Customer createCustomer(String identity, String fullname) { | ||
var customer = new Customer(identity, fullname); | ||
customers.put(identity,customer); | ||
return customer; | ||
} | ||
|
||
public Optional<Customer> getCustomer(String identity) { | ||
return Optional.ofNullable(customers.get(identity)); | ||
} | ||
|
||
public Customer findCustomer(String identity) { | ||
return getCustomer(identity).orElseThrow(() -> new CustomerNotFoundException(identity)); | ||
} | ||
|
||
public Optional<Customer> deleteCustomer(String identity) { | ||
return Optional.ofNullable(customers.remove(identity)); | ||
} | ||
|
||
public double getTotalBalance() { | ||
return customers.values() | ||
.stream() | ||
.parallel() | ||
.mapToDouble(Customer::getTotalBalance) | ||
.sum(); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
core-banking/src/com/example/banking/domain/exception/CustomerNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.example.banking.domain.exception; | ||
|
||
@SuppressWarnings("serial") | ||
public class CustomerNotFoundException extends RuntimeException { | ||
|
||
private final String identity; | ||
|
||
public CustomerNotFoundException(String identity) { | ||
this.identity = identity; | ||
} | ||
|
||
public String getIdentity() { | ||
return identity; | ||
} | ||
|
||
} |