List of usage examples for com.google.common.base Predicates not
public static <T> Predicate<T> not(Predicate<T> predicate)
From source file:org.apache.brooklyn.core.mgmt.rebind.dto.MementosGenerators.java
/** * @deprecated since 0.7.0; use {@link #newBasicMemento(BrooklynObject)} instead *//* www . j a v a 2 s.c o m*/ @Deprecated public static BasicLocationMemento.Builder newLocationMementoBuilder(Location location) { BasicLocationMemento.Builder builder = BasicLocationMemento.builder(); populateBrooklynObjectMementoBuilder(location, builder); Set<String> nonPersistableFlagNames = MutableMap.<String, Object>builder() .putAll(FlagUtils.getFieldsWithFlagsWithModifiers(location, Modifier.TRANSIENT)) .putAll(FlagUtils.getFieldsWithFlagsWithModifiers(location, Modifier.STATIC)) .put("id", String.class).filterValues(Predicates.not(Predicates.instanceOf(ConfigKey.class))) .build().keySet(); Map<String, Object> persistableFlags = MutableMap.<String, Object>builder().putAll( FlagUtils.getFieldsWithFlagsExcludingModifiers(location, Modifier.STATIC ^ Modifier.TRANSIENT)) .removeAll(nonPersistableFlagNames).build(); ConfigBag persistableConfig = new ConfigBag().copy(((LocationInternal) location).config().getLocalBag()) .removeAll(nonPersistableFlagNames); builder.copyConfig(persistableConfig); builder.locationConfig.putAll(persistableFlags); Location parentLocation = location.getParent(); builder.parent = (parentLocation != null) ? parentLocation.getId() : null; for (Location child : location.getChildren()) { builder.children.add(child.getId()); } return builder; }
From source file:org.opentestsystem.authoring.testauth.publish.SharedPublisherHelper.java
private List<TestComputationRule> buildTestComputationRulesForLevelRules( final List<ScoringRule> scoringRuleList, final List<BlueprintElement> blueprintElementList) { final List<TestComputationRule> testComputationRuleList = Lists.newArrayList(); if (Iterables.any(scoringRuleList, LEVEL_TYPE_FILTER)) { // construct each leaf node into a separate scoring rule final List<ScoringRule> levelScoringRules = Lists .newArrayList(Iterables.filter(scoringRuleList, LEVEL_TYPE_FILTER)); for (final ScoringRule scoringRule : levelScoringRules) { final int i = 1; // winnow blueprintElement list down to matching levels only Iterables.removeIf(blueprintElementList, Predicates.not(LEVEL_FILTER.getInstance(scoringRule.getBlueprintReferenceId()))); // transform every leaf node bp element into a scoring rule mimicking this scoringRule testComputationRuleList.addAll(Lists.transform(blueprintElementList, LEAF_NODE_LEVEL_SCORING_RULE_TRANSFORMER.getInstance(scoringRule, i))); }/*from w w w . jav a 2s. c o m*/ } return testComputationRuleList; }
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 w w. j av a 2s . c om * @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.ui.tools.internal.layout.PinnedElementsHandler.java
/** * Finds all the packable vertical gaps with no edit-parts and moves the * parts beyond them to the left to reduce the gap to the minimum while * still respecting the parts' padding./*from w ww.ja va2s . c om*/ */ private void packHorizontally() { final int[] hRange = getHorizontalRange(allEditParts, EXCLUDE_PADDING); final List<IGraphicalEditPart> movableParts = Lists .newArrayList(Collections2.filter(allEditParts, Predicates.not(isPinned))); Collections.sort(movableParts, leftToRightComparator); for (int i = 0; i < movableParts.size(); i++) { /* * Split the movable parts into two groups (left and right) on index * i. If there is a sufficiently large gap between the two groups, * move the elements of the right group to the left. */ final Set<IGraphicalEditPart> leftSide = Sets.newHashSet(movableParts.subList(0, i)); final Rectangle leftBox; final Insets leftPadding; if (i == 0) { // Artificial box corresponding to the left margin of the figure // along which to pack. leftBox = new Rectangle(hRange[0] - 1, 0, 1, 1); leftPadding = new Insets(0, 0, 0, 0); } else { leftBox = getBoundingBox(leftSide, EXCLUDE_PADDING); leftPadding = getPadding(leftSide); } final Set<IGraphicalEditPart> rightSide = Sets.newHashSet(movableParts.subList(i, movableParts.size())); final Rectangle rightBox = getBoundingBox(rightSide, EXCLUDE_PADDING); final Insets rightPadding = getPadding(rightSide); final int currentGapWidth = rightBox.getLeft().x - leftBox.getRight().x; final int minGapWidth = Math.max(MINIMAL_GAP_WIDTH, Math.max(leftPadding.right, rightPadding.left)); if (i == 0 && isHorizontalOriginFree(allEditParts, hRange[0])) { // We can move the rightSide elements to the free space translate(rightSide, new Dimension(-currentGapWidth, 0)); } else if (currentGapWidth > minGapWidth) { translate(rightSide, new Dimension(-(currentGapWidth - minGapWidth), 0)); } } }
From source file:com.squareup.javapoet.Types.java
private static Type get(javax.lang.model.type.IntersectionType mirror) { final Type[] bounds = FluentIterable.from(mirror.getBounds()).transform(FOR_TYPE_MIRROR) .filter(Predicates.not(Predicates.<Type>equalTo(ClassName.OBJECT))).toArray(Type.class); return new IntersectionType() { @Override/* ww w . j av a 2 s.c o m*/ public Type[] getBounds() { return bounds; } @Override public int hashCode() { return Arrays.hashCode(bounds); } @Override public boolean equals(Object o) { return o instanceof IntersectionType && Arrays.equals(bounds, ((IntersectionType) o).getBounds()); } @Override public String toString() { return typeToString(this); } }; }
From source file:com.puppetlabs.geppetto.graph.catalog.CatalogDeltaGraphProducer.java
private void edgesForResources(RootGraph g, Iterable<CatalogResource> resources, Map<CatalogResource, Vertex> resourceVertexMap, // Map<String, Vertex> vertexMap, // Map<String, Edge> edgeMap, // Set<String> edges) { for (CatalogResource r : resources) { final String sourceKey = keyOf(r); final Vertex source = vertexMap.get(sourceKey); for (CatalogResourceParameter p : Iterables.filter(getParameterIterable(r), Predicates.not(regularParameterPredicate))) { String aName = p.getName(); String style = null;//from w w w .j a v a 2s . com if ("subscribe".equals(aName)) style = CatalogGraphStyles.STYLE_SubscribeEdge; else if ("before".equals(aName)) style = CatalogGraphStyles.STYLE_BeforeEdge; else if ("notify".equals(aName)) style = CatalogGraphStyles.STYLE_NotifyEdge; else style = CatalogGraphStyles.STYLE_RequireEdge; for (String targetRef : p.getValue()) { final String targetKey = targetRef.toLowerCase(); Vertex target = vertexMap.get(targetKey); if (target == null) { target = createVertexForMissingResource(targetRef); vertexMap.put(targetKey, target); // keep it if there are more references g.addVertex(target); } Edge edge = new Edge(aName, style, source, target); String key = sourceKey + "-" + aName + "-" + targetKey; edgeMap.put(key, edge); edges.add(key); } } } }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java
/** * {@inheritDoc}/*from w w w. j a v a 2 s .c o m*/ */ @Override protected boolean applyComputedLayout(Map<? extends ISequenceElement, Range> finalRanges, boolean pack) { boolean applied = false; Iterable<ISequenceEvent> keySet = Iterables.filter(finalRanges.keySet(), ISequenceEvent.class); // Begin with lifelines and executions (anchor positions move) for (ISequenceEvent ise : Iterables.filter(keySet, Predicates.not(Predicates.instanceOf(Message.class)))) { final Range newRange = finalRanges.get(ise); ise.setVerticalRange(newRange); applied = true; } // Then apply computed vertical range on messages for (Message smep : Iterables.filter(keySet, Message.class)) { final Range newRange = finalRanges.get(smep); smep.setVerticalRange(newRange); applied = true; } applied = layoutUnconnectedLostMessageEnd() || applied; return applied; }
From source file:com.sri.ai.grinder.library.Equality.java
/** * Assumes that first argument is an equality (with possibly more than two arguments) and returns a pair, * the first member of which is a set of the variables in the equality, * and the second member of which is a set of constants in the equality. *//*from w ww . j av a2 s . c om*/ public static Pair<Set<Expression>, Set<Expression>> getVariablesListAndConstantsList(Expression equality, RewritingProcess process) { Pair<Set<Expression>, Set<Expression>> result; Set<Expression> variables = new LinkedHashSet<Expression>(); Set<Expression> constants = new LinkedHashSet<Expression>(); Predicate<Expression> notIsConstant = Predicates.not(process.getIsUniquelyNamedConstantPredicate()); Util.collectOrReturnFalseIfElementDoesNotFitEither(equality.getArguments(), variables, notIsConstant, constants, process.getIsUniquelyNamedConstantPredicate()); result = Pair.make(variables, constants); return result; }
From source file:clocker.mesos.entity.MesosClusterImpl.java
/** * De-register our {@link MesosLocation} and its children. *///from ww w . ja v a2s. c o m @Override public void stop() { disconnectSensors(); sensors().set(SERVICE_UP, Boolean.FALSE); deleteLocation(); Duration timeout = config().get(SHUTDOWN_TIMEOUT); // Find all applications and stop, blocking for up to five minutes until ended try { Iterable<Entity> entities = Iterables.filter(getManagementContext().getEntityManager().getEntities(), Predicates.and(MesosUtils.sameCluster(this), Predicates.not(EntityPredicates.applicationIdEqualTo(getApplicationId())))); Set<Application> applications = ImmutableSet .copyOf(Iterables.transform(entities, new Function<Entity, Application>() { @Override public Application apply(Entity input) { return input.getApplication(); } })); LOG.debug("Stopping applications: {}", Iterables.toString(applications)); Entities.invokeEffectorList(this, applications, Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping applications", e); } // Stop all framework tasks in parallel try { Group frameworks = sensors().get(MESOS_FRAMEWORKS); LOG.debug("Stopping framework tasks in: {}", Iterables.toString(frameworks.getMembers())); Entities.invokeEffectorList(this, frameworks.getMembers(), Startable.STOP).get(timeout); } catch (Exception e) { LOG.warn("Error stopping frameworks", e); } // Stop anything else left over // TODO Stop slave entities try { super.stop(); } catch (Exception e) { LOG.warn("Error stopping children", e); } }
From source file:clocker.docker.location.DockerContainerLocation.java
@Override public int copyTo(final Map<String, ?> props, final InputStream src, final long filesize, final String destination) { Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port"))); boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH)); boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH)); if (entitySsh && dockerSsh) { return super.copyTo(nonPortProps, src, filesize, destination); } else {// w w w . j a v a 2s. c om return copyTo(props, src, destination); } }