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

org.duelengine.css.ast.ContainerNode Maven / Gradle / Ivy

The newest version!
package org.duelengine.css.ast;

import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class ContainerNode extends CssNode {
	private final List children = new ArrayList();
	private Map variables;

	public ContainerNode(int index, int line, int column) {
		super(index, line, column);
	}

	protected ContainerNode(CssNode... children) {
		if (children != null) {
			for (CssNode child : children) {
				appendChild(child);
			}
		}
	}

	@Override
	public CssNodeType getNodeType() {
		return CssNodeType.CONTAINER;
	}
	
	public boolean hasChildren() {
		return !children.isEmpty();
	}

	public int childCount() {
		return children.size();
	}

	public List getChildren() {
		return children;
	}

	public CssNode getFirstChild() {
		return children.isEmpty() ? null : children.get(0);
	}

	public CssNode getLastChild() {
		return children.isEmpty() ? null : children.get(children.size()-1);
	}

	protected CssNode filterChild(CssNode child) {
		// evaluate any LESS expressions before insertion
		return child.eval(this);
	}

	public void appendChild(CssNode child) {
		child = filterChild(child);
		if (child == null) {
			// variable declarations do not generate content
			return;
		}

		children.add(child);
		child.setParent(this);
	}

	public boolean removeChild(CssNode oldChild) {
		if (oldChild == null) {
			return false;
		}

		for (int i=0; i 0);
	}

	public Collection getVariables() {
		return (variables != null) ? variables.values() : null;
	}

	public boolean containsVariable(String name) {
		return (variables != null) && variables.containsKey(name);
	}
	
	public void putVariable(LessVariableDeclarationNode value) {
		if (variables == null) {
			variables = new HashMap();
		}

		variables.put(value.getIdent(), value);
	}

	public LessVariableDeclarationNode getVariable(String name) {
		if (variables == null || !variables.containsKey(name)) {
			return null;
		}

		return variables.get(name);
	}
	
	@Override
	public boolean equals(Object arg) {
		if (!(arg instanceof ContainerNode) || !this.getClass().equals(arg.getClass())) {
			// includes null
			return false;
		}

		ContainerNode that = (ContainerNode)arg;
		if (this.children.size() != that.children.size()) {
			return false;
		}

		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy