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);
}
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());
}
}
}
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);
}
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;
}
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);
}
Aggregations