Example usage for com.google.common.collect Iterables elementsEqual

List of usage examples for com.google.common.collect Iterables elementsEqual

Introduction

In this page you can find the example usage for com.google.common.collect Iterables elementsEqual.

Prototype

@CheckReturnValue
public static boolean elementsEqual(Iterable<?> iterable1, Iterable<?> iterable2) 

Source Link

Document

Determines whether two iterables contain equal elements in the same order.

Usage

From source file:org.sosy_lab.cpachecker.cpa.arg.ARGTransferRelation.java

boolean areAbstractSuccessors(AbstractState pElement, CFAEdge pCfaEdge,
        Collection<? extends AbstractState> pSuccessors, ProofChecker wrappedProofChecker)
        throws CPATransferException, InterruptedException {
    ARGState element = (ARGState) pElement;

    assert Iterables.elementsEqual(element.getChildren(), pSuccessors);

    AbstractState wrappedState = element.getWrappedState();
    Multimap<CFAEdge, AbstractState> wrappedSuccessors = HashMultimap.create();
    for (AbstractState absElement : pSuccessors) {
        ARGState successorElem = (ARGState) absElement;
        wrappedSuccessors.put(element.getEdgeToChild(successorElem), successorElem.getWrappedState());
    }//from w w w  .  java 2s.com

    if (pCfaEdge != null) {
        return wrappedProofChecker.areAbstractSuccessors(wrappedState, pCfaEdge,
                wrappedSuccessors.get(pCfaEdge));
    }

    CFANode loc = AbstractStates.extractLocation(element);
    for (CFAEdge edge : leavingEdges(loc)) {
        if (!wrappedProofChecker.areAbstractSuccessors(wrappedState, edge, wrappedSuccessors.get(edge))) {
            return false;
        }
    }
    return true;
}

From source file:com.spectralogic.ds3client.MockNetwork.java

@Override
public WebResponse getResponse(final Ds3Request request) throws IOException {
    assertThat(request.getVerb(), is(this.verb));
    assertThat(request.getPath(), is(this.path));
    if (this.queryParams != null) {
        this.assertMapsEqual(this.queryParams, request.getQueryParams());
    }// ww w .j  a  va 2s . co m

    if (this.requestHeaders != null) {
        assertThat(this.requestHeaders.size(), is(request.getHeaders().size()));
        assertTrue(Iterables.elementsEqual(this.requestHeaders.keySet(), request.getHeaders().keySet()));
        for (final String key : this.requestHeaders.keySet()) {
            assertThat(this.requestHeaders.get(key), is(notNullValue()));
            assertThat(request.getHeaders().get(key), is(notNullValue()));
            assertTrue(Iterables.elementsEqual(this.requestHeaders.get(key), request.getHeaders().get(key)));

        }
    }

    if (this.requestContent != null) {
        final InputStream stream = request.getStream();
        assertThat(stream, is(notNullValue()));
        final String computedStream = IOUtils.toString(stream);
        assertThat(computedStream, is(this.requestContent));
    }
    return new MockedWebResponse(this.responseContent, this.statusCode, this.headers);
}

From source file:com.torodb.kvdocument.values.KvDocument.java

/**
 * Two documents are equal if they contain the same entries in the same order.
 *
 * @param obj// w ww. ja v  a  2  s  .c om
 * @return
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof KvDocument)) {
        return false;
    }
    KvDocument other = (KvDocument) obj;

    return Iterables.elementsEqual(this, other);
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.AbstractSequenceOrderingLayout.java

/**
 * /*  w  w w.  j a  va2s  .c  om*/
 * Look in the semantic, graphical and flaggedEnds orderings to retrieve the
 * safest predecessor and try to keep a stable delta regarding it.
 * 
 * @param currentPos
 *            the current position (x or y)
 * @param element
 *            the current ordering element
 * @param alreadyComputedLocations
 *            the already computed locations
 * @return the delta stable position.
 */
protected int getDeltaStablePosition(final int currentPos, final U element,
        Map<? extends U, Integer> alreadyComputedLocations) {
    int deltaStablePos = currentPos;
    int semanticIndex = semanticOrdering.indexOf(element);
    int graphicalIndex = graphicalOrdering.indexOf(element);
    int flaggedIndex = flaggedEnds.indexOf(element);

    if (flaggedIndex != -1 && semanticIndex != 0 && graphicalIndex != -1) {
        List<U> semanticPredecessors = Lists.newArrayList(semanticOrdering.subList(0, semanticIndex));
        List<U> graphicalPredecessors = Lists.newArrayList(graphicalOrdering.subList(0, graphicalIndex));
        List<U> flaggedPredecessors = Lists.newArrayList(flaggedEnds.subList(0, flaggedIndex));

        // Intersection
        semanticPredecessors.retainAll(flaggedEnds);
        graphicalPredecessors.retainAll(flaggedEnds);
        flaggedPredecessors.retainAll(semanticPredecessors);

        // Which is the safer position ?
        Function<U, Integer> oldPosition = getOldPosition();
        U flaggedPred = null;

        if (Iterables.elementsEqual(semanticPredecessors, graphicalPredecessors)
                && !graphicalPredecessors.isEmpty()) {
            flaggedPred = graphicalPredecessors.get(graphicalPredecessors.size() - 1);
        } else {
            // Desynchronisation -> flagged position
            oldPosition = getOldFlaggedPosition();

            // Look for the last semantic predecessor with same index in
            // semantic and flagged lists.
            U potentialSafePred = null;
            for (int i = 0; i < flaggedPredecessors.size(); i++) {
                U semPot = semanticPredecessors.get(i);
                U flaggedPot = flaggedPredecessors.get(i);
                if (semPot != null && semPot.equals(flaggedPot)) {
                    potentialSafePred = semPot;
                }
            }

            if (potentialSafePred != null) {
                flaggedPred = potentialSafePred;
            }
        }

        if (flaggedPred != null) {
            Integer predY = oldPosition.apply(flaggedPred);
            Integer flaggedY = oldPosition.apply(element);
            int delta = flaggedY - predY;
            if (delta >= 0) {
                deltaStablePos = alreadyComputedLocations.get(flaggedPred) + delta;
            }
        }
    }
    return deltaStablePos;
}

From source file:com.torodb.kvdocument.values.KvArray.java

/**
 * Two ArrayValues values are equal if their contains equal elements in the same position.
 *
 * <p>An easy way to implement that is to delegate on {@link
 * Iterators#elementsEqual(java.lang.Iterator, java.lang.Iterator) }
 *
 * @param obj/*from   w  w  w.  j  av a2  s.c  om*/
 * @return
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof KvArray)) {
        return false;
    }
    KvArray other = (KvArray) obj;
    if (!other.getElementType().equals(this.getElementType())) {
        return false;
    }
    if (!equalsOptimization(other)) {
        return false;
    }
    return Iterables.elementsEqual(other, this);
}

From source file:org.gradle.internal.fingerprint.impl.DefaultCurrentFileCollectionFingerprint.java

private boolean hasSameRootHashes(FileCollectionFingerprint oldFingerprint) {
    return Iterables.elementsEqual(rootHashes.entries(), oldFingerprint.getRootHashes().entries());
}

From source file:com.torodb.torod.core.subdocument.values.ScalarArray.java

/**
 * Two ArrayValues values are equal if their contains equal elements in the
 * same position.//from  ww  w.j a va2  s .c  o m
 *
 * An easy way to implement that is to delegate on
 * {@link Iterators#elementsEqual(java.lang.Iterator, java.lang.Iterator) }
 *
 * @param obj
 * @return
 */
@Override
public boolean equals(Object obj) {
    if (obj == this) {
        return true;
    }
    if (obj == null) {
        return false;
    }
    if (!(obj instanceof ScalarArray)) {
        return false;
    }
    ScalarArray other = (ScalarArray) obj;
    if (!equalsOptimization(other)) {
        return false;
    }
    return Iterables.elementsEqual(other, this);
}

From source file:org.obiba.magma.type.LineStringType.java

@SuppressWarnings("unchecked")
@Override/*from   w w w . j  ava 2s.  c  o m*/
public int compare(Value o1, Value o2) {
    if (o1.isNull() && o2.isNull())
        return 0;
    if (o1.isNull())
        return -1;
    if (o2.isNull())
        return 1;

    Iterable<Coordinate> line1 = (Iterable<Coordinate>) o1.getValue();
    Iterable<Coordinate> line2 = (Iterable<Coordinate>) o2.getValue();
    if (Iterables.size(line1) == Iterables.size(line2)) {
        if (Iterables.elementsEqual(line1, line2))
            return 0;
        return -1;
    }
    if (Iterables.size(line1) < Iterables.size(line2)) {
        return -1;
    }
    return 1;
}

From source file:com.google.gxp.compiler.base.Conditional.java

public Conditional withSchemaAndClauses(Schema newSchema, List<Clause> newClauses,
        Expression newElseExpression) {
    return (Objects.equal(getSchema(), newSchema) && Iterables.elementsEqual(newClauses, clauses)
            && elseExpression.equals(newElseExpression)) ? this
                    : new Conditional(this, newSchema, newClauses, newElseExpression);
}

From source file:com.google.gxp.compiler.base.OutputElement.java

public OutputElement withAttributesAndContent(List<Attribute> newAttributes, Expression newContent) {
    return (Iterables.elementsEqual(newAttributes, attributes) && newContent.equals(content)) ? this
            : new OutputElement(this, newAttributes, newContent);
}