Example usage for com.google.common.base Predicates in

List of usage examples for com.google.common.base Predicates in

Introduction

In this page you can find the example usage for com.google.common.base Predicates in.

Prototype

public static <T> Predicate<T> in(Collection<? extends T> target) 

Source Link

Document

Returns a predicate that evaluates to true if the object reference being tested is a member of the given collection.

Usage

From source file:com.isotrol.impe3.palette.menu.category.CategoryComponent.java

private Predicate<Category> calculateSelected() {
    Category c = getSelected();//  w w w  .j a  v  a 2 s .co m
    if (c == null || !categories.containsValue(c)) {
        return Predicates.alwaysFalse();
    }
    if (config != null && config.selectParents()) {
        Set<Category> selected = Sets.newHashSet();
        do {
            selected.add(c);
            c = categories.getParent(c.getId());
        } while (c != null);
        return Predicates.in(selected);
    }
    return Predicates.equalTo(c);
}

From source file:org.eclipse.sirius.diagram.sequence.business.internal.query.ISequenceEventQuery.java

private void populateMovedElements(ISequenceEvent inspectedElement, Collection<ISequenceEvent> moved) {
    moved.add(inspectedElement);// www.  j  a va  2 s . co  m
    for (ISequenceEvent subEvent : Iterables.filter(inspectedElement.getEventsToMoveWith(),
            Predicates.not(Predicates.in(moved)))) {
        populateMovedElements(subEvent, moved);
    }

}

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

/**
 * Computes the delta between lostEnds and their attached lifeline.
 * /*from  w ww.  j  a  v a2 s.  c o m*/
 * @param pack
 *            pack the space between instance roles.
 * @return computed deltas.
 */
public Map<LostMessageEnd, Integer> computeLostMessageEndDeltaWithLifeline(boolean pack) {
    Map<LostMessageEnd, Integer> deltas = Maps.newHashMap();

    for (Lifeline lifeline : sequenceDiagram.getAllLifelines()) {
        int lifelineX = lifeline.getProperLogicalBounds().x;

        // Align sources on left
        Map<Operand, Integer> maxOpSourceDeltas = Maps.newHashMap();
        int maxLifelineSourceDelta = 0;
        for (LostMessageEnd lostSource : lostSources.get(lifeline)) {
            Rectangle bounds = lostSource.getProperLogicalBounds().getCopy();
            int delta = bounds.x - lifelineX;
            if (pack || AbstractSequenceLayout.createdFromTool(lostSource)
                    || AbstractSequenceLayout.createdFromExternalChange(lostSource)) {
                delta = getFoundEndPackedX(lostSource, lifeline, lifelineX, bounds.width);
            }
            deltas.put(lostSource, delta);

            // Force align
            if (operands.containsKey(lostSource)) {
                Operand op = operands.get(lostSource);
                int opMax = 0;
                if (maxOpSourceDeltas.containsKey(op)) {
                    opMax = maxOpSourceDeltas.get(op);
                }
                opMax = Math.min(opMax, delta);
                maxOpSourceDeltas.put(op, opMax);
            } else {
                Kind kind = getMessageKind(lostSource);

                if (!Message.Kind.CREATION.equals(kind) && !Message.Kind.DESTRUCTION.equals(kind)) {
                    maxLifelineSourceDelta = Math.min(maxLifelineSourceDelta, delta);
                }
            }
        }

        // Align targets on right
        Map<Operand, Integer> maxOpTargetDeltas = Maps.newHashMap();
        int maxLifelineTargetDelta = 0;
        for (LostMessageEnd lostTarget : lostTargets.get(lifeline)) {
            Rectangle bounds = lostTarget.getProperLogicalBounds().getCopy();
            int delta = bounds.x - lifelineX;
            if (pack || AbstractSequenceLayout.createdFromTool(lostTarget)
                    || AbstractSequenceLayout.createdFromExternalChange(lostTarget)) {
                delta = LayoutConstants.LOST_MESSAGE_DEFAULT_WIDTH;
                if (lostMessages.containsKey(lostTarget)) {
                    Message message = lostMessages.get(lostTarget);
                    delta += message.getSourceElement().getProperLogicalBounds().right() - lifelineX;
                } else if (unconnectedLostEnds.contains(lostTarget)) {
                    ISequenceEvent sourceEvent = getISequenceEvent(getKnownSourceNode(lostTarget));
                    if (sourceEvent != null) {
                        delta += sourceEvent.getProperLogicalBounds().right() - lifelineX;
                    }
                }
            }
            deltas.put(lostTarget, delta);

            // Force align
            if (operands.containsKey(lostTarget)) {
                Operand op = operands.get(lostTarget);
                int opMax = 0;
                if (maxOpTargetDeltas.containsKey(op)) {
                    opMax = maxOpTargetDeltas.get(op);
                }
                opMax = Math.max(opMax, delta);
                maxOpTargetDeltas.put(op, opMax);
            } else {
                maxLifelineTargetDelta = Math.max(maxLifelineTargetDelta, delta);
            }
        }

        // Force align
        if (pack) {
            for (Map.Entry<Operand, Integer> entry : maxOpSourceDeltas.entrySet()) {
                Integer maxSourceDelta = entry.getValue();
                for (LostMessageEnd source : Iterables.filter(operands2lostEnds.get(entry.getKey()),
                        Predicates.in(lostSources.get(lifeline)))) {
                    deltas.put(source, maxSourceDelta);
                }
            }
            for (LostMessageEnd source : Iterables.filter(lostSources.get(lifeline),
                    Predicates.not(Predicates.in(operands.keySet())))) {
                Kind kind = getMessageKind(source);

                if (!Message.Kind.CREATION.equals(kind) && !Message.Kind.DESTRUCTION.equals(kind)) {
                    deltas.put(source, maxLifelineSourceDelta);
                }
            }
            for (Map.Entry<Operand, Integer> entry : maxOpTargetDeltas.entrySet()) {
                Integer maxTargetDelta = entry.getValue();
                for (LostMessageEnd target : Iterables.filter(operands2lostEnds.get(entry.getKey()),
                        Predicates.in(lostTargets.get(lifeline)))) {
                    deltas.put(target, maxTargetDelta);
                }
            }
            for (LostMessageEnd target : Iterables.filter(lostTargets.get(lifeline),
                    Predicates.not(Predicates.in(operands.keySet())))) {
                deltas.put(target, maxLifelineTargetDelta);
            }
        }
    }
    return deltas;
}

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

