Search in sources :

Example 1 with AssignmentNode

use of name.abuchen.portfolio.ui.views.taxonomy.TaxonomyNode.AssignmentNode in project portfolio by buchen.

the class TaxonomyModel method addUnassigned.

private void addUnassigned(Client client) {
    for (Security security : client.getSecurities()) {
        Assignment assignment = new Assignment(security);
        assignment.setWeight(0);
        investmentVehicle2weight.put(security, assignment);
    }
    for (Account account : client.getAccounts()) {
        Assignment assignment = new Assignment(account);
        assignment.setWeight(0);
        investmentVehicle2weight.put(account, assignment);
    }
    visitAll(node -> {
        if (!(node instanceof AssignmentNode))
            return;
        Assignment assignment = node.getAssignment();
        Assignment count = investmentVehicle2weight.get(assignment.getInvestmentVehicle());
        count.setWeight(count.getWeight() + assignment.getWeight());
    });
    List<Assignment> unassigned = new ArrayList<>();
    for (Assignment assignment : investmentVehicle2weight.values()) {
        if (assignment.getWeight() >= Classification.ONE_HUNDRED_PERCENT)
            continue;
        Assignment a = new Assignment(assignment.getInvestmentVehicle());
        a.setWeight(Classification.ONE_HUNDRED_PERCENT - assignment.getWeight());
        unassigned.add(a);
        assignment.setWeight(Classification.ONE_HUNDRED_PERCENT);
    }
    Collections.sort(unassigned, (o1, o2) -> o1.getInvestmentVehicle().toString().compareToIgnoreCase(o2.getInvestmentVehicle().toString()));
    for (Assignment assignment : unassigned) unassignedNode.addChild(assignment);
}
Also used : Assignment(name.abuchen.portfolio.model.Classification.Assignment) Account(name.abuchen.portfolio.model.Account) AssignmentNode(name.abuchen.portfolio.ui.views.taxonomy.TaxonomyNode.AssignmentNode) ArrayList(java.util.ArrayList) Security(name.abuchen.portfolio.model.Security)

Aggregations

ArrayList (java.util.ArrayList)1 Account (name.abuchen.portfolio.model.Account)1 Assignment (name.abuchen.portfolio.model.Classification.Assignment)1 Security (name.abuchen.portfolio.model.Security)1 AssignmentNode (name.abuchen.portfolio.ui.views.taxonomy.TaxonomyNode.AssignmentNode)1