All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kaazing.robot.lang.ast.AstAcceptNode Maven / Gradle / Ivy

/*
 * Copyright (c) 2014 "Kaazing Corporation," (www.kaazing.com)
 *
 * This file is part of Robot.
 *
 * Robot is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program. If not, see .
 */

package org.kaazing.robot.lang.ast;

import static org.kaazing.robot.lang.ast.util.AstUtil.equivalent;

import java.net.URI;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

public class AstAcceptNode extends AstStreamNode {

    private URI location;
    private Map options;
    private String acceptName;
    private List acceptables;

    public URI getLocation() {
        return location;
    }

    public void setLocation(URI location) {
        this.location = location;
    }

    public String getAcceptName() {
        return acceptName;
    }

    public void setAcceptName(String acceptName) {
        this.acceptName = acceptName;
    }

    public Map getOptions() {
        if (options == null) {
            options = new LinkedHashMap();
        }

        return options;
    }

    public List getAcceptables() {
        if (acceptables == null) {
            acceptables = new LinkedList();
        }

        return acceptables;
    }

    @Override
    public int hashCode() {
        int hashCode = super.hashTo();

        if (location != null) {
            hashCode <<= 4;
            hashCode ^= location.hashCode();
        }

        if (options != null) {
            hashCode <<= 4;
            hashCode ^= options.hashCode();
        }

        if (acceptName != null) {
            hashCode <<= 4;
            hashCode ^= acceptName.hashCode();
        }

        if (acceptables != null) {
            hashCode <<= 4;
            hashCode ^= acceptables.hashCode();
        }

        return hashCode;
    }

    @Override
    public boolean equals(Object obj) {
        return (this == obj) || ((obj instanceof AstAcceptNode) && equalTo((AstAcceptNode) obj));
    }

    protected boolean equalTo(AstAcceptNode that) {
        return super.equalTo(that) && equivalent(this.location, that.location) && equivalent(this.options, that.options)
                && equivalent(this.acceptName, that.acceptName) && equivalent(this.acceptables, that.acceptables);
    }

    @Override
    public  R accept(Visitor visitor, P parameter) throws Exception {

        return visitor.visit(this, parameter);
    }

    @Override
    protected void formatNode(StringBuilder sb) {
        super.formatNode(sb);

        if (acceptables != null) {
            for (AstAcceptableNode acceptable : acceptables) {
                acceptable.formatNode(sb);
            }
        }
    }

    @Override
    protected void formatNodeLine(StringBuilder sb) {
        super.formatNodeLine(sb);
        sb.append("accept ");
        sb.append(location);

        if (acceptName != null) {
            sb.append(" as ");
            sb.append(acceptName);
        }

        sb.append('\n');
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy