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

package MONAViewer.monalanguage.node;

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

public final class AQuantExp extends PExp
{
    private final LinkedList _q_ = new TypedLinkedList(new Q_Cast());
    private PExp _tail_;

    public AQuantExp ()
    {
    }

    public AQuantExp (
            List _q_,
            PExp _tail_
    )
    {
        this._q_.clear();
        this._q_.addAll(_q_);
        setTail (_tail_);
    }

    public Object clone()
    {
        return new AQuantExp (
            cloneList (_q_),
            (PExp)cloneNode (_tail_)
        );
    }

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

    public LinkedList getQ ()
    {
        return _q_;
    }

    public void setQ (List list)
    {
        _q_.clear();
        _q_.addAll(list);
    }
    public PExp getTail ()
    {
        return _tail_;
    }

    public void setTail (PExp node)
    {
        if(_tail_ != null)
        {
            _tail_.parent(null);
        }

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

            node.parent(this);
        }

        _tail_ = node;
    }

    public String toString()
    {
        return ""
            + toString (_q_)
            + toString (_tail_)
        ;
    }

    void removeChild(Node child)
    {
        if ( _q_.remove(child))
        {
            return;
        }
        if ( _tail_ == child )
        {
            _tail_ = null;
            return;
        }
    }

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

                i.remove();
                oldChild.parent(null);
                return;
            }
        }
        if ( _tail_ == oldChild )
        {
            setTail ((PExp) newChild);
            return;
        }
    }

    private class Q_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PExp node = (PExp) o;

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

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

            return node;
        }
    }
}
