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

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

Introduction

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

Prototype

public static boolean retainAll(Iterable<?> removeFrom, Collection<?> elementsToRetain) 

Source Link

Document

Removes, from an iterable, every element that does not belong to the provided collection.

Usage

From source file:org.opentestsystem.delivery.testreg.upload.validator.fileformat.DuplicateUniquePair.java

public List<Integer[]> getDuplicateRowNumbers() {
    final Map<DataRecord, List<Integer>> dataRecordDuplicateRowMap = Maps.newHashMap();

    for (final DataRecord record : this.uniqueRecordSet) {

        if (this.duplicates.contains(record)) {
            if (dataRecordDuplicateRowMap.get(record) != null) {
                dataRecordDuplicateRowMap.get(record).add(record.getRowMetadata().getRowNum());
            } else {
                final List<Integer> recordNumbers = new ArrayList<Integer>();
                recordNumbers.add(getRowNumber(record.getRowMetadata()));
                Iterables.retainAll(this.duplicates, Arrays.asList(record));
                recordNumbers.addAll(getRowNumbers(this.duplicates));
                dataRecordDuplicateRowMap.put(record, recordNumbers);
            }//from w  w  w.ja v  a2s  . c o m
        }
    }
    return getDuplicateRowNumber(dataRecordDuplicateRowMap);
}

From source file:org.obeonetwork.graal.design.services.actor.ActorUtils.java

/**
 * Get the list of actors that should be visually connected to a task
 * The list depends on inherited actors and already visible tasks on diagram 
 * @param task The task for which we want the actors list
 * @param tasksOnDiagram List of visible tasks on diagram
 * @return List of Actors/*from www .  j a  va 2 s  .c  om*/
 */
private Collection<Actor> getVisibleLinksToActorsFromTask(Task task, final List<Task> tasksOnDiagram) {
    if (task.getActors().isEmpty()) {
        // Get using tasks that are displayed on diagram
        List<Task> usingTasksOnDiagram = Lists.newArrayList(task.getUsedBy());
        Iterables.retainAll(usingTasksOnDiagram, tasksOnDiagram);

        // Filter the related actors to keep those not already associated with a displayed using task
        List<Actor> relatedActors = Lists.newArrayList(task.getRelatedActors());
        for (Task usingTask : usingTasksOnDiagram) {
            if (!relatedActors.isEmpty()) {
                Iterables.removeAll(relatedActors, usingTask.getRelatedActors());
            } else {
                break;
            }
        }
        // If some of the actors are not linked to displayed tasks
        // we then have to display the whole actors list to prevent from misunderstanding
        if (!relatedActors.isEmpty()) {
            return task.getRelatedActors();
        } else {
            return Collections.emptyList();
        }
    } else {
        return task.getActors();
    }
}

From source file:org.opentestsystem.delivery.testreg.upload.validator.fileformat.DuplicateRecordProcessor.java

/**
 * Returns duplicate rows as list of row numbers array. For example, if row 1 has duplicates in row 8, row 10, row 11
 * and for row 3 have duplicates in row 6, row 9, this method would return a list like [{1,8,10, 11}, {3,6,9}]
 * //from ww  w  .  j  av a2s .  c om
 * @param duplicateUniquePair
 *        A pair object which has duplicate & unique records
 * @return
 *         An Integer array of duplicate row numbers segmented by the similar record type
 */
public List<Integer[]> getDuplicateRowNumbers(final DuplicateUniquePair duplicateUniquePair) {
    final Map<DataRecord, List<Integer>> dataRecordDuplicateRowMap = Maps.newHashMap();

    final List<DataRecord> duplicatesList = duplicateUniquePair.getDuplicates();

    for (final DataRecord record : duplicateUniquePair.getUniqueRecordSet()) {
        if (duplicatesList.contains(record)) {
            if (dataRecordDuplicateRowMap.get(record) != null) {
                dataRecordDuplicateRowMap.get(record).add(getRowNumber(record.getRowMetadata()));
            } else {
                final List<Integer> recordNumbers = Lists.newArrayList();
                recordNumbers.add(getRowNumber(record.getRowMetadata()));
                final List<DataRecord> deseDupes = Lists.newArrayList(ImmutableList.copyOf(duplicatesList));
                Iterables.retainAll(deseDupes, Arrays.asList(record));
                recordNumbers.addAll(getRowNumbers(deseDupes));
                dataRecordDuplicateRowMap.put(record, recordNumbers);
            }
        }
    }
    return getRowNumbersArray(dataRecordDuplicateRowMap.values());
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.elements.Execution.java

private Option<Message> getCompoundMessage(boolean start) {
    Node node = getNotationNode();
    Set<Edge> edges = Sets.newHashSet();
    Iterables.addAll(edges, Iterables.filter(node.getSourceEdges(), Edge.class));
    Iterables.addAll(edges, Iterables.filter(node.getTargetEdges(), Edge.class));

    List<EventEnd> ends = EventEndHelper.findEndsFromSemanticOrdering(this);
    for (Edge edge : edges) {
        Option<Message> message = ISequenceElementAccessor.getMessage(edge);
        if (message.some()) {
            List<EventEnd> messageEnds = EventEndHelper.findEndsFromSemanticOrdering(message.get());
            Iterables.retainAll(messageEnds, ends);
            if (!messageEnds.isEmpty()) {
                SingleEventEnd see = EventEndHelper.getSingleEventEnd(messageEnds.get(0),
                        getSemanticTargetElement().get());
                if (start == see.isStart()) {
                    return message;
                }//from w  ww .  j av a2 s . c o  m
            }
        }
    }
    return Options.newNone();
}

From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.ISEComplexMoveValidator.java

private void categorizeMoves() {
    MoveSwitch moveAnalyzer = new MoveSwitch();
    for (ISequenceEvent movedEvent : Lists.newArrayList(movedElements)) {
        Range extendedRange = moveAnalyzer.doSwitch(movedEvent);
        globalMovedRange = globalMovedRange.union(extendedRange);
    }//  ww  w .  j ava 2 s  .c  o m

    Set<ISequenceEvent> move = Sets.newHashSet();
    move.add(primarySelected);
    move.addAll(otherEntryPoints);
    Iterables.retainAll(move, sequenceNodesToMove);
    Iterables.addAll(topLevelElements, move);

    Rectangle movedRange = new Rectangle(0, globalMovedRange.getLowerBound(), 0, globalMovedRange.width());
    globalMovedRange = RangeHelper.verticalRange(request.getLogicalTransformedRectangle(movedRange));
}

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

/**
 * Get the common {@link ISequenceEvent} between the given ends.
 * /*  w w  w . ja  va  2s.c  o  m*/
 * @param end1
 *            a first {@link EventEnd}
 * @param end2
 *            a second {@link EventEnd}
 * @return the common events between given ends
 */
protected Collection<ISequenceEvent> getCommonISequenceEvent(EventEnd end1, EventEnd end2) {
    if (end1 == null || end2 == null) {
        return Collections.<ISequenceEvent>emptyList();
    }
    Collection<ISequenceEvent> ises1 = endToISequencEvents.get(end1);
    Collection<ISequenceEvent> ises2 = endToISequencEvents.get(end2);
    Collection<ISequenceEvent> commonIses = Lists.newArrayList(ises2);
    Iterables.retainAll(commonIses, ises1);
    return commonIses;
}