jInfer

cz.cuni.mff.ksi.jinfer.base.utils
Class CloneHelper

java.lang.Object
  extended by cz.cuni.mff.ksi.jinfer.base.utils.CloneHelper

public class CloneHelper
extends Object

Utilities for cloning. Note that this class uses an inner cache of already cloned elements to deal with cyclic dependencies, and should be used to clone at most one full grammar. If not sure, create a new instance of this class to clone something.


Constructor Summary
CloneHelper()
           
 
Method Summary
 Element cloneElement(Element e)
          Clones a single element.
 Element cloneElement(Element e, List<String> contextPrefix)
          Clones a single element.
 List<Element> cloneGrammar(List<Element> grammar)
          Clones the whole grammar at once.
 Regexp<AbstractStructuralNode> cloneRegexp(Regexp<AbstractStructuralNode> r, List<String> contextPrefix)
          Clones a regular expression.
static List<String> getPrefixedContext(NamedNode node, List<String> contextPrefix)
          Concatenate context from contextPrefix and the context of node When contextPrefix is {"X","Y"} and the context of node is {"A", "B"}, method returns {"X","Y","A","B"}.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CloneHelper

public CloneHelper()
Method Detail

cloneGrammar

public List<Element> cloneGrammar(List<Element> grammar)
Clones the whole grammar at once.

Parameters:
grammar - Grammar to be cloned.
Returns:
Cloned grammar: contains the same elements, but in different object instances.

cloneElement

public Element cloneElement(Element e)
Clones a single element. This is done for all its children recursively.

Parameters:
e - Element to be cloned.
Returns:
Cloned element that is equal to the original, but different instance.
See Also:
cloneElement(cz.cuni.mff.ksi.jinfer.base.objects.nodes.Element, java.util.List)

cloneElement

public Element cloneElement(Element e,
                            List<String> contextPrefix)
Clones a single element. Context of every element is prefixed with the contextPrefix. For example: if element A has children B,C and contextPrefix is null or empty, the contexts are When the contentPrefix contains strings "X","Y","Z", the final contexts of the elements are respectively. This is done for all children recursively.

Parameters:
e - Element to be cloned.
contextPrefix - Context to be used as prefix.
Returns:
Cloned element that is equal to the original in everything except the new context, but different instance.

cloneRegexp

public Regexp<AbstractStructuralNode> cloneRegexp(Regexp<AbstractStructuralNode> r,
                                                  List<String> contextPrefix)
Clones a regular expression. Elements are prefixed with the contextPrefix as in cloneElement(cz.cuni.mff.ksi.jinfer.base.objects.nodes.Element, java.util.List).

Parameters:
r - Regexp to be cloned.
contextPrefix - Context to be used as prefix.
Returns:
Cloned regexp: equal, but different instance.

getPrefixedContext

public static List<String> getPrefixedContext(NamedNode node,
                                              List<String> contextPrefix)
Concatenate context from contextPrefix and the context of node When contextPrefix is {"X","Y"} and the context of node is {"A", "B"}, method returns {"X","Y","A","B"}.

Parameters:
node - Node from which the context is retrieved.
contextPrefix - Context that should be appended before the node context.
Returns:
New concatenated list. Otherwise, the result will be equal to the context of node when contextPrefix is empty or null. Result will be equal to contextPrefix if the context of node is empty or null. Result will be null if both arguments are null.

jInfer

Generated on Fri Dec 9 00:01:25 CET 2011