// calculating source and destination position
int srcInd = -1, destInd = -1;
for (int i = 0; i < siblings.size(); i++)
{
NodeData nodeData = siblings.get(i);
if (srcInd == -1)
{
if (nodeData.getQPath().getName().equals(srcPath.getName()))
{
srcInd = i;
}
}
if (destPath != null && destInd == -1)
{
if (nodeData.getQPath().getName().equals(destPath.getName()))
{
destInd = i;
if (srcInd != -1)
{
break;
}
}
}
else
{
if (srcInd != -1)
{
break;
}
}
}
// check if resulting order would be different to current order
if (destInd == -1)
{
if (srcInd == siblings.size() - 1)
{
// no change, we're done
return;
}
}
else
{
if ((destInd - srcInd) == 1)
{
// no change, we're done
return;
}
}
// reorder list
if (destInd == -1)
{
siblings.add(siblings.remove(srcInd));
}
else
{
if (srcInd < destInd)
{
siblings.add(destInd, siblings.get(srcInd));
siblings.remove(srcInd);
}
else
{
siblings.add(destInd, siblings.remove(srcInd));
}
}
int sameNameIndex = 0;
List<ItemState> changes = new ArrayList<ItemState>();
ItemState deleteState = null;
for (int j = 0; j < siblings.size(); j++)
{
NodeData sdata = siblings.get(j);
// calculating same name index
if (sdata.getQPath().getName().getAsString().equals(srcPath.getName().getAsString()))
++sameNameIndex;
// skeep unchanged
if (sdata.getOrderNumber() == j)
continue;
NodeData newData = sdata;
// change same name index
if (sdata.getQPath().getName().getAsString().equals(srcPath.getName().getAsString())
&& sdata.getQPath().getIndex() != sameNameIndex)
{
// update with new index
QPath siblingPath =
QPath.makeChildPath(newData.getQPath().makeParentPath(), newData.getQPath().getName(), sameNameIndex);
newData =
new TransientNodeData(siblingPath, newData.getIdentifier(), newData.getPersistedVersion(),
newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(),
newData.getACL());
}
else
{
newData =
new TransientNodeData(newData.getQPath(), newData.getIdentifier(), newData.getPersistedVersion(),
newData.getPrimaryTypeName(), newData.getMixinTypeNames(), j, newData.getParentIdentifier(),
newData.getACL());
}
/*
* 8.3.7.8 Re-ordering a set of Child Nodes. When an orderBefore(A, B) is
* performed, an implementation must generate a NODE_REMOVED for node A