public boolean contains(Object first, Object second) {
        for (Pair p : stack) {
            if (p.first == first && p.second == second ||
                    p.first == second && p.second == first)
            {
                return true;
            }
        }
        return false;
    }