package core;

import com.google.common.base.MoreObjects;
import core.account.Account;
import core.account.AccountDetails;
import lombok.Getter;

import java.math.BigDecimal;
import java.time.Instant;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;

/**
 * Describes a ledger's accounts with their corresponding balances at a specific moment in time.
 */
public class TrialBalanceResult {
    final private Map<AccountDetails, BigDecimal> accountDetailsToBalance =
            new TreeMap<>((o1, o2) -> o1.getAccountNumber().compareTo(o2.getAccountNumber()));
    final private long creationTimestamp;
    @Getter
    final private boolean isBalanced;

    public TrialBalanceResult(Set<Account> accounts) {
        checkNotNull(accounts);
        checkArgument(!accounts.isEmpty());
        accounts.forEach(
                a -> accountDetailsToBalance.put(a.getAccountDetails(), a.getBalance())
        );
        creationTimestamp = Instant.now().toEpochMilli();
        BigDecimal balance = BigDecimal.ZERO;
        accounts.forEach(a -> balance.add(a.getBalance()));
        isBalanced = balance.equals(BigDecimal.ZERO);
    }

    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this)
                .add("isBalanced", isBalanced)
                .add("accountDetailsToBalance", accountDetailsToBalance)
                .add("creationTimestamp", Instant.ofEpochMilli(creationTimestamp).toString())
                .toString();
    }
}

@@ -190,24 +190,53 @@
 me.Instant;%0A
+import java.util.Comparator;%0A
 import java.
@@ -245,16 +245,16 @@
 il.Map;%0A
-
 import j
@@ -671,55 +671,45 @@
 p%3C%3E(
-(o1, o2) -%3E o1.getAccountNumber().compareTo(o2.
+Comparator.comparing(AccountDetails::
 getA
@@ -720,18 +720,16 @@
 ntNumber
-()
 ));%0A    
@@ -1159,16 +1159,83 @@
 alance =
+ accounts.stream()%0A                .reduce(%0A                       
  BigDeci
@@ -1242,17 +1242,17 @@
 mal.ZERO
-;
+,
 %0A       
@@ -1256,43 +1256,51 @@
     
-accounts.forEach(a -%3E balance
+                (acc, next) -%3E acc
 .add(
-a
+next
 .get
@@ -1309,16 +1309,74 @@
 lance())
+,%0A                        BigDecimal::add%0A                
 );%0A     

Fix trial balance check