/* This file was generated by SableCC (http://www.sablecc.org/). */

package MONAViewer.monalanguage.node;

import java.util.*;
import MONAViewer.monalanguage.analysis.*;

public final class AVar1Declaration extends PDeclaration
{
    private final LinkedList _univ_ = new TypedLinkedList(new Univ_Cast());
    private final LinkedList _name_where_ = new TypedLinkedList(new NameWhere_Cast());

    public AVar1Declaration ()
    {
    }

    public AVar1Declaration (
            List _univ_,
            List _name_where_
    )
    {
        this._univ_.clear();
        this._univ_.addAll(_univ_);
        this._name_where_.clear();
        this._name_where_.addAll(_name_where_);
    }

    public Object clone()
    {
        return new AVar1Declaration (
            cloneList (_univ_),
            cloneList (_name_where_)
        );
    }

    public void apply(Switch sw)
    {
        ((Analysis) sw).caseAVar1Declaration(this);
    }

    public LinkedList getUniv ()
    {
        return _univ_;
    }

    public void setUniv (List list)
    {
        _univ_.clear();
        _univ_.addAll(list);
    }
    public LinkedList getNameWhere ()
    {
        return _name_where_;
    }

    public void setNameWhere (List list)
    {
        _name_where_.clear();
        _name_where_.addAll(list);
    }

    public String toString()
    {
        return ""
            + toString (_univ_)
            + toString (_name_where_)
        ;
    }

    void removeChild(Node child)
    {
        if ( _univ_.remove(child))
        {
            return;
        }
        if ( _name_where_.remove(child))
        {
            return;
        }
    }

    void replaceChild(Node oldChild, Node newChild)
    {
        for(ListIterator i = _univ_.listIterator(); i.hasNext();)
        {
            if(i.next() == oldChild)
            {
                if(newChild != null)
                {
                    i.set(newChild);
                    oldChild.parent(null);
                    return;
                }

                i.remove();
                oldChild.parent(null);
                return;
            }
        }
        for(ListIterator i = _name_where_.listIterator(); i.hasNext();)
        {
            if(i.next() == oldChild)
            {
                if(newChild != null)
                {
                    i.set(newChild);
                    oldChild.parent(null);
                    return;
                }

                i.remove();
                oldChild.parent(null);
                return;
            }
        }
    }

    private class Univ_Cast implements Cast
    {
        public Object cast(Object o)
        {
            TName node = (TName) o;

            if((node.parent() != null) &&
                (node.parent() != AVar1Declaration.this))
            {
                node.parent().removeChild(node);
            }

            if((node.parent() == null) ||
                (node.parent() != AVar1Declaration.this))
            {
                node.parent(AVar1Declaration.this);
            }

            return node;
        }
    }
    private class NameWhere_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PNameWhere node = (PNameWhere) o;

            if((node.parent() != null) &&
                (node.parent() != AVar1Declaration.this))
            {
                node.parent().removeChild(node);
            }

            if((node.parent() == null) ||
                (node.parent() != AVar1Declaration.this))
            {
                node.parent(AVar1Declaration.this);
            }

            return node;
        }
    }
}
