List of usage examples for com.google.common.collect Iterables any
public static <T> boolean any(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.eclipse.sirius.diagram.sequence.business.internal.layout.vertical.SequenceVerticalLayout.java
private int getGapBeforeOperandEnd(EventEnd endBefore, EventEnd end, int currentLocation, int genericGap, Map<EventEnd, Integer> alreadyComputedLocations) { int beforeGap = genericGap; Iterable<Operand> operands = Iterables.filter(eventEndToSequenceEvents.apply(end), Operand.class); if (!Iterables.isEmpty(operands) && endBefore instanceof SingleEventEnd) { if (Iterables.any(eventEndToSequenceEvents.apply(endBefore), Predicates.instanceOf(CombinedFragment.class)) && ((SingleEventEnd) endBefore).isStart()) { beforeGap = LayoutConstants.COMBINED_FRAGMENT_TITLE_HEIGHT; } else {/*from w ww .j av a 2s . c o m*/ Operand op = selectEndedOperand(end, operands); if (op != null) { int startLoc = getStartLocation(op, alreadyComputedLocations); int minEndLoc = startLoc + LayoutConstants.DEFAULT_OPERAND_HEIGHT; beforeGap = Math.max(minEndLoc - currentLocation, genericGap); } } } return beforeGap; }
From source file:com.google.devtools.j2cpp.translate.DeadCodeEliminator.java
/** * Determines whether a type is visible in the scope of the specified context. */// w w w. ja v a 2s . co m private boolean inScope(ITypeBinding type, ITypeBinding context) { return context.equals(type) || context.getSuperclass() != null && inScope(type, context.getSuperclass()) || Iterables.any(Arrays.asList(context.getDeclaredTypes()), Predicates.equalTo(type)); }
From source file:gov.nih.nci.caarray.domain.project.Experiment.java
/** * @return whether this experiment has any imported and parsed array designs *///from www.j a v a2 s.c om public boolean hasParsedArrayDesigns() { return Iterables.any(getArrayDesigns(), new Predicate<ArrayDesign>() { public boolean apply(ArrayDesign design) { return design.isImportedAndParsed(); } }); }
From source file:org.killbill.billing.subscription.api.user.DefaultSubscriptionBase.java
private void filterOutDuplicateCancelEvents(final List<SubscriptionBaseEvent> inputEvents) { Collections.sort(inputEvents, new Comparator<SubscriptionBaseEvent>() { @Override//www.jav a 2s . c om public int compare(final SubscriptionBaseEvent o1, final SubscriptionBaseEvent o2) { int res = o1.getEffectiveDate().compareTo(o2.getEffectiveDate()); if (res == 0) { res = o1.getTotalOrdering() < (o2.getTotalOrdering()) ? -1 : 1; } return res; } }); final boolean isCancelled = Iterables.any(inputEvents, new Predicate<SubscriptionBaseEvent>() { @Override public boolean apply(final SubscriptionBaseEvent input) { if (input.isActive() && input.getType() == EventType.API_USER) { final ApiEvent userEV = (ApiEvent) input; if (userEV.getApiEventType() == ApiEventType.CANCEL && userEV.isFromDisk()) { return true; } } return false; } }); if (!isCancelled) { return; } boolean foundFirstOnDiskCancel = false; final Iterator<SubscriptionBaseEvent> it = inputEvents.iterator(); while (it.hasNext()) { final SubscriptionBaseEvent input = it.next(); if (!input.isActive()) { continue; } if (input.getType() == EventType.API_USER) { final ApiEvent userEV = (ApiEvent) input; if (userEV.getApiEventType() == ApiEventType.CANCEL) { if (userEV.isFromDisk()) { if (!foundFirstOnDiskCancel) { foundFirstOnDiskCancel = true; } else { it.remove(); } } else { it.remove(); } } } } }
From source file:com.eucalyptus.autoscaling.activities.ActivityManager.java
private ScalingProcessTask<?, ?> perhapsTerminateInstances(final AutoScalingGroupScalingView group, final int terminateCount) { final List<String> instancesToTerminate = Lists.newArrayList(); boolean anyRegisteredInstances = false; int currentCapacity = 0; try {/* w ww . j a v a2 s . co m*/ final List<AutoScalingInstanceCoreView> currentInstances = autoScalingInstances.listByGroup(group, Predicates.alwaysTrue(), TypeMappers.lookup(AutoScalingInstance.class, AutoScalingInstanceCoreView.class)); currentCapacity = currentInstances.size(); if (currentInstances.size() == terminateCount) { Iterables.addAll(instancesToTerminate, Iterables.transform(currentInstances, RestrictedTypes.toDisplayName())); anyRegisteredInstances = Iterables.any(currentInstances, ConfigurationState.Registered.forView()); } else { // First terminate instances in zones that are no longer in use final Set<String> groupZones = Sets.newLinkedHashSet(group.getAvailabilityZones()); groupZones.removeAll( zoneMonitor.getUnavailableZones(AutoScalingConfiguration.getZoneFailureThresholdMillis())); final Set<String> unwantedZones = Sets .newHashSet(Iterables.transform(currentInstances, availabilityZone())); unwantedZones.removeAll(groupZones); final Set<String> targetZones; final List<AutoScalingInstanceCoreView> remainingInstances = Lists.newArrayList(currentInstances); if (!unwantedZones.isEmpty()) { int unwantedInstanceCount = CollectionUtils.reduce(currentInstances, 0, CollectionUtils.count(withAvailabilityZone(unwantedZones))); if (unwantedInstanceCount < terminateCount) { Iterable<AutoScalingInstanceCoreView> unwantedInstances = Iterables.filter(currentInstances, withAvailabilityZone(unwantedZones)); Iterables.addAll(instancesToTerminate, Iterables.transform(unwantedInstances, RestrictedTypes.toDisplayName())); Iterables.removeAll(remainingInstances, Lists.newArrayList(unwantedInstances)); anyRegisteredInstances = Iterables.any(unwantedInstances, ConfigurationState.Registered.forView()); targetZones = groupZones; } else { targetZones = unwantedZones; } } else { targetZones = groupZones; } final Map<String, Integer> zoneCounts = buildAvailabilityZoneInstanceCounts(currentInstances, targetZones); for (int i = instancesToTerminate.size(); i < terminateCount && remainingInstances.size() >= 1; i++) { final Map.Entry<String, Integer> entry = selectEntry(zoneCounts, Ordering.natural().reverse()); final AutoScalingInstanceCoreView instanceForTermination = TerminationPolicyType .selectForTermination(group.getTerminationPolicies(), Lists.newArrayList( Iterables.filter(remainingInstances, withAvailabilityZone(entry.getKey())))); remainingInstances.remove(instanceForTermination); entry.setValue(entry.getValue() - 1); instancesToTerminate.add(instanceForTermination.getInstanceId()); anyRegisteredInstances |= ConfigurationState.Registered.forView().apply(instanceForTermination); } } } catch (final Exception e) { logger.error(e, e); } final List<ActivityCause> causes = Lists.newArrayList(); causes.add(new ActivityCause(String.format( "an instance was taken out of service in response to a difference between desired and actual capacity, shrinking the capacity from %1$d to %2$d", group.getCapacity(), group.getCapacity() - instancesToTerminate.size()))); for (final String instanceId : instancesToTerminate) { causes.add(new ActivityCause(String.format("instance %1$s was selected for termination", instanceId))); } return removeFromLoadBalancerOrTerminate(group, currentCapacity, anyRegisteredInstances, instancesToTerminate, causes, false); }
From source file:org.yakindu.sct.model.stext.validation.STextJavaValidator.java
@Check(CheckType.FAST) public void checkAnnotationTarget(final AnnotatableElement element) { EList<Annotation> annotations = element.getAnnotations(); for (Annotation annotation : annotations) { EList<EObject> targets = annotation.getTargets(); boolean found = Iterables.any(targets, new Predicate<EObject>() { @Override// w ww . j a v a2s . c om public boolean apply(EObject input) { return ((EClass) input).isInstance(element); } }); if (!found) { error(String.format(ERROR_WRONG_ANNOTATION_TARGET_MSG, annotation.getName(), element.eClass()), TypesPackage.Literals.ANNOTATABLE_ELEMENT__ANNOTATIONS, element.getAnnotations().indexOf(annotation), ERROR_WRONG_ANNOTATION_TARGET_CODE); } } }
From source file:com.eucalyptus.compute.common.internal.tags.FilterSupport.java
/** * Construct a predicate from a filter pattern. * * A Pattern is constructed from the given filter, as per AWS: * * Filters support the following wildcards: * * *: Matches zero or more characters * ?: Matches exactly one character//from w ww .j a v a 2 s . c om * * Your search can include the literal values of the wildcard characters; you just need to escape * them with a backslash before the character. For example, a value of \*amazon\?\\ searches for * the literal string *amazon?\. * * Wildcards are translated to regular expression wildcards: * * .*: Matches zero or more characters * . : Matches exactly one character * * Any other regular expression syntax from the filter value is escaped (Pattern.quote) */ private static Predicate<Set<String>> resourceValueMatcher(final String filterPattern) { final StringBuilder regexBuilder = new StringBuilder(); if (translateWildcards(filterPattern, regexBuilder, ".", ".*", SyntaxEscape.Regex)) { return new Predicate<Set<String>>() { private final Pattern pattern = Pattern.compile(regexBuilder.toString()); @Override public boolean apply(final Set<String> values) { return Iterables.any(values, new Predicate<String>() { @Override public boolean apply(final String value) { return value != null && pattern.matcher(value).matches(); } }); } }; } // even if no regex, may contain \ escapes that must be removed final String processedFilterPattern = filterPattern.replaceAll("\\\\", Matcher.quoteReplacement("\\")); return new Predicate<Set<String>>() { @Override public boolean apply(final Set<String> values) { return values.contains(processedFilterPattern); } }; }
From source file:com.eucalyptus.autoscaling.activities.ActivityManager.java
private ScalingProcessTask<?, ?> perhapsReplaceInstances(final AutoScalingGroupScalingView group) { final List<String> instancesToTerminate = Lists.newArrayList(); boolean anyRegisteredInstances = false; if (scalingProcessEnabled(ScalingProcessType.ReplaceUnhealthy, group)) try {/* w ww .j ava 2 s . co m*/ final List<AutoScalingInstanceCoreView> currentInstances = autoScalingInstances .listUnhealthyByGroup(group, TypeMappers.lookup(AutoScalingInstance.class, AutoScalingInstanceCoreView.class)); Iterables.addAll(instancesToTerminate, Iterables.limit( Iterables.transform(currentInstances, RestrictedTypes.toDisplayName()), Math.min(AutoScalingConfiguration.getMaxLaunchIncrement(), currentInstances.size()))); anyRegisteredInstances = Iterables.any(currentInstances, ConfigurationState.Registered.forView()); if (!instancesToTerminate.isEmpty()) { logger.info("Terminating unhealthy instances: " + instancesToTerminate); } } catch (final Exception e) { logger.error(e, e); } return removeFromLoadBalancerOrTerminate(group, group.getCapacity(), anyRegisteredInstances, instancesToTerminate, Collections.singletonList( new ActivityCause("an instance was taken out of service in response to a health-check")), true); }
From source file:io.druid.segment.realtime.plumber.RealtimePlumber.java
private void registerServerViewCallback() { serverView.registerSegmentCallback(mergeExecutor, new ServerView.BaseSegmentCallback() { @Override/*from w ww . j a v a 2s .c om*/ public ServerView.CallbackAction segmentAdded(DruidServerMetadata server, DataSegment segment) { if (stopped) { log.info("Unregistering ServerViewCallback"); mergeExecutor.shutdown(); return ServerView.CallbackAction.UNREGISTER; } if (!server.isAssignable()) { return ServerView.CallbackAction.CONTINUE; } log.debug("Checking segment[%s] on server[%s]", segment, server); if (schema.getDataSource().equals(segment.getDataSource()) && config.getShardSpec().getPartitionNum() == segment.getShardSpec().getPartitionNum()) { final Interval interval = segment.getInterval(); for (Map.Entry<Long, Sink> entry : sinks.entrySet()) { final Long sinkKey = entry.getKey(); if (interval.contains(sinkKey)) { final Sink sink = entry.getValue(); log.info("Segment[%s] matches sink[%s] on server[%s]", segment, sink, server); final String segmentVersion = segment.getVersion(); final String sinkVersion = sink.getSegment().getVersion(); if (segmentVersion.compareTo(sinkVersion) >= 0) { log.info("Segment version[%s] >= sink version[%s]", segmentVersion, sinkVersion); abandonSegment(sinkKey, sink); } } } } return ServerView.CallbackAction.CONTINUE; } }, new Predicate<DataSegment>() { @Override public boolean apply(final DataSegment segment) { return schema.getDataSource().equalsIgnoreCase(segment.getDataSource()) && config.getShardSpec().getPartitionNum() == segment.getShardSpec().getPartitionNum() && Iterables.any(sinks.keySet(), new Predicate<Long>() { @Override public boolean apply(Long sinkKey) { return segment.getInterval().contains(sinkKey); } }); } }); }
From source file:io.prestosql.metadata.FunctionRegistry.java
public boolean isAggregationFunction(QualifiedName name) { return Iterables.any(functions.get(name), function -> function.getSignature().getKind() == AGGREGATE); }