• Welcome to Valhalla Legends Archive.
 

testing stacks.

Started by TooTallDawg, July 10, 2006, 02:12 PM

Previous topic - Next topic

TooTallDawg

i'm trying to test 3 stacks.  below is a method that test only 1 stack.  can anyone help me code this method in order for it to test all 3 stacks?

private Stack<Product> fragile;
private Stack<Product> normal;
private Stack<Product> heavy;
.
.
.
.
public Product getProduct() {
       
    if(fragile.empty()) {
            return null;
    } else {
            return fragile.pop();
    }
}


MyndFyre

Test all three stacks for what?  Hepatitis?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

Hdx

What order do you want them to be ested in?
And do you not know of nested ifs?
Tho I wouldnt use them here.
If this is what your looking for here you go:
public Product getProduct() {
       
    if(fragile.empty() != true)
            return fragile.pop();

    if(normal.empty() != true)
            return normal.pop();

    if(heavy.empty() != true)
            return heavy.pop();

    return null;
}

Thats my only guess as for what he wants from the lil info provided.
~-~(HDX)~-~

Proud host of the JBLS server www.JBLS.org.
JBLS.org Status:
JBLS/BNLS Server Status

TooTallDawg

thanks.  that code works just fine.

Ender

I don't want to come off as an asshole, but those boolean literals, true/false, are ugly and unnecessary. Perhaps you did it for clarity, though.

TooTallDawg

would you prefer this:

    public Product getProduct() {
        if(!fragile.empty()) {
            return fragile.pop();
        } else if(!normal.empty()) {
            return normal.pop();
        } else if(!heavy.empty()) {
            return heavy.pop();
        }
        return null;
    }