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

package MONAViewer.monalanguage.node;

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

public final class AImportExp extends PExp
{
    private TString _string_;
    private final LinkedList _map_entry_ = new TypedLinkedList(new MapEntry_Cast());

    public AImportExp ()
    {
    }

    public AImportExp (
            TString _string_,
            List _map_entry_
    )
    {
        setString (_string_);
        this._map_entry_.clear();
        this._map_entry_.addAll(_map_entry_);
    }

    public Object clone()
    {
        return new AImportExp (
            (TString)cloneNode (_string_),
            cloneList (_map_entry_)
        );
    }

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

    public TString getString ()
    {
        return _string_;
    }

    public void setString (TString node)
    {
        if(_string_ != null)
        {
            _string_.parent(null);
        }

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

            node.parent(this);
        }

        _string_ = node;
    }
    public LinkedList getMapEntry ()
    {
        return _map_entry_;
    }

    public void setMapEntry (List list)
    {
        _map_entry_.clear();
        _map_entry_.addAll(list);
    }

    public String toString()
    {
        return ""
            + toString (_string_)
            + toString (_map_entry_)
        ;
    }

    void removeChild(Node child)
    {
        if ( _string_ == child )
        {
            _string_ = null;
            return;
        }
        if ( _map_entry_.remove(child))
        {
            return;
        }
    }

    void replaceChild(Node oldChild, Node newChild)
    {
        if ( _string_ == oldChild )
        {
            setString ((TString) newChild);
            return;
        }
        for(ListIterator i = _map_entry_.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 MapEntry_Cast implements Cast
    {
        public Object cast(Object o)
        {
            PMapEntry node = (PMapEntry) o;

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

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

            return node;
        }
    }
}