private void applyCompoundReordering(EObject semanticElement, List<EventEnd> ends, List<EventEnd> compoundEnds,
        EventEnd startingEndPredecessor, EventEnd finishingEndPredecessor, ReorderTool reorderTool) {
    if (compoundEnds.isEmpty() || ends.size() != 2) {
        return;//from  w  w w.j a  v  a 2s.  co  m
    }

    EventEnd startEventEnd = null;
    EventEnd endEventEnd = null;
    List<EObject> startSemanticEvents = Lists.newArrayList();

    // The main event has been reordered, the order of its ends might have
    // changed.
    for (EventEnd ee : ends) {
        SingleEventEnd see = EventEndHelper.getSingleEventEnd(ee, semanticElement);
        if (see.isStart()) {
            startEventEnd = ee;
            startSemanticEvents = EventEndHelper.getSemanticEvents(startEventEnd);
        } else {
            endEventEnd = ee;
        }
    }

    for (EventEnd ee : compoundEnds) {
        List<EObject> eeSemElts = EventEndHelper.getSemanticEvents(ee);
        EventEnd otherEnd = Iterables.any(eeSemElts, Predicates.in(startSemanticEvents)) ? startEventEnd
                : endEventEnd;
        EventEnd predecessor = Iterables.any(eeSemElts, Predicates.in(startSemanticEvents))
                ? startingEndPredecessor
                : finishingEndPredecessor;

        for (EObject elt : eeSemElts) {
            SingleEventEnd singleEventEnd = EventEndHelper.getSingleEventEnd(otherEnd, elt);
            ISequenceEvent ise = EventEndHelper.findISequenceEvent(singleEventEnd, diagram);
            if (!singleEventEnd.isStart()) {
                // SemanticEvent is before otherEnd
                applySemanticReordering(elt, predecessor, ee, reorderTool);
            } else {
                // SemanticEvent is after otherEnd
                applySemanticReordering(elt, predecessor, otherEnd, reorderTool);
            }
            reordered.add(ise);
        }
    }
}

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

private Collection<Range> getTitleZoneRanges(SequenceDiagram diagram) {
    Collection<Range> titleZones = Lists.newArrayList();
    for (CombinedFragment unmovedCF : Iterables.filter(diagram.getAllCombinedFragments(),
            Predicates.not(Predicates.in(movedElements)))) {
        int titleZoneLowerBound = rangeFunction.apply(unmovedCF).getLowerBound();
        int titleZoneUpperBound = rangeFunction.apply(unmovedCF.getFirstOperand()).getLowerBound();

        titleZones.add(new Range(titleZoneLowerBound, titleZoneUpperBound));
    }//from   w ww . ja v  a 2  s.  c om
    return titleZones;
}

From source file:org.apache.ambari.server.api.services.stackadvisor.StackAdvisorBlueprintProcessor.java

/**
 * Remove user defined properties from stack advisor output in case of it applies only on the stack defaults
 *///from  w ww.jav  a2  s .  com
private BlueprintConfigurations filterBlueprintConfig(String configType, BlueprintConfigurations config,
        Map<String, Map<String, String>> userProvidedProperties, ClusterTopology topology) {
    if (topology.getConfigRecommendationStrategy() == ConfigRecommendationStrategy.ONLY_STACK_DEFAULTS_APPLY) {
        if (userProvidedProperties.containsKey(configType)) {
            BlueprintConfigurations newConfig = new BlueprintConfigurations();
            Map<String, String> filteredProps = Maps.filterKeys(config.getProperties(),
                    Predicates.not(Predicates.in(userProvidedProperties.get(configType).keySet())));
            newConfig.setProperties(Maps.newHashMap(filteredProps));

            if (config.getPropertyAttributes() != null) {
                Map<String, ValueAttributesInfo> filteredAttributes = Maps.filterKeys(
                        config.getPropertyAttributes(),
                        Predicates.not(Predicates.in(userProvidedProperties.get(configType).keySet())));
                newConfig.setPropertyAttributes(Maps.newHashMap(filteredAttributes));
            }
            return newConfig;
        }
    }
    return config;
}

From source file:eu.numberfour.n4js.external.EclipseExternalLibraryWorkspace.java

@Override
public void registerProjects(NpmProjectAdaptionResult result, IProgressMonitor monitor) {

    checkState(result.isOK(), "Expected OK result: " + result);

    final SubMonitor subMonitor = convert(monitor, 3);

    final Iterable<IProject> projectsToClean = from(result.getToBeBuilt().getToBeDeleted())
            .transform(uri -> getProject(new File(uri).getName())).filter(notNull());

    final Collection<IProject> workspaceProjectsToRebuild = newHashSet(
            collector.collectProjectsWithDirectExternalDependencies(projectsToClean));

    // Clean projects.
    if (!Iterables.isEmpty(projectsToClean)) {
        builderHelper.clean(projectsToClean, subMonitor.newChild(1));
    }/*from   w  ww  .ja va  2s.co  m*/
    subMonitor.worked(1);

    // Update internal state.
    updateState();

    // Rebuild whole external workspace. Filter out projects that are present in the Eclipse workspace (if any).
    final Collection<String> eclipseWorkspaceProjectNames = getAllEclipseWorkspaceProjectNames();
    final Predicate<String> eclipseWorkspaceProjectNamesFilter = Predicates.in(eclipseWorkspaceProjectNames);

    final Iterable<IProject> projectsToBuild = from(result.getToBeBuilt().getToBeUpdated())
            .transform(uri -> getProject(new File(uri).getName())).filter(notNull())
            .filter(p -> !eclipseWorkspaceProjectNamesFilter.apply(p.getName()));

    // Build recently added projects that do not exist in workspace.
    // XXX akitta: consider filtering out external projects that exists in index already. (@ higher priority level)
    if (!Iterables.isEmpty(projectsToBuild)) {
        builderHelper.build(projectsToBuild, subMonitor.newChild(1));
    }
    subMonitor.worked(1);

    addAll(workspaceProjectsToRebuild,
            collector.collectProjectsWithDirectExternalDependencies(projectsToBuild));
    scheduler.scheduleBuildIfNecessary(workspaceProjectsToRebuild);

}

From source file:org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.filters.impl.DifferenceFilterManager.java

/**
 * Store value in preferences./*from w ww  .j  ava 2  s .  co m*/
 * 
 * @param currentValue
 *            Value to store.
 * @param defaultConf
 *            Default value.
 */
private void storeInPreferences(Set<? extends IDifferenceFilter> currentValue,
        Set<? extends IDifferenceFilter> defaultConf, String prefKey) {
    if (currentValue != null && !currentValue.equals(defaultConf)) {
        Map<String, IDifferenceFilter> toStore = Maps.filterValues(Maps.transformValues(map, TO_FILTER),
                Predicates.in(currentValue));
        String preferenceValue = Joiner.on(ItemUtil.PREFERENCE_DELIMITER).join(toStore.keySet());
        preferenceStore.put(prefKey, preferenceValue);
    } else {
        preferenceStore.remove(prefKey);
    }
}

