Search in sources :

Example 31 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class AbstractNodeTreeViewer method doAddClassification.

private void doAddClassification(TaxonomyNode parent) {
    Classification newClassification = new Classification(null, UUID.randomUUID().toString(), Messages.LabelNewClassification);
    TaxonomyNode newNode = parent.addChild(newClassification);
    nodeViewer.setExpandedState(parent, true);
    onTaxnomyNodeEdited(parent);
    nodeViewer.editElement(newNode, 0);
}
Also used : Classification(name.abuchen.portfolio.model.Classification)

Example 32 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class GroupByTaxonomy method createCategoriesAndAllocate.

private void createCategoriesAndAllocate(final Map<InvestmentVehicle, Item> vehicle2position) {
    for (Classification classification : taxonomy.getRoot().getChildren()) {
        final Map<InvestmentVehicle, Item> vehicle2item = new HashMap<>();
        // first: assign items to categories
        // item.weight records both the weight
        // (a) already assigned to any category
        // (b) assigned to this category
        classification.accept(new Taxonomy.Visitor() {

            @Override
            public void visit(Classification classification, Assignment assignment) {
                Item item = vehicle2position.get(assignment.getInvestmentVehicle());
                if (item != null) {
                    // record (a)
                    item.weight += assignment.getWeight();
                    SecurityPosition position = item.position;
                    if (assignment.getWeight() == Classification.ONE_HUNDRED_PERCENT) {
                        vehicle2item.put(assignment.getInvestmentVehicle(), item);
                    } else {
                        Item other = vehicle2item.get(assignment.getInvestmentVehicle());
                        if (other == null) {
                            other = new Item(position);
                            vehicle2item.put(assignment.getInvestmentVehicle(), other);
                        }
                        // record (b) into the copy
                        other.weight += assignment.getWeight();
                    }
                }
            }
        });
        if (!vehicle2item.isEmpty()) {
            AssetCategory category = new AssetCategory(classification, converter, date, valuation);
            categories.add(category);
            for (Entry<InvestmentVehicle, Item> entry : vehicle2item.entrySet()) {
                Item item = entry.getValue();
                SecurityPosition position = item.position;
                if (item.weight != Classification.ONE_HUNDRED_PERCENT)
                    position = SecurityPosition.split(position, item.weight);
                category.addPosition(new AssetPosition(position, converter, date, getValuation()));
            }
            // sort positions by name
            Collections.sort(category.getPositions(), new AssetPosition.ByDescription());
        }
    }
}
Also used : HashMap(java.util.HashMap) Taxonomy(name.abuchen.portfolio.model.Taxonomy) Assignment(name.abuchen.portfolio.model.Classification.Assignment) Classification(name.abuchen.portfolio.model.Classification) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 33 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class GroupByTaxonomy method allocateLeftOvers.

private void allocateLeftOvers(final Map<InvestmentVehicle, Item> vehicle2position) {
    Classification classification = new Classification(null, Classification.UNASSIGNED_ID, Messages.LabelWithoutClassification);
    AssetCategory unassigned = new AssetCategory(classification, converter, date, getValuation());
    for (Entry<InvestmentVehicle, Item> entry : vehicle2position.entrySet()) {
        Item item = entry.getValue();
        if (item.weight < Classification.ONE_HUNDRED_PERCENT) {
            SecurityPosition position = item.position;
            if (item.weight != 0)
                position = SecurityPosition.split(position, Classification.ONE_HUNDRED_PERCENT - item.weight);
            unassigned.addPosition(new AssetPosition(position, converter, date, getValuation()));
        }
    }
    if (!unassigned.getPositions().isEmpty())
        categories.add(unassigned);
}
Also used : Classification(name.abuchen.portfolio.model.Classification) InvestmentVehicle(name.abuchen.portfolio.model.InvestmentVehicle)

Example 34 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class TaxonomyNode method addChild.

/* package */
TaxonomyNode addChild(Assignment newAssignment) {
    Classification classification = getClassification();
    if (classification == null)
        return null;
    classification.addAssignment(newAssignment);
    TaxonomyNode newChild = new AssignmentNode(this, newAssignment);
    newChild.setRank(getTopRank() + 1);
    children.add(newChild);
    return newChild;
}
Also used : Classification(name.abuchen.portfolio.model.Classification)

Example 35 with Classification

use of name.abuchen.portfolio.model.Classification in project portfolio by buchen.

the class TaxonomyNode method removeChild.

/* package */
void removeChild(TaxonomyNode node) {
    Classification classification = getClassification();
    if (classification == null)
        throw new UnsupportedOperationException();
    if (node.isClassification())
        classification.getChildren().remove(node.getClassification());
    else
        classification.getAssignments().remove(node.getAssignment());
    children.remove(node);
}
Also used : Classification(name.abuchen.portfolio.model.Classification)

Aggregations

Classification (name.abuchen.portfolio.model.Classification)36 ArrayList (java.util.ArrayList)21 TestCurrencyConverter (name.abuchen.portfolio.TestCurrencyConverter)20 Client (name.abuchen.portfolio.model.Client)20 Taxonomy (name.abuchen.portfolio.model.Taxonomy)20 Test (org.junit.Test)20 IOException (java.io.IOException)18 Security (name.abuchen.portfolio.model.Security)17 PerformanceIndex (name.abuchen.portfolio.snapshot.PerformanceIndex)17 Collectors (java.util.stream.Collectors)16 AccountTransaction (name.abuchen.portfolio.model.AccountTransaction)16 ClientFactory (name.abuchen.portfolio.model.ClientFactory)16 CurrencyUnit (name.abuchen.portfolio.money.CurrencyUnit)16 LocalDate (java.time.LocalDate)15 LocalDateTime (java.time.LocalDateTime)15 List (java.util.List)15 Money (name.abuchen.portfolio.money.Money)15 Values (name.abuchen.portfolio.money.Values)15 ReportingPeriod (name.abuchen.portfolio.snapshot.ReportingPeriod)15 ClientClassificationFilter (name.abuchen.portfolio.snapshot.filter.ClientClassificationFilter)15