package org.spbu.bdd.core.impl;

import org.spbu.bdd.core.IBddBackend;
import org.spbu.bdd.core.INode;
import org.spbu.bdd.core.INonterminal;

public class NonterminalImpl extends NodeImpl implements INonterminal {
	int var;
	int one;
	int zero;
	IBddBackend backend;	
	
	public String toString() {
		return "NT var "+var+" index "+index+" <"+one+"> <"+zero+">";
	}
	
	public NonterminalImpl(int var, int one, int zero, IBddBackend backend) {
		this(var, one, zero, backend, 0);
	}
	
	public NonterminalImpl(int var, int one, int zero, IBddBackend backend, int index) {
		super();
		this.var = var;
		this.one = one;
		this.zero = zero;
		this.backend = backend;
		setIndex(index);
	}
	
	public int oneIndex() {
		return one;
	}
	
	public int zeroIndex() {
		return zero;
	}
	
	public INode one() {
		return backend.getNode(one);
	}
	public int var() {
		return var;
	}
	public INode zero() {
		return backend.getNode(zero);
	}
	public boolean isTerm() {
		return false;
	}

	@Override
	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + one;
		result = PRIME * result + var;
		result = PRIME * result + zero;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NonterminalImpl other = (NonterminalImpl) obj;
		if (one != other.one)
			return false;
		if (var != other.var)
			return false;
		if (zero != other.zero)
			return false;
		return true;
	}
}