From source file:org.eclipse.xtext.util.formallang.NfaToProduction.java

protected <T> boolean createAlternative(StateAliasNfa<T> states) {
    boolean created = false;
    Multimap<Pair<Set<StateAlias<T>>, Set<StateAlias<T>>>, StateAlias<T>> alternative = LinkedHashMultimap
            .create();/*www .j ava2s .c o m*/

    for (StateAlias<T> candidate : new NfaUtil().collect(states))
        if (!candidate.getIncoming().isEmpty() && !candidate.getOutgoing().isEmpty())
            alternative.put(Tuples.create(candidate.getIncoming(), candidate.getOutgoing()), candidate);

    for (Pair<Set<StateAlias<T>>, Set<StateAlias<T>>> inout : alternative.keySet()) {
        Collection<StateAlias<T>> candidates = alternative.get(inout);

        if (candidates.size() < 2)
            continue;

        boolean many = inout.getFirst().containsAll(candidates) && inout.getSecond().containsAll(candidates);
        boolean single = !Iterables.any(inout.getFirst(), Predicates.in(candidates))
                && !Iterables.any(inout.getSecond(), Predicates.in(candidates));
        if (!many && !single)
            continue;

        AlternativeAlias<T> alt = new AlternativeAlias<T>();
        alt.setMany(many);
        StateAlias<T> altState = new StateAlias<T>(alt);
        for (StateAlias<T> candidate : candidates) {
            alt.addChild(candidate.getElement());
            for (StateAlias<T> in : candidate.getIncoming())
                in.getOutgoing().remove(candidate);
            for (StateAlias<T> out : candidate.getOutgoing())
                out.getIncoming().remove(candidate);
        }
        for (StateAlias<T> in : inout.getFirst())
            if (!candidates.contains(in)) {
                altState.getIncoming().add(in);
                in.getOutgoing().add(altState);
            }
        for (StateAlias<T> out : inout.getSecond())
            if (!candidates.contains(out)) {
                altState.getOutgoing().add(out);
                out.getIncoming().add(altState);
            }
        created = true;
    }
    return created;
}

From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.util.FinalParentHelper.java

/**
 * Get the {@link ISequenceEvent} for ...
 * // w  ww  .  jav a  2s  .  c  o  m
 * @param self
 *            {@link AbstractNodeEvent} to consider.
 * @param smep
 *            the {@link Message} to consider.
 * @param deltaY
 *            the deltaY to use
 * @param deltaHeight
 *            the deltaHeight to use
 * 
 * @return the {@link ISequenceEvent} for ...
 */
public static ISequenceEvent getFinalRemoteParent(AbstractNodeEvent self, Message smep, int deltaY,
        int deltaHeight) {
    Range finalMessageRange = smep.getVerticalRange().shifted(deltaY);
    if (deltaHeight != 0) {
        finalMessageRange = new Range(finalMessageRange.getLowerBound(),
                finalMessageRange.getUpperBound() + deltaHeight);
    }
    Set<ISequenceEvent> allMovedElements = new ISequenceEventQuery(self).getAllDescendants();
    allMovedElements.add(self);

    ISequenceEvent sourceParent = (smep.getSourceElement() instanceof ISequenceEvent)
            ? (ISequenceEvent) smep.getSourceElement()
            : null;

    /*
     * The target will not be an ISequenceEvent for creation and destruction
     * messages as instance roles and EOL are not ISequenceEvents.
     */
    ISequenceEvent targetParent = (smep.getTargetElement() instanceof ISequenceEvent)
            ? (ISequenceEvent) smep.getTargetElement()
            : null;
    ISequenceEvent remoteParent = allMovedElements.contains(sourceParent) ? targetParent : sourceParent;

    ISequenceEvent finalRemoteParent = null;
    if (remoteParent != null) {
        Option<Lifeline> remoteLifeline = remoteParent.getLifeline();
        if (remoteLifeline.some()) {
            EventFinder remoteFinder = new EventFinder(remoteLifeline.get());
            remoteFinder.setEventsToIgnore(Predicates.in(Lists.newArrayList(allMovedElements)));
            finalRemoteParent = remoteFinder.findMostSpecificEvent(finalMessageRange);
        }
    }
    return finalRemoteParent;
}