com.obdobion.algebrain.operator.OpXnor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algebrain Show documentation
Show all versions of algebrain Show documentation
Equation processing for Java
The newest version!
package com.obdobion.algebrain.operator;
import java.text.ParseException;
import com.obdobion.algebrain.EquPart;
import com.obdobion.algebrain.Operator;
import com.obdobion.algebrain.ValueStack;
/**
*
* OpOr class.
*
*
* @author Chris DeGreef [email protected]
* @since 1.3.9
*/
public class OpXnor extends Operator
{
/**
*
* Constructor for OpOr.
*
*/
public OpXnor()
{}
/**
*
* Constructor for OpOr.
*
*
* @param opTok a {@link com.obdobion.algebrain.EquPart} object.
*/
public OpXnor(final EquPart opTok)
{
super(opTok);
}
/** {@inheritDoc} */
@Override
protected int precedence()
{
return 9;
}
/** {@inheritDoc} */
@Override
public void resolve(final ValueStack values) throws Exception
{
if (values.size() < 2)
throw new Exception("missing operands for " + toString());
try
{
final boolean b0 = values.popBoolean();
final boolean b1 = values.popBoolean();
values.push(new Boolean(!((b1 || b0) && !(b1 && b0))));
} catch (final ParseException e)
{
e.fillInStackTrace();
throw new Exception(toString() + "; " + e.getMessage(), e);
}
}
/** {@inheritDoc} */
@Override
public String toString()
{
return "op(xnor)";
}
}