Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
deepcloudlabs committed Jul 21, 2022
1 parent 9202b4b commit fb3d780
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 0 deletions.
62 changes: 62 additions & 0 deletions core-banking/src/com/example/banking/domain/Bank.java
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();
}
}
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;
}

}

0 comments on commit fb3d780

Please sign in to comment.