Example usage for com.google.common.collect ImmutableMultiset copyOf

List of usage examples for com.google.common.collect ImmutableMultiset copyOf

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMultiset copyOf.

Prototype

public static <E> ImmutableMultiset<E> copyOf(Iterator<? extends E> elements) 

Source Link

Document

Returns an immutable multiset containing the given elements, in the "grouped iteration order" described in the class documentation.

Usage

From source file:org.apache.calcite.test.CalciteAssert.java

static ImmutableMultiset<String> toSet(ResultSet resultSet) throws SQLException {
    return ImmutableMultiset.copyOf(toList(resultSet));
}

From source file:org.sosy_lab.cpachecker.util.predicates.interpolation.InterpolationManager.java

/**
 * Put the list of formulas into the order in which they should be given to
 * the solver, as defined by the {@link #direction} configuration option.
 * @param traceFormulas The list of formulas to check.
 * @return The same list of formulas in different order,
 *         and each formula has its position in the original list as third element of the pair.
 *///from w  ww .  ja  va  2  s .  c om
private List<Triple<BooleanFormula, AbstractState, Integer>> orderFormulas(
        final List<BooleanFormula> traceFormulas, final List<AbstractState> pAbstractionStates) {

    // In this list are all formulas together with their position in the original list
    ImmutableList.Builder<Triple<BooleanFormula, AbstractState, Integer>> orderedFormulas = ImmutableList
            .builder();

    if (direction == CexTraceAnalysisDirection.ZIGZAG) {
        int e = traceFormulas.size() - 1;
        int s = 0;
        boolean fromStart = false;
        while (s <= e) {
            int i = fromStart ? s++ : e--;
            fromStart = !fromStart;

            orderedFormulas.add(Triple.of(traceFormulas.get(i), pAbstractionStates.get(i), i));
        }

    } else {
        final boolean backwards = direction == CexTraceAnalysisDirection.BACKWARDS;
        final int increment = backwards ? -1 : 1;

        for (int i = backwards ? traceFormulas.size() - 1 : 0; backwards ? i >= 0
                : i < traceFormulas.size(); i += increment) {

            orderedFormulas.add(Triple.of(traceFormulas.get(i), pAbstractionStates.get(i), i));
        }
    }

    ImmutableList<Triple<BooleanFormula, AbstractState, Integer>> result = orderedFormulas.build();
    assert traceFormulas.size() == result.size();
    assert ImmutableMultiset.copyOf(from(result).transform(Triple.getProjectionToFirst()))
            .equals(ImmutableMultiset.copyOf(
                    traceFormulas)) : "Ordered list does not contain the same formulas with the same count";
    return result;
}