List of usage examples for com.google.common.base Predicates not
public static <T> Predicate<T> not(Predicate<T> predicate)
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.FrameCreationValidator.java
private void computeExpanzionZone(Range creationRange) { if (ccdTool instanceof InteractionUseCreationTool) { for (ISequenceEvent parent : localParents) { Range newExpansionZone = new Range(parent.getVerticalRange().getUpperBound() - 1, creationRange.getUpperBound()); expansionZone = expansionZone.union(newExpansionZone); }//from w w w .j a v a 2 s.c o m SortedSet<ISequenceEvent> overlapped = Sets.newTreeSet(new RangeComparator()); overlapped.addAll(sequenceEventsInCreationRange.values()); for (ISequenceEvent ise : Iterables.filter(overlapped, Predicates.not(Predicates.in(localParents)))) { int lowerBound = ise.getVerticalRange().getLowerBound(); if (lowerBound >= creationRange.getLowerBound()) { Range newExpansionZone = new Range(lowerBound - 1, creationRange.getUpperBound()); expansionZone = expansionZone.union(newExpansionZone); break; } } } else if (ccdTool instanceof CombinedFragmentCreationTool) { Collection<ISequenceEvent> partialOverlaps = Lists .newArrayList(Iterables.concat(localParents, eventsToShift)); for (ISequenceEvent parent : localParents) { checkOtherLifelines(parent, partialOverlaps); int expansionCut = Math.max(creationRange.getLowerBound(), parent.getVerticalRange().getUpperBound() - 1); Range newExpansionZone = new Range(expansionCut, creationRange.getUpperBound()); expansionZone = expansionZone.union(newExpansionZone); } for (ISequenceEvent eventToShift : eventsToShift) { checkOtherLifelines(eventToShift, partialOverlaps); int expansionCut = Math.max(creationRange.getLowerBound(), eventToShift.getVerticalRange().getLowerBound() - 1); Range newExpansionZone = new Range(expansionCut, creationRange.getUpperBound()); expansionZone = expansionZone.union(newExpansionZone); } } }
From source file:brooklyn.entity.nosql.etcd.EtcdClusterImpl.java
protected void onServerPoolMemberChanged(Entity member) { synchronized (mutex) { log.debug("For {}, considering membership of {} which is in locations {}", new Object[] { this, member, member.getLocations() }); Map<Entity, String> nodes = getAttribute(ETCD_CLUSTER_NODES); if (belongsInServerPool(member)) { if (nodes == null) { nodes = Maps.newLinkedHashMap(); }//from w w w. j a v a2 s . c om String name = Preconditions.checkNotNull(getNodeName(member)); // Wait until node has been installed DynamicTasks .queueIfPossible( DependentConfiguration.attributeWhenReady(member, EtcdNode.ETCD_NODE_INSTALLED)) .orSubmitAndBlock(this).andWaitForSuccess(); // Check for first node in the cluster. Entity firstNode = getAttribute(DynamicCluster.FIRST); if (member.equals(firstNode)) { nodes.put(member, name); recalculateClusterAddresses(nodes); log.info("Adding first node {}: {}; {} to cluster", new Object[] { this, member, name }); ((EntityInternal) member).setAttribute(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE); } else { int retry = 3; // TODO use a configurable Repeater instead? while (retry-- > 0 && member.getAttribute(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER) == null && !nodes.containsKey(member)) { Optional<Entity> anyNodeInCluster = Iterables.tryFind(nodes.keySet(), Predicates.and(Predicates.instanceOf(EtcdNode.class), EntityPredicates .attributeEqualTo(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE))); if (anyNodeInCluster.isPresent()) { DynamicTasks .queueIfPossible(DependentConfiguration .attributeWhenReady(anyNodeInCluster.get(), Startable.SERVICE_UP)) .orSubmitAndBlock(this).andWaitForSuccess(); Entities.invokeEffectorWithArgs(this, anyNodeInCluster.get(), EtcdNode.JOIN_ETCD_CLUSTER, name, getNodeAddress(member)).blockUntilEnded(); nodes.put(member, name); recalculateClusterAddresses(nodes); log.info("Adding node {}: {}; {} to cluster", new Object[] { this, member, name }); ((EntityInternal) member).setAttribute(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE); } else { log.info("Waiting for first node in cluster {}", this); Time.sleep(Duration.seconds(15)); } } } } else { if (nodes != null && nodes.containsKey(member)) { Optional<Entity> anyNodeInCluster = Iterables.tryFind(nodes.keySet(), Predicates.and( Predicates.instanceOf(EtcdNode.class), EntityPredicates .attributeEqualTo(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.TRUE), Predicates.not(Predicates.equalTo(member)))); if (anyNodeInCluster.isPresent()) { Entities.invokeEffectorWithArgs(this, anyNodeInCluster.get(), EtcdNode.LEAVE_ETCD_CLUSTER, getNodeName(member)).blockUntilEnded(); } nodes.remove(member); recalculateClusterAddresses(nodes); log.info("Removing node {}: {}; {} from cluster", new Object[] { this, member, getNodeName(member) }); ((EntityInternal) member).setAttribute(EtcdNode.ETCD_NODE_HAS_JOINED_CLUSTER, Boolean.FALSE); } } ServiceNotUpLogic.updateNotUpIndicatorRequiringNonEmptyMap(this, ETCD_CLUSTER_NODES); log.debug("Done {} checkEntity {}", this, member); } }
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.policy.SequenceInteractionFeedBackBuilder.java
private void feedBackResizedElements(Collection<Figure> feedbacks) { for (ISequenceEvent movedElement : Iterables.filter(validator.getResizedStartMessages(), Predicates.not(Predicates.in(validator.getEventsInError())))) { addFeedBack(movedElement, ISE_FEEDBACK_COLOR, false, feedbacks, validator.getRangeFunction().apply(movedElement)); }/* ww w .j av a 2s. c om*/ for (ISequenceEvent movedElement : Iterables.filter(validator.getResizedEndMessages(), Predicates.not(Predicates.in(validator.getEventsInError())))) { Range feedbackRange = validator.getRangeFunction().apply(movedElement); Range expansionZone = validator.getExpansionZone(); if ((expansionZone != null && !expansionZone.isEmpty()) && feedbackRange.includes(expansionZone.getUpperBound())) { feedbackRange = new Range(feedbackRange.getLowerBound(), feedbackRange.getUpperBound() - expansionZone.width()); } addFeedBack(movedElement, ISE_FEEDBACK_COLOR, false, feedbacks, feedbackRange); } }
From source file:org.apache.aurora.scheduler.sla.MetricCalculator.java
@Timed("sla_stats_computation") @Override/*from w w w . j a v a2 s .c om*/ public void run() { FluentIterable<IScheduledTask> tasks = FluentIterable .from(Storage.Util.fetchTasks(storage, Query.unscoped())); List<IScheduledTask> prodTasks = tasks .filter(Predicates.compose(Predicates.and(ITaskConfig::isProduction, IS_SERVICE), Tasks::getConfig)) .toList(); List<IScheduledTask> nonProdTasks = tasks.filter(Predicates .compose(Predicates.and(Predicates.not(ITaskConfig::isProduction), IS_SERVICE), Tasks::getConfig)) .toList(); long nowMs = clock.nowMillis(); Range<Long> timeRange = Range.closedOpen(nowMs - settings.refreshRateMs, nowMs); runAlgorithms(prodTasks, settings.prodMetrics, timeRange, NAME_QUALIFIER_PROD); runAlgorithms(nonProdTasks, settings.nonProdMetrics, timeRange, NAME_QUALIFIER_NON_PROD); }
From source file:brooklyn.entity.basic.EntityPredicates.java
public static <T> Predicate<Entity> attributeNotEqualTo(final AttributeSensor<T> attribute, final T val) { return attributeSatisfies(attribute, Predicates.not(Predicates.equalTo(val))); }
From source file:brooklyn.entity.rebind.Dumpers.java
private static void deepVisitInternal(Object o, Predicate<Field> fieldPredicate, List<Object> visited, Deque<Object> refChain, Visitor visitor) throws IllegalArgumentException, IllegalAccessException { Class<?> clazz = (o != null) ? o.getClass() : null; refChain.addLast(o);/*from w w w. ja v a 2s . c o m*/ Iterable<Object> filteredRefChain = Iterables.filter(refChain, Predicates.not(Predicates.instanceOf(Dumpers.Entry.class))); try { if (o == null) { // no-op } else if (isClassUntraversable(clazz)) { visitor.visit(o, filteredRefChain); } else if (containsSame(visited, o)) { // no-op } else { visited.add(o); boolean subTreeComplete = visitor.visit(o, filteredRefChain); if (!subTreeComplete) { Map<String, Object> members = findMembers(o, fieldPredicate); for (Map.Entry<String, Object> entry : members.entrySet()) { deepVisitInternal(entry.getValue(), fieldPredicate, visited, refChain, visitor); } } } } finally { refChain.removeLast(); } }
From source file:org.carrot2.webapp.model.WebappConfig.java
@SuppressWarnings("unchecked") private static Map<String, List<AttributeDescriptor>> prepareSourceAttributeMetadata( ProcessingComponentSuite components) throws Exception { final List<DocumentSourceDescriptor> sources = components.getSources(); final Map<String, List<AttributeDescriptor>> sourceDescriptors = Maps.newLinkedHashMap(); for (DocumentSourceDescriptor documentSourceDescriptor : sources) { final BindableDescriptor bindableDescriptor = documentSourceDescriptor.getBindableDescriptor() .only(Input.class).only(new LevelsPredicate(AttributeLevel.BASIC, AttributeLevel.MEDIUM)) .only(Predicates.<AttributeDescriptor>and(Predicates.not(new InternalAttributePredicate()), new Predicate<AttributeDescriptor>() { /** Attribute types supported in advanced source options */ final Set<Class<?>> ALLOWED_PLAIN_TYPES = ImmutableSet.<Class<?>>of(Byte.class, Short.class, Integer.class, Long.class, Float.class, Double.class, Boolean.class, String.class, Character.class); private final Set<String> IGNORED = ImmutableSet.<String>of(AttributeNames.QUERY, AttributeNames.RESULTS); public boolean apply(AttributeDescriptor d) { return (d.type.isEnum() || ALLOWED_PLAIN_TYPES.contains(d.type)) && !IGNORED.contains(d.key); }//from w w w .j a va2s .c o m })); final List<AttributeDescriptor> descriptors = Lists .newArrayList(bindableDescriptor.attributeDescriptors.values()); Collections.sort(descriptors, new Comparator<AttributeDescriptor>() { public int compare(AttributeDescriptor d1, AttributeDescriptor d2) { return getOrder(d1) - getOrder(d2); } private int getOrder(AttributeDescriptor d) { if (d.type.isEnum()) { return 0; } else if (d.type.equals(Boolean.class)) { return 2; } else { return 1; } } }); sourceDescriptors.put(documentSourceDescriptor.getId(), descriptors); } return sourceDescriptors; }
From source file:com.google.devtools.build.android.dexer.DexFileMerger.java
private static void processClassAndDexFiles(ZipFile zip, DexFileAggregator out, MergingDexer dexer, Predicate<ZipEntry> extraFilter) throws IOException { @SuppressWarnings("unchecked") // Predicates.and uses varargs parameter with generics ArrayList<? extends ZipEntry> filesToProcess = Lists .newArrayList(Iterators.filter(Iterators.forEnumeration(zip.entries()), Predicates.and(Predicates.not(ZipEntryPredicates.isDirectory()), ZipEntryPredicates.suffixes(".class", ".dex"), extraFilter))); Collections.sort(filesToProcess, ZipEntryComparator.LIKE_DX); for (ZipEntry entry : filesToProcess) { String filename = entry.getName(); try (InputStream content = zip.getInputStream(entry)) { if (filename.endsWith(".dex")) { // We don't want to use the Dex(InputStream) constructor because it closes the stream, // which will break the for loop, and it has its own bespoke way of reading the file into // a byte buffer before effectively calling Dex(byte[]) anyway. out.add(new Dex(ByteStreams.toByteArray(content))); } else if (filename.endsWith(".class")) { dexer.add(Dexing.parseClassFile(ByteStreams.toByteArray(content), filename)); } else { throw new IllegalStateException("Shouldn't get here: " + filename); }//from w ww . j av a2 s.c o m } } }
From source file:org.eclipse.sirius.business.internal.session.IsModifiedSavingPolicy.java
/** * Computes the set of resources to save. This is a safe approximation of * the exact sub-set of resource in the scope whose serialization has * changed. Saving all the returned resources will produce the same result * as saving all the resources in the scope, but in the general case will * save much less resources (and thus be faster). * <p>// w ww .j a va2 s .com * It may save more resources than strictly needed. For example if resource * A (not modified) contains references to elements in resource B * (modified), but the only references are to elements in B whose URI will * not change. In such a case we will save A anyway. More precise analyses * would be possible but cost-prohibitive. * <p> * {@inheritDoc} */ @Override public Collection<Resource> computeResourcesToSave(Set<Resource> scope, Map<?, ?> options, IProgressMonitor monitor) { final Map<Object, Object> mergedOptions = new HashMap<Object, Object>(getDefaultSaveOptions()); if (options != null) { mergedOptions.putAll(options); } Set<Resource> saveable = Sets.newLinkedHashSet(Iterables.filter(scope, new Predicate<Resource>() { @Override public boolean apply(Resource resourcetoSave) { return !ResourceSetSync.isReadOnly(resourcetoSave) && !SiriusUtil.isModelerDescriptionFile(resourcetoSave); } })); /* We must save a resource if is has been logically modified ... */ Set<Resource> logicallyModified = Sets.newLinkedHashSet(Iterables.filter(saveable, isModified)); /* * ... or it references a resource which has been modified (in which * case the URIs to the referenced elements in these resource *may* * havechanged)... */ Set<Resource> dependOnLogicallyModified = Sets.newLinkedHashSet(); if (logicallyModified.size() > 0) { Iterables.addAll(dependOnLogicallyModified, Iterables .filter(Sets.difference(saveable, logicallyModified), new ResourceHasReferenceTo(isModified))); } Predicate<Resource> exists = new Predicate<Resource>() { private URIConverter defaultConverter; @Override public boolean apply(Resource resourcetoSave) { ResourceSet rs = resourcetoSave.getResourceSet(); URIConverter uriConverter = rs == null ? getDefaultURIConverter() : rs.getURIConverter(); return uriConverter.exists(resourcetoSave.getURI(), mergedOptions); } private URIConverter getDefaultURIConverter() { if (defaultConverter == null) { defaultConverter = new ResourceSetImpl().getURIConverter(); } return defaultConverter; } }; Set<Resource> underlyingFileDoesNotExist = Sets .newLinkedHashSet(Iterables.filter(saveable, Predicates.not(exists))); Set<Resource> isConflictingOrDeleted = Sets .newLinkedHashSet(Iterables.filter(saveable, underlyingFileIsDeletedOrConflicting)); /* * or the underlying file is out of date and must be recreated/updated * to match the version in memory. */ Set<Resource> toSave = Sets.newLinkedHashSet(); for (Resource resource : Sets.union(logicallyModified, dependOnLogicallyModified)) { if (hasDifferentSerialization(resource, mergedOptions)) { toSave.add(resource); } else { ResourceMigrationMarker.clearMigrationMarker(resource); } } Iterables.addAll(toSave, Sets.union(underlyingFileDoesNotExist, isConflictingOrDeleted)); /* * if we have something to save which has no different serialization * then something is fishy... */ return toSave; }
From source file:com.sri.ai.grinder.sgdpllt.library.CommutativeAssociative.java
/** * Similar to {@link Expressions#apply(Object, Object...)}, * but makes a simplified function application of an associative commutative operator, * that is, its application but for the cases in which there are no arguments, or a single argument. * When there are no arguments, a given neutral element value is returned. * When a single argument is provided, it is returned itself. * @param isIdempotent TODO//ww w . ja va 2 s .c o m */ public static Expression make(Object functor, List<Expression> arguments, Expression neutralElement, boolean isIdempotent) { Predicate<Expression> notEqualToNeutralElement = Predicates.not(new Equals<Expression>(neutralElement)); arguments = Util.collectToList(arguments, notEqualToNeutralElement); if (isIdempotent) { Set<Expression> argumentsSet = new LinkedHashSet<Expression>(arguments); arguments = new ArrayList<Expression>(argumentsSet); } if (arguments.isEmpty()) { return Expressions.wrap(neutralElement); } if (arguments.size() == 1) { return arguments.get(0); } Expression result = Expressions.makeExpressionOnSyntaxTreeWithLabelAndSubTrees(Expressions.wrap(functor), arguments); result = Associative.associateWhenSureOperatorIsAssociative(result); return result; }