Search in sources :

Example 76 with Stack

use of java.util.Stack in project pcgen by PCGen.

the class OrCommandTest method testOr02.

/* Test the case where the first operand is false, but the second is true */
public void testOr02() {
    final PostfixMathCommandI c = new OrCommand();
    final Stack<Double> s = new Stack<>();
    s.push(0.0);
    s.push(2.0);
    c.setCurNumberOfParameters(2);
    runOr(s, c);
    final Double result = s.pop();
    is(result, eq(2.0, 0.1), "if (0.0,2.0) returns 2.0");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) CompareEqualDouble(pcgen.util.testchecker.CompareEqualDouble) Stack(java.util.Stack)

Example 77 with Stack

use of java.util.Stack in project pcgen by PCGen.

the class OrCommandTest method testOr01.

/* Test the case where the first operand is true */
public void testOr01() {
    final PostfixMathCommandI c = new OrCommand();
    final Stack<Object> s = new Stack<>();
    s.push(1.0);
    s.push(2.0);
    c.setCurNumberOfParameters(2);
    runOr(s, c);
    final Double result = (Double) s.pop();
    is(result, eq(1.0, 0.1), "if (1.0,2.0) returns 1.0");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) CompareEqualDouble(pcgen.util.testchecker.CompareEqualDouble) Stack(java.util.Stack)

Example 78 with Stack

use of java.util.Stack in project pcgen by PCGen.

the class OrCommandTest method testOr05.

/* Test the case where false and zero are skipped */
public void testOr05() {
    final PostfixMathCommandI c = new OrCommand();
    final Stack s = new Stack();
    s.push(false);
    s.push(false);
    s.push(false);
    s.push(false);
    c.setCurNumberOfParameters(4);
    runOr(s, c);
    final Object result = s.pop();
    is(result, new CompareEqualDouble(0.0), "if (false,false,false,false) returns 0.0");
}
Also used : PostfixMathCommandI(org.nfunk.jep.function.PostfixMathCommandI) CompareEqualDouble(pcgen.util.testchecker.CompareEqualDouble) Stack(java.util.Stack)

Example 79 with Stack

use of java.util.Stack in project pcgen by PCGen.

the class OrCommand method run.

/**
	 * @param inStack
	 *            Stack of incoming arguments.
	 * @throws ParseException
	 */
@Override
@SuppressWarnings({ "unchecked" })
public //Uses JEP, which doesn't use generics
void run(final Stack inStack) throws ParseException {
    // check the stack
    checkStack(inStack);
    // Check if stack is null
    if (null == inStack) {
        throw new ParseException("Stack argument null");
    }
    final Stack newStack = new Stack();
    int paramCount = curNumberOfParameters;
    while (paramCount > 0) {
        paramCount--;
        newStack.push(inStack.pop());
    }
    int paramCount1 = curNumberOfParameters;
    Object result = 0.0;
    while (paramCount1 > 0) {
        paramCount1--;
        final Object operand = newStack.pop();
        // If we're haven't found a true value yet
        if (operand instanceof Number) {
            if (((Number) operand).doubleValue() != 0.0d) {
                result = operand;
                break;
            }
        } else if (operand instanceof Boolean) {
            if ((Boolean) operand) {
                result = operand;
                break;
            }
        } else {
            throw new ParseException("Invalid parameter type for: " + operand);
        }
    }
    // finally, put back the result
    inStack.push(result);
}
Also used : ParseException(org.nfunk.jep.ParseException) Stack(java.util.Stack)

Example 80 with Stack

use of java.util.Stack in project Main by SpartanRefactoring.

the class PropositionTest method hasCycles.

private boolean hasCycles(final BooleanSupplier s) {
    final Stack<BooleanSupplier> path = new Stack<>();
    path.add(s);
    final Queue<BooleanSupplier> todo = new LinkedList<>();
    do {
        final BooleanSupplier current = todo.isEmpty() ? path.pop() : todo.remove();
        if (path.contains(current))
            return true;
        if (current instanceof Proposition.Some) {
            todo.addAll(((Proposition.Some) current).inner);
            continue;
        }
        if (current instanceof Proposition.Singleton)
            path.push(((Proposition.Singleton) current).inner);
    } while (!path.isEmpty());
    return false;
}
Also used : Proposition(il.org.spartan.utils.Proposition) BooleanSupplier(java.util.function.BooleanSupplier) LinkedList(java.util.LinkedList) Stack(java.util.Stack)

Aggregations

Stack (java.util.Stack)245 HashSet (java.util.HashSet)42 ArrayList (java.util.ArrayList)37 File (java.io.File)23 IOException (java.io.IOException)22 View (android.view.View)18 Test (org.junit.Test)18 ViewGroup (android.view.ViewGroup)14 HashMap (java.util.HashMap)14 Set (java.util.Set)12 LinkedList (java.util.LinkedList)11 List (java.util.List)11 ImageView (android.widget.ImageView)10 Map (java.util.Map)10 Document (org.w3c.dom.Document)10 TestInputHandler (org.apache.maven.plugins.repository.testutil.TestInputHandler)9 PostfixMathCommandI (org.nfunk.jep.function.PostfixMathCommandI)9 DocumentBuilder (javax.xml.parsers.DocumentBuilder)8 NotificationPanelView (com.android.systemui.statusbar.phone.NotificationPanelView)7 TreeSet (java.util.TreeSet)7