moveTo(-1, target);
}
private void moveTo(int index, TaxonomyNode target)
{
Classification classification = target.getClassification();
if (classification == null)
throw new UnsupportedOperationException();
// if node is assignment *and* target contains assignment for same
// investment vehicle *then* merge nodes
if (isAssignment())
{
InvestmentVehicle investmentVehicle = getAssignment().getInvestmentVehicle();
TaxonomyNode sibling = target.getChildByInvestmentVehicle(investmentVehicle);
if (sibling != null)
{
sibling.absorb(this);
return;
}
}
// change parent, update children collections and rank
this.getParent().removeChild(this);
this.parent = target;
if (isClassification())
{
getClassification().setParent(classification);
classification.getChildren().add(getClassification());
}
else
{
classification.getAssignments().add(getAssignment());
}
List<TaxonomyNode> siblings = target.getChildren();
if (index == -1)
index = siblings.size();