2020-10-17 11:39:01 +00:00
|
|
|
package treeops
|
|
|
|
|
|
|
|
import "github.com/elliotchance/orderedmap"
|
|
|
|
|
|
|
|
func AssignOperator(d *dataTreeNavigator, matchingNodes *orderedmap.OrderedMap, pathNode *PathTreeNode) (*orderedmap.OrderedMap, error) {
|
|
|
|
lhs, err := d.getMatchingNodes(matchingNodes, pathNode.Lhs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for el := lhs.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
|
|
|
|
rhs, err := d.getMatchingNodes(nodeToMap(candidate), pathNode.Rhs)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// grab the first value
|
|
|
|
first := rhs.Front()
|
|
|
|
|
|
|
|
if first != nil {
|
|
|
|
candidate.UpdateFrom(first.Value.(*CandidateNode))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matchingNodes, nil
|
|
|
|
}
|
2020-10-19 05:14:29 +00:00
|
|
|
|
|
|
|
// does not update content or values
|
|
|
|
func AssignAttributesOperator(d *dataTreeNavigator, matchingNodes *orderedmap.OrderedMap, pathNode *PathTreeNode) (*orderedmap.OrderedMap, error) {
|
|
|
|
lhs, err := d.getMatchingNodes(matchingNodes, pathNode.Lhs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for el := lhs.Front(); el != nil; el = el.Next() {
|
|
|
|
candidate := el.Value.(*CandidateNode)
|
|
|
|
|
|
|
|
rhs, err := d.getMatchingNodes(nodeToMap(candidate), pathNode.Rhs)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// grab the first value
|
|
|
|
first := rhs.Front()
|
|
|
|
|
|
|
|
if first != nil {
|
|
|
|
candidate.UpdateAttributesFrom(first.Value.(*CandidateNode))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return matchingNodes, nil
|
|
|
|
}
|