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:com.google.gxp.compiler.base.Concatenation.java

public boolean equals(Concatenation that) {
    return equalsExpression(that) && Iterables.elementsEqual(values, that.values);
}

From source file:org.sonatype.nexus.repository.group.GroupFacetImpl.java

@Override
protected void doUpdate(final Configuration configuration) throws Exception {
    // detect member changes
    Set<String> previousMemberNames = config.memberNames;
    super.doUpdate(configuration);

    // check whether any members or their ordering have changed
    if (!Iterables.elementsEqual(config.memberNames, previousMemberNames)) {
        cacheController.invalidateCache();
    }//from  w  ww.j  ava2s.  c  o m
}

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

public boolean equals(Conditional that) {
    return equalsExpression(that) && Iterables.elementsEqual(clauses, that.clauses)
            && elseExpression.equals(that.elseExpression);
}

From source file:org.eclipse.sirius.ui.business.internal.session.EditingSession.java

private void reorderEditorsIfNeeded(DialectEditor justAddedEditor) {
    List<DialectEditor> reorderedList = Lists.newArrayList();
    IEditorReference[] editorReferences = null;

    IWorkbenchPage page = EclipseUIUtil.getActivePage();
    if (page != null) {
        editorReferences = page.getEditorReferences();
    }/*from w w w .  j av  a  2  s  . c o m*/

    if (editorReferences != null) {
        for (IEditorReference ref : Lists.newArrayList(editorReferences)) {
            IEditorPart editor2 = ref.getEditor(false);

            IEditorInput refInput = null;
            try {
                refInput = ref.getEditorInput();
            } catch (PartInitException e) {
                // Can happen during eclipse launch.
            }
            if (editor2 == null && justAddedEditor.getEditorInput() == refInput) {
                reorderedList.add(justAddedEditor);
            } else if (editors.contains(editor2)) {
                reorderedList.add((DialectEditor) editor2);
            }
        }

        if (editors.size() == reorderedList.size() && !Iterables.elementsEqual(editors, reorderedList)) {
            editors.clear();
            editors.addAll(reorderedList);
        }
    }
}

From source file:org.asoem.greyfish.utils.collect.BitString.java

@Override
public final boolean equals(@Nullable final Object obj) {
    if (obj == this) {
        return true;
    }/*from w  w  w. j  a  va2 s  . co m*/
    if (!(obj instanceof BitString)) {
        return false;
    }
    final BitString bitString = (BitString) obj;
    return this.size() == bitString.size() && Iterables.elementsEqual(this.asIndices(), bitString.asIndices());
}

From source file:org.onos.yangtools.yang.data.api.YangInstanceIdentifier.java

boolean pathArgumentsEqual(final YangInstanceIdentifier other) {
    return Iterables.elementsEqual(getPathArguments(), other.getPathArguments());
}

From source file:eu.project.ttc.models.ContextVector.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof ContextVector) {
        ContextVector v = (ContextVector) obj;
        return Objects.equal(this.term, v.term) && Iterables.elementsEqual(this.getEntries(), v.getEntries());
    } else/*ww w.j a  v a  2 s .  c om*/
        return false;
}

From source file:org.elasticsearch.search.suggest.context.CategoryContextMapping.java

@Override
public boolean equals(Object obj) {
    if (obj instanceof CategoryContextMapping) {
        CategoryContextMapping other = (CategoryContextMapping) obj;
        if (this.fieldName.equals(other.fieldName)) {
            return Iterables.elementsEqual(this.defaultValues, other.defaultValues);
        }// w ww  .  j  av  a  2s .  c  om
    }
    return false;
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.operation.SynchronizeISequenceEventsSemanticOrderingOperation.java

private void updateSemanticPosition(ISequenceEvent eventToUpdate) {
    DDiagramElement dde = resolveDiagramElement(eventToUpdate);
    if (dde == null || reordered.contains(eventToUpdate)) {
        return;/*from   w  w  w.j  av a  2s. c o  m*/
    }

    ReorderTool reorderTool = findReorderTool(dde);
    if (reorderTool == null) {
        return;
    }

    EObject semanticElement = dde.getTarget();
    EList<EventEnd> endsBySemanticOrder = sequenceDiagram.getSemanticOrdering().getEventEnds();
    EList<EventEnd> endsByGraphicalOrder = sequenceDiagram.getGraphicalOrdering().getEventEnds();

    List<EventEnd> ends = EventEndHelper.findEndsFromSemanticOrdering(eventToUpdate);
    List<EventEnd> compoundEnds = getCompoundEnds(eventToUpdate, ends);

    // Ignore the ends of the descendants: they are treated by recursive
    // calls.
    Set<EventEnd> toIgnore = selectEndsToIgnore(eventToUpdate, endsBySemanticOrder, ends, compoundEnds);

    // The semantic ordering contains the state before the move
    EventEnd startingEndPredecessorBefore = findEndPredecessor(semanticElement, STARTING_END,
            endsBySemanticOrder, toIgnore);
    EventEnd finishingEndPredecessorBefore = findEndPredecessor(semanticElement, FINISHING_END,
            endsBySemanticOrder, toIgnore);

    // The graphical ordering contains the state after
    EventEnd startingEndPredecessorAfter = findEndPredecessor(semanticElement, STARTING_END,
            endsByGraphicalOrder, toIgnore);
    EventEnd finishingEndPredecessorAfter = findEndPredecessor(semanticElement, FINISHING_END,
            endsByGraphicalOrder, toIgnore);

    // Handle lost messages
    if (eventToUpdate.isLogicallyInstantaneous() && eventToUpdate instanceof Message && ends.size() == 1
            && !Iterables.any(ends, Predicates.instanceOf(CompoundEventEnd.class))) {
        SingleEventEnd see = (SingleEventEnd) ends.iterator().next();
        if (see.isStart()) {
            finishingEndPredecessorBefore = startingEndPredecessorBefore;
            finishingEndPredecessorAfter = startingEndPredecessorAfter;
        } else {
            startingEndPredecessorBefore = finishingEndPredecessorBefore;
            startingEndPredecessorAfter = finishingEndPredecessorAfter;
        }

    }

    if (!Objects.equal(startingEndPredecessorBefore, startingEndPredecessorAfter)
            || !Objects.equal(finishingEndPredecessorBefore, finishingEndPredecessorAfter)
            || !Iterables.elementsEqual(endsByGraphicalOrder, endsBySemanticOrder)) {
        applySemanticReordering(semanticElement, startingEndPredecessorAfter, finishingEndPredecessorAfter,
                reorderTool);
        applyCompoundReordering(semanticElement, ends, compoundEnds, startingEndPredecessorAfter,
                finishingEndPredecessorAfter, reorderTool);
        reordered.add(eventToUpdate);

        new RefreshSemanticOrderingsOperation(sequenceDiagram).execute();
        updateSubEventsSemanticPositions(eventToUpdate);
    }
}

From source file:org.waveprotocol.box.server.waveserver.LocalWaveletContainerImpl.java

/**
 * Apply a signed delta to a local wavelet. This assumes the caller has
 * validated that the delta is at the correct version and can be applied to
 * the wavelet. Must be called with writelock held.
 *
 * @param signedDelta the delta that is to be applied to wavelet.
 * @return the transformed and applied delta.
 * @throws OperationException if an error occurs during transformation or
 *         application/*from  w w w. j av a 2  s.  com*/
 * @throws InvalidProtocolBufferException if the signed delta did not contain a valid delta
 * @throws InvalidHashException if delta hash sanity checks fail
 */
private WaveletDeltaRecord transformAndApplyLocalDelta(ProtocolSignedDelta signedDelta)
        throws OperationException, InvalidProtocolBufferException, InvalidHashException, PersistenceException {
    ProtocolWaveletDelta protocolDelta = ByteStringMessage.parseProtocolWaveletDelta(signedDelta.getDelta())
            .getMessage();

    Preconditions.checkArgument(protocolDelta.getOperationCount() > 0, "empty delta");

    WaveletDelta transformed = maybeTransformSubmittedDelta(
            CoreWaveletOperationSerializer.deserialize(protocolDelta));

    // TODO(ljvderijk): a Clock needs to be injected here (Issue 104)
    long applicationTimestamp = System.currentTimeMillis();

    HashedVersion currentVersion = getCurrentVersion();

    // This is always false right now because the current algorithm doesn't transform ops away.
    if (transformed.size() == 0) {
        Preconditions.checkState(currentVersion.getVersion() != 0,
                "currentVersion can not be 0 if delta was transformed");
        Preconditions.checkState(transformed.getTargetVersion().getVersion() <= currentVersion.getVersion());
        // The delta was transformed away. That's OK but we don't call either
        // applyWaveletOperations(), because that will throw IllegalArgumentException, or
        // commitAppliedDelta(), because empty deltas cannot be part of the delta history.
        TransformedWaveletDelta emptyDelta = new TransformedWaveletDelta(transformed.getAuthor(),
                transformed.getTargetVersion(), applicationTimestamp, transformed);
        return new WaveletDeltaRecord(transformed.getTargetVersion(), null, emptyDelta);
    }

    if (!transformed.getTargetVersion().equals(currentVersion)) {
        Preconditions.checkState(transformed.getTargetVersion().getVersion() < currentVersion.getVersion());
        // The delta was a duplicate of an existing server delta.
        // We duplicate-eliminate it (don't apply it to the wavelet state and don't store it in
        // the delta history) and return the server delta which it was a duplicate of
        // (so delta submission becomes idempotent).
        ByteStringMessage<ProtocolAppliedWaveletDelta> existingDeltaBytes = lookupAppliedDelta(
                transformed.getTargetVersion());
        TransformedWaveletDelta dupDelta = lookupTransformedDelta(transformed.getTargetVersion());
        LOG.info("Duplicate delta " + dupDelta + " for wavelet " + getWaveletName());
        // TODO(anorth): Replace these comparisons with methods on delta classes.
        Preconditions.checkState(dupDelta.getAuthor().equals(transformed.getAuthor()),
                "Duplicate delta detected but mismatched author, expected %s found %s", transformed.getAuthor(),
                dupDelta.getAuthor());
        Preconditions.checkState(Iterables.elementsEqual(dupDelta, transformed),
                "Duplicate delta detected but mismatched ops, expected %s found %s", transformed, dupDelta);

        return new WaveletDeltaRecord(transformed.getTargetVersion(), existingDeltaBytes, dupDelta);
    }

    // Build the applied delta to commit
    ByteStringMessage<ProtocolAppliedWaveletDelta> appliedDelta = AppliedDeltaUtil.buildAppliedDelta(
            signedDelta, transformed.getTargetVersion(), transformed.size(), applicationTimestamp);

    return applyDelta(appliedDelta, transformed);
}