001    /* This file was generated by SableCC (http://www.sablecc.org/). */
002    
003    package org.jdmp.core.script.jdmp.node;
004    
005    import java.util.*;
006    
007    @SuppressWarnings("nls")
008    public abstract class Node implements Switchable, Cloneable
009    {
010        private Node parent;
011    
012        @Override
013        public abstract Object clone();
014    
015        public Node parent()
016        {
017            return this.parent;
018        }
019    
020        void parent(@SuppressWarnings("hiding") Node parent)
021        {
022            this.parent = parent;
023        }
024    
025        abstract void removeChild(Node child);
026        abstract void replaceChild(Node oldChild, Node newChild);
027    
028        public void replaceBy(Node node)
029        {
030            this.parent.replaceChild(this, node);
031        }
032    
033        protected String toString(Node node)
034        {
035            if(node != null)
036            {
037                return node.toString();
038            }
039    
040            return "";
041        }
042    
043        protected String toString(List list)
044        {
045            StringBuffer s = new StringBuffer();
046    
047            for(Iterator i = list.iterator(); i.hasNext();)
048            {
049                s.append(i.next());
050            }
051    
052            return s.toString();
053        }
054    
055        @SuppressWarnings("unchecked")
056        protected <T extends Node> T cloneNode(T node)
057        {
058            if(node != null)
059            {
060                return (T) node.clone();
061            }
062    
063            return null;
064        }
065    
066        protected <T> List<T> cloneList(List<T> list)
067        {
068            List<T> clone = new LinkedList<T>();
069    
070            for(T n : list)
071            {
072                clone.add(n);
073            }
074    
075            return clone;
076        }
077    }