Example usage for com.google.common.collect Multiset equals

List of usage examples for com.google.common.collect Multiset equals

Introduction

In this page you can find the example usage for com.google.common.collect Multiset equals.

Prototype

@Override

boolean equals(@Nullable Object object);

Source Link

Document

Compares the specified object with this multiset for equality.

Usage

From source file:com.arpnetworking.tsdaggregator.test.UnorderedRecordEquality.java

/**
 * Compare two <code>Record</code> instances ignoring the ordering of the
 * values in each metric./*from   www  .  j  a  va2  s  .  c o m*/
 * 
 * @param r1 First <code>Record</code> instance.
 * @param r2 Second <code>Record</code> instance.
 * @return True if and only if <code>Record</code> instances are equal
 * irregardless of the order of the values of each metric.
 */
public static boolean equals(final Record r1, final Record r2) {
    if (!r1.getTime().equals(r2.getTime()) || !r1.getAnnotations().equals(r2.getAnnotations())) {
        return false;
    }

    for (final Map.Entry<String, ? extends Metric> entry : r1.getMetrics().entrySet()) {
        if (!r2.getMetrics().containsKey(entry.getKey())) {
            return false;
        }
        final Metric m1 = entry.getValue();
        final Metric m2 = r2.getMetrics().get(entry.getKey());
        if (!m1.getType().equals(m2.getType())) {
            return false;
        }

        final Multiset<Quantity> v1 = HashMultiset.create(m1.getValues());
        final Multiset<Quantity> v2 = HashMultiset.create(m2.getValues());
        if (!v1.equals(v2)) {
            return false;
        }
    }

    return true;
}

From source file:org.jetbrains.jet.checkers.CheckerTestUtil.java

public static void diagnosticsDiff(List<DiagnosedRange> expected, Collection<Diagnostic> actual,
        DiagnosticDiffCallbacks callbacks) {
    Iterator<DiagnosedRange> expectedDiagnostics = expected.iterator();
    List<DiagnosticDescriptor> sortedDiagnosticDescriptors = getSortedDiagnosticDescriptors(actual);
    Iterator<DiagnosticDescriptor> actualDiagnostics = sortedDiagnosticDescriptors.iterator();

    DiagnosedRange currentExpected = safeAdvance(expectedDiagnostics);
    DiagnosticDescriptor currentActual = safeAdvance(actualDiagnostics);
    while (currentExpected != null || currentActual != null) {
        if (currentExpected != null) {
            if (currentActual == null) {
                missingDiagnostics(callbacks, currentExpected);
                currentExpected = safeAdvance(expectedDiagnostics);
            } else {
                int expectedStart = currentExpected.getStart();
                int actualStart = currentActual.getStart();
                int expectedEnd = currentExpected.getEnd();
                int actualEnd = currentActual.getEnd();
                if (expectedStart < actualStart) {
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedStart > actualStart) {
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else if (expectedEnd > actualEnd) {
                    assert expectedStart == actualStart;
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedEnd < actualEnd) {
                    assert expectedStart == actualStart;
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else {
                    assert expectedStart == actualStart && expectedEnd == actualEnd;
                    Multiset<String> actualDiagnosticTypes = currentActual.getDiagnosticTypeStrings();
                    Multiset<String> expectedDiagnosticTypes = currentExpected.getDiagnostics();
                    if (!actualDiagnosticTypes.equals(expectedDiagnosticTypes)) {
                        Multiset<String> expectedCopy = HashMultiset.create(expectedDiagnosticTypes);
                        expectedCopy.removeAll(actualDiagnosticTypes);
                        Multiset<String> actualCopy = HashMultiset.create(actualDiagnosticTypes);
                        actualCopy.removeAll(expectedDiagnosticTypes);

                        for (String type : expectedCopy) {
                            callbacks.missingDiagnostic(type, expectedStart, expectedEnd);
                        }//from  w w  w.  j  a  v a2  s.c  om
                        for (String type : actualCopy) {
                            callbacks.unexpectedDiagnostic(type, actualStart, actualEnd);
                        }
                    }
                    currentExpected = safeAdvance(expectedDiagnostics);
                    currentActual = safeAdvance(actualDiagnostics);
                }

            }
        } else {
            if (currentActual != null) {
                unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                currentActual = safeAdvance(actualDiagnostics);
            } else {
                break;
            }
        }

        //            assert expectedDiagnostics.hasNext() || actualDiagnostics.hasNext();
    }
}

From source file:org.napile.compiler.checkers.CheckerTestUtil.java

public static void diagnosticsDiff(List<DiagnosedRange> expected, Collection<Diagnostic> actual,
        DiagnosticDiffCallbacks callbacks) {
    Iterator<DiagnosedRange> expectedDiagnostics = expected.iterator();
    List<DiagnosticDescriptor> sortedDiagnosticDescriptors = getSortedDiagnosticDescriptors(actual);
    Iterator<DiagnosticDescriptor> actualDiagnostics = sortedDiagnosticDescriptors.iterator();

    DiagnosedRange currentExpected = safeAdvance(expectedDiagnostics);
    DiagnosticDescriptor currentActual = safeAdvance(actualDiagnostics);
    while (currentExpected != null || currentActual != null) {
        if (currentExpected != null) {
            if (currentActual == null) {
                missingDiagnostics(callbacks, currentExpected);
                currentExpected = safeAdvance(expectedDiagnostics);
            } else {
                int expectedStart = currentExpected.getStart();
                int actualStart = currentActual.getStart();
                int expectedEnd = currentExpected.getEnd();
                int actualEnd = currentActual.getEnd();
                if (expectedStart < actualStart) {
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedStart > actualStart) {
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else if (expectedEnd > actualEnd) {
                    assert expectedStart == actualStart;
                    missingDiagnostics(callbacks, currentExpected);
                    currentExpected = safeAdvance(expectedDiagnostics);
                } else if (expectedEnd < actualEnd) {
                    assert expectedStart == actualStart;
                    unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                    currentActual = safeAdvance(actualDiagnostics);
                } else {
                    assert expectedStart == actualStart && expectedEnd == actualEnd;
                    Multiset<String> actualDiagnosticTypes = currentActual.getDiagnosticTypeStrings();
                    Multiset<String> expectedDiagnosticTypes = currentExpected.getDiagnostics();
                    if (!actualDiagnosticTypes.equals(expectedDiagnosticTypes)) {
                        Multiset<String> expectedCopy = HashMultiset.create(expectedDiagnosticTypes);
                        expectedCopy.removeAll(actualDiagnosticTypes);
                        Multiset<String> actualCopy = HashMultiset.create(actualDiagnosticTypes);
                        actualCopy.removeAll(expectedDiagnosticTypes);

                        for (String type : expectedCopy) {
                            callbacks.missingDiagnostic(type, expectedStart, expectedEnd);
                        }//w w w . j  a  v a 2s.co m
                        for (String type : actualCopy) {
                            callbacks.unexpectedDiagnostic(type, actualStart, actualEnd);
                        }
                    }
                    currentExpected = safeAdvance(expectedDiagnostics);
                    currentActual = safeAdvance(actualDiagnostics);
                }
            }
        } else {
            if (currentActual != null) {
                unexpectedDiagnostics(currentActual.getDiagnostics(), callbacks);
                currentActual = safeAdvance(actualDiagnostics);
            } else {
                break;
            }
        }

        //            assert expectedDiagnostics.hasNext() || actualDiagnostics.hasNext();
    }
}

From source file:com.facebook.presto.sql.planner.SubPlan.java

public void sanityCheck() {
    Multiset<PlanFragmentId> exchangeIds = fragment.getRemoteSourceNodes().stream()
            .map(RemoteSourceNode::getSourceFragmentIds).flatMap(List::stream).collect(toImmutableMultiset());

    Multiset<PlanFragmentId> childrenIds = children.stream().map(SubPlan::getFragment).map(PlanFragment::getId)
            .collect(toImmutableMultiset());

    Preconditions.checkState(exchangeIds.equals(childrenIds),
            "Subplan exchange ids don't match child fragment ids (%s vs %s)", exchangeIds, childrenIds);

    for (SubPlan child : children) {
        child.sanityCheck();/*from  w  w  w  .  j  a v  a  2s  .c o  m*/
    }
}

From source file:org.apache.hadoop.hive.ql.optimizer.SharedWorkOptimizer.java

private static SharedResult extractSharedOptimizationInfo(ParseContext pctx,
        SharedWorkOptimizerCache optimizerCache, TableScanOperator retainableTsOp,
        TableScanOperator discardableTsOp) throws SemanticException {
    Set<Operator<?>> retainableOps = new LinkedHashSet<>();
    Set<Operator<?>> discardableOps = new LinkedHashSet<>();
    Set<Operator<?>> discardableInputOps = new HashSet<>();
    long dataSize = 0l;
    long maxDataSize = 0l;

    retainableOps.add(retainableTsOp);/*ww  w  .  j ava2s .c o  m*/
    discardableOps.add(discardableTsOp);
    Operator<?> equalOp1 = retainableTsOp;
    Operator<?> equalOp2 = discardableTsOp;
    if (equalOp1.getNumChild() > 1 || equalOp2.getNumChild() > 1) {
        // TODO: Support checking multiple child operators to merge further.
        discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, discardableOps));
        return new SharedResult(retainableOps, discardableOps, discardableInputOps, dataSize, maxDataSize);
    }
    Operator<?> currentOp1 = retainableTsOp.getChildOperators().get(0);
    Operator<?> currentOp2 = discardableTsOp.getChildOperators().get(0);

    // Special treatment for Filter operator that ignores the DPP predicates
    if (currentOp1 instanceof FilterOperator && currentOp2 instanceof FilterOperator) {
        boolean equalFilters = false;
        FilterDesc op1Conf = ((FilterOperator) currentOp1).getConf();
        FilterDesc op2Conf = ((FilterOperator) currentOp2).getConf();

        if (op1Conf.getIsSamplingPred() == op2Conf.getIsSamplingPred()
                && StringUtils.equals(op1Conf.getSampleDescExpr(), op2Conf.getSampleDescExpr())) {
            Multiset<String> conjsOp1String = extractConjsIgnoringDPPPreds(op1Conf.getPredicate());
            Multiset<String> conjsOp2String = extractConjsIgnoringDPPPreds(op2Conf.getPredicate());
            if (conjsOp1String.equals(conjsOp2String)) {
                equalFilters = true;
            }
        }

        if (equalFilters) {
            equalOp1 = currentOp1;
            equalOp2 = currentOp2;
            retainableOps.add(equalOp1);
            discardableOps.add(equalOp2);
            if (currentOp1.getChildOperators().size() > 1 || currentOp2.getChildOperators().size() > 1) {
                // TODO: Support checking multiple child operators to merge further.
                discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, discardableInputOps));
                discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, discardableOps));
                discardableInputOps
                        .addAll(gatherDPPBranchOps(pctx, optimizerCache, retainableOps, discardableInputOps));
                return new SharedResult(retainableOps, discardableOps, discardableInputOps, dataSize,
                        maxDataSize);
            }
            currentOp1 = currentOp1.getChildOperators().get(0);
            currentOp2 = currentOp2.getChildOperators().get(0);
        } else {
            // Bail out
            discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, discardableInputOps));
            discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, discardableOps));
            discardableInputOps
                    .addAll(gatherDPPBranchOps(pctx, optimizerCache, retainableOps, discardableInputOps));
            return new SharedResult(retainableOps, discardableOps, discardableInputOps, dataSize, maxDataSize);
        }
    }

    // Try to merge rest of operators
    while (!(currentOp1 instanceof ReduceSinkOperator)) {
        // Check whether current operators are equal
        if (!compareOperator(pctx, currentOp1, currentOp2)) {
            // If they are not equal, we could zip up till here
            break;
        }
        if (currentOp1.getParentOperators().size() != currentOp2.getParentOperators().size()) {
            // If they are not equal, we could zip up till here
            break;
        }
        if (currentOp1.getParentOperators().size() > 1) {
            List<Operator<?>> discardableOpsForCurrentOp = new ArrayList<>();
            int idx = 0;
            for (; idx < currentOp1.getParentOperators().size(); idx++) {
                Operator<?> parentOp1 = currentOp1.getParentOperators().get(idx);
                Operator<?> parentOp2 = currentOp2.getParentOperators().get(idx);
                if (parentOp1 == equalOp1 && parentOp2 == equalOp2) {
                    continue;
                }
                if ((parentOp1 == equalOp1 && parentOp2 != equalOp2)
                        || (parentOp1 != equalOp1 && parentOp2 == equalOp2)) {
                    // Input operator is not in the same position
                    break;
                }
                // Compare input
                List<Operator<?>> removeOpsForCurrentInput = compareAndGatherOps(pctx, parentOp1, parentOp2);
                if (removeOpsForCurrentInput == null) {
                    // Inputs are not the same, bail out
                    break;
                }
                // Add inputs to ops to remove
                discardableOpsForCurrentOp.addAll(removeOpsForCurrentInput);
            }
            if (idx != currentOp1.getParentOperators().size()) {
                // If inputs are not equal, we could zip up till here
                break;
            }
            discardableInputOps.addAll(discardableOpsForCurrentOp);
        }

        equalOp1 = currentOp1;
        equalOp2 = currentOp2;
        retainableOps.add(equalOp1);
        discardableOps.add(equalOp2);
        if (equalOp1 instanceof MapJoinOperator) {
            MapJoinOperator mop = (MapJoinOperator) equalOp1;
            dataSize = StatsUtils.safeAdd(dataSize, mop.getConf().getInMemoryDataSize());
            maxDataSize = mop.getConf().getMemoryMonitorInfo().getAdjustedNoConditionalTaskSize();
        }
        if (currentOp1.getChildOperators().size() > 1 || currentOp2.getChildOperators().size() > 1) {
            // TODO: Support checking multiple child operators to merge further.
            break;
        }
        // Update for next iteration
        currentOp1 = currentOp1.getChildOperators().get(0);
        currentOp2 = currentOp2.getChildOperators().get(0);
    }

    // Add the rest to the memory consumption
    Set<Operator<?>> opsWork1 = findWorkOperators(optimizerCache, currentOp1);
    for (Operator<?> op : opsWork1) {
        if (op instanceof MapJoinOperator && !retainableOps.contains(op)) {
            MapJoinOperator mop = (MapJoinOperator) op;
            dataSize = StatsUtils.safeAdd(dataSize, mop.getConf().getInMemoryDataSize());
            maxDataSize = mop.getConf().getMemoryMonitorInfo().getAdjustedNoConditionalTaskSize();
        }
    }
    Set<Operator<?>> opsWork2 = findWorkOperators(optimizerCache, currentOp2);
    for (Operator<?> op : opsWork2) {
        if (op instanceof MapJoinOperator && !discardableOps.contains(op)) {
            MapJoinOperator mop = (MapJoinOperator) op;
            dataSize = StatsUtils.safeAdd(dataSize, mop.getConf().getInMemoryDataSize());
            maxDataSize = mop.getConf().getMemoryMonitorInfo().getAdjustedNoConditionalTaskSize();
        }
    }

    discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, discardableInputOps));
    discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, discardableOps));
    discardableInputOps.addAll(gatherDPPBranchOps(pctx, optimizerCache, retainableOps, discardableInputOps));
    return new SharedResult(retainableOps, discardableOps, discardableInputOps, dataSize, maxDataSize);
}

From source file:net.shipilev.elections.cikrf.Parser.java

private void summaryCompare(PrintWriter pw, SummaryData summ1, SummaryData summ2) {
    HashSet<List<String>> geos = new HashSet<List<String>>();
    geos.addAll(summ1.keys());//from  w  w  w . ja va 2  s.c  o m
    geos.retainAll(summ2.keys());

    boolean foundAnomalies = false;
    for (List<String> geo : geos) {
        Multiset<Metric> val1 = summ1.get(geo);
        Multiset<Metric> val2 = summ2.get(geo);

        Collection<Metric> metrics = new TreeSet<Metric>();
        metrics.addAll(val1.elementSet());
        metrics.addAll(val2.elementSet());

        if (!val1.equals(val2)) {
            foundAnomalies = true;
            pw.printf("Found mismatches in aggregates over %s:\n", geo);
            for (Metric key : metrics) {
                Integer v1 = val1.count(key);
                Integer v2 = val2.count(key);

                if (!v1.equals(v2)) {
                    pw.printf(" {%9d} vs {%9d} [%4.1f%%]: %s\n", v1, v2, (v1 * 100.0 / v2 - 100), key);
                }
            }
            pw.println();
        }
    }

    if (!foundAnomalies) {
        pw.println("No anomalies in data.");
    }

    pw.flush();
}

From source file:additionalpipes.chunk.ChunkManager.java

public void sendPersistentChunks(EntityPlayerMP player) {
    Multiset<ChunkCoordIntPair> oldSet = players.get(player);
    boolean showAllPersistentChunks = oldSet.remove(null);
    Multiset<ChunkCoordIntPair> newSet = HashMultiset.create();

    WorldServer world = (WorldServer) player.worldObj;
    for (Map.Entry<ChunkCoordIntPair, Ticket> e : ForgeChunkManager.getPersistentChunksFor(world).entries()) {
        if (!showAllPersistentChunks && !APDefaultProps.ID.equals(e.getValue().getModId())) {
            continue;
        }//from w ww . j  ava  2s.c  o  m

        if (world.getPlayerManager().isPlayerWatchingChunk(player, e.getKey().chunkXPos,
                e.getKey().chunkZPos)) {
            newSet.add(e.getKey());
        }
    }

    if (!oldSet.equals(newSet)) {
        PacketChunkCoordList packet = new PacketChunkCoordList(APPacketIds.UPDATE_LASERS, newSet);
        CoreProxy.proxy.sendToPlayer(player, packet);
        if (showAllPersistentChunks) {
            newSet.add(null);
        }
        players.put(player, newSet);
    }
}