groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul King (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (GROOVY-8206) Groovy clone node with parent
Date Fri, 26 May 2017 03:25:04 GMT

     [ https://issues.apache.org/jira/browse/GROOVY-8206?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

Paul King updated GROOVY-8206:
------------------------------
    Description: 
As of now groovy supports clone node feature without cloning parents.
We can add following custom methods in some util class to make cloning more advanced :
1:
{code}
private Node cloneNode(Node node, Node parentNode) {
    Object newValue = node.value()
    Node clonedNode = new Node(null, node.name(), new HashMap(node.attributes()), newValue)
    if (newValue instanceof NodeList) {
        NodeList nodes = (NodeList) newValue
        newValue = cloneNodeList(nodes, clonedNode)
    }
    clonedNode.setValue(newValue)
    clonedNode.setParent(parentNode)
    return clonedNode
}
{code}

2:
{code}
private NodeList cloneNodeList(NodeList nodeList, Node parentNode) {
    NodeList result = new NodeList(nodeList.size())
    for (int i = 0; i < nodeList.size(); i++) {
        Object next = nodeList.get(i)
        if (next instanceof Node) {
            result.add(cloneNode((Node) next, parentNode))
        } else {
            result.add(next)
        }
    }
    return result
}
{code}


  was:
As of now groovy supports clone node feature without cloning parents.
We can add following custom methods in some util class to make cloning more advanced :
1:
private Node cloneNode(Node node, Node parentNode){
		Object newValue = node.value()
		Node clonedNode = new Node(null, node.name(), new HashMap(node.attributes()), newValue)
		if (newValue instanceof NodeList) {
			NodeList nodes = (NodeList) newValue
			newValue = cloneNodeList(nodes, clonedNode)
		}
		clonedNode.setValue(newValue)
		clonedNode.setParent(parentNode)
		return clonedNode
	}


2:
private NodeList cloneNodeList(NodeList nodeList, Node parentNode) {
        NodeList result = new NodeList(nodeList.size())
        for (int i = 0; i < nodeList.size(); i++) {
            Object next = nodeList.get(i)
            if (next instanceof Node) {
				result.add(cloneNode((Node) next, parentNode))
            } else {
                result.add(next)
            }
        }
        return result
    }




> Groovy clone node with parent
> -----------------------------
>
>                 Key: GROOVY-8206
>                 URL: https://issues.apache.org/jira/browse/GROOVY-8206
>             Project: Groovy
>          Issue Type: Improvement
>          Components: groovy-jdk
>            Reporter: Manish Yadav
>
> As of now groovy supports clone node feature without cloning parents.
> We can add following custom methods in some util class to make cloning more advanced
:
> 1:
> {code}
> private Node cloneNode(Node node, Node parentNode) {
>     Object newValue = node.value()
>     Node clonedNode = new Node(null, node.name(), new HashMap(node.attributes()), newValue)
>     if (newValue instanceof NodeList) {
>         NodeList nodes = (NodeList) newValue
>         newValue = cloneNodeList(nodes, clonedNode)
>     }
>     clonedNode.setValue(newValue)
>     clonedNode.setParent(parentNode)
>     return clonedNode
> }
> {code}
> 2:
> {code}
> private NodeList cloneNodeList(NodeList nodeList, Node parentNode) {
>     NodeList result = new NodeList(nodeList.size())
>     for (int i = 0; i < nodeList.size(); i++) {
>         Object next = nodeList.get(i)
>         if (next instanceof Node) {
>             result.add(cloneNode((Node) next, parentNode))
>         } else {
>             result.add(next)
>         }
>     }
>     return result
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)

Mime
View raw message