List of usage examples for com.google.common.base Predicates in
public static <T> Predicate<T> in(Collection<? extends T> target)
From source file:eu.lp0.cursus.xml.data.entity.DataXMLEvent.java
public DataXMLEvent(Event event, Set<Race> races, Set<Pilot> pilots) { super(event); name = event.getName();/* ww w . j av a 2 s . com*/ description = event.getDescription(); if (!event.getAttendees().isEmpty()) { attendees = new ArrayList<DataXMLEventAttendee>(event.getAttendees().size()); for (Pilot pilot : Sets.filter(event.getAttendees(), Predicates.in(pilots))) { attendees.add(new DataXMLEventAttendee(pilot)); } Collections.sort(attendees); } this.races = new ArrayList<DataXMLRace>(races.size()); for (Race race : races) { this.races.add(new DataXMLRace(race, pilots)); } }
From source file:com.google.devtools.build.lib.rules.config.ConfigFeatureFlag.java
@Override public ConfiguredTarget create(RuleContext ruleContext) throws InterruptedException, RuleErrorException { List<String> specifiedValues = ruleContext.attributes().get("allowed_values", STRING_LIST); ImmutableSet<String> values = ImmutableSet.copyOf(specifiedValues); Predicate<String> isValidValue = Predicates.in(values); if (values.size() != specifiedValues.size()) { ImmutableMultiset<String> groupedValues = ImmutableMultiset.copyOf(specifiedValues); ImmutableList.Builder<String> duplicates = new ImmutableList.Builder<String>(); for (Multiset.Entry<String> value : groupedValues.entrySet()) { if (value.getCount() > 1) { duplicates.add(value.getElement()); }/*from ww w .j a v a2s . c o m*/ } ruleContext.attributeError("allowed_values", "cannot contain duplicates, but contained multiple of " + Printer.repr(duplicates.build(), '\'')); } String defaultValue = ruleContext.attributes().get("default_value", STRING); if (!isValidValue.apply(defaultValue)) { ruleContext.attributeError("default_value", "must be one of " + Printer.repr(values.asList(), '\'') + ", but was " + Printer.repr(defaultValue, '\'')); } if (ruleContext.hasErrors()) { // Don't bother validating the value if the flag was already incorrectly specified without // looking at the value. return null; } String value = ruleContext.getFragment(ConfigFeatureFlagConfiguration.class) .getFeatureFlagValue(ruleContext.getOwner()).or(defaultValue); if (!isValidValue.apply(value)) { // TODO(mstaib): When configurationError is available, use that instead. ruleContext.ruleError("value must be one of " + Printer.repr(values.asList(), '\'') + ", but was " + Printer.repr(value, '\'')); return null; } ConfigFeatureFlagProvider provider = ConfigFeatureFlagProvider.create(value, isValidValue); return new RuleConfiguredTargetBuilder(ruleContext) .setFilesToBuild(NestedSetBuilder.<Artifact>emptySet(STABLE_ORDER)) .addProvider(RunfilesProvider.class, RunfilesProvider.EMPTY) .addProvider(ConfigFeatureFlagProvider.class, provider).addNativeDeclaredProvider(provider).build(); }
From source file:com.eucalyptus.config.ws.PropertiesRequestLoggingFilter.java
@Override public Collection<String> apply(final Collection<String> parametersOrBody) { if (Iterables.tryFind(ACTION_NVPS, Predicates.in(parametersOrBody)).isPresent()) { final Optional<String> nameParameterAndValue = Iterables.tryFind(parametersOrBody, Strings.startsWith(NAME_PARAMETER)); final Optional<String> valueParameterAndValue = Iterables.tryFind(parametersOrBody, Strings.startsWith(VALUE_PARAMETER)); if (nameParameterAndValue.isPresent() && valueParameterAndValue.isPresent()) try { final ConfigurableProperty entry = PropertyDirectory .getPropertyEntry(Strings.trimPrefix(NAME_PARAMETER, nameParameterAndValue.get())); if (ConfigurableFieldType.KEYVALUEHIDDEN == entry.getWidgetType()) { final ArrayList<String> parametersCopy = Lists.newArrayList(parametersOrBody); parametersCopy.set(parametersCopy.indexOf(valueParameterAndValue.get()), VALUE_PARAMETER_REDACTED); return parametersCopy; }/*from w w w.j a v a2s.c o m*/ } catch (IllegalAccessException e) { // property not found } } return parametersOrBody; }
From source file:com.twitter.aurora.scheduler.filter.AttributeFilter.java
/** * Tests whether an attribute matches a limit constraint. * * @param attributes Attributes to match against. * @param jobKey Key of the job with the limited constraint. * @param limit Limit value.//w ww . ja va 2s. com * @param activeTasks All active tasks in the system. * @param attributeFetcher Interface for fetching attributes for hosts in the system. * @return {@code true} if the limit constraint is satisfied, {@code false} otherwise. */ static boolean matches(final Set<Attribute> attributes, final IJobKey jobKey, int limit, Iterable<IScheduledTask> activeTasks, final AttributeLoader attributeFetcher) { Predicate<IScheduledTask> sameJob = Predicates.compose(Predicates.equalTo(jobKey), Tasks.SCHEDULED_TO_JOB_KEY); Predicate<IScheduledTask> hasAttribute = new Predicate<IScheduledTask>() { @Override public boolean apply(IScheduledTask task) { Iterable<Attribute> hostAttributes = attributeFetcher.apply(task.getAssignedTask().getSlaveHost()); return Iterables.any(hostAttributes, Predicates.in(attributes)); } }; return limit > Iterables.size(Iterables.filter(activeTasks, Predicates.and(sameJob, hasAttribute))); }
From source file:net.automatalib.util.graphs.ShortestPaths.java
public static <N, E> Iterable<Path<N, E>> shortestPaths(IndefiniteGraph<N, E> graph, Collection<? extends N> start, int limit, Collection<?> targets) { return shortestPaths(graph, start, limit, Predicates.in(targets)); }
From source file:org.eclipse.sirius.diagram.sequence.ui.tool.internal.edit.validator.InstanceRoleMoveValidator.java
/** * {@inheritDoc}/*from w ww . j a v a 2s.co m*/ */ @Override public boolean isValid(ChangeBoundsRequest request) { boolean valid = super.isValid(request); if (instanceRoles.size() != 0) { SequenceDiagram sequenceDiagram = instanceRoles.get(0).getDiagram(); List<InstanceRole> allInstanceRoles = sequenceDiagram.getSortedInstanceRole(); RequestQuery query = new RequestQuery(request); Point moveDelta = query.getLogicalDelta().getLocation(); Collections.sort(instanceRoles, comparator); // if move request is constrained then it's a explicit user move // request // otherwise it's a indirect request from ConnectionCreationTool for // a // Create Message for example if (!request.isConstrainedMove()) { moveDelta.y = 0; } Iterable<Rectangle> notMovedIRBounds = Iterables.transform( Iterables.filter(allInstanceRoles, Predicates.not(Predicates.in(instanceRoles))), ISequenceElement.PROPER_LOGICAL_BOUNDS); // Iterate on all instanceRoles to move from the request for (InstanceRole instanceRole : instanceRoles) { moveDeltas.put(instanceRole, moveDelta.getCopy()); Rectangle boundBeforeResizing = instanceRole.getBounds(); Rectangle boundAfterResizing = boundBeforeResizing.getTranslated(moveDelta); for (Rectangle notMovedBounds : notMovedIRBounds) { int nmbLeftX = notMovedBounds.getLeft().x; int nmbRightX = notMovedBounds.getRight().x; int mLeftX = boundAfterResizing.getLeft().x; boolean leftOverlapFixIR = nmbLeftX <= mLeftX && mLeftX <= nmbRightX; if (leftOverlapFixIR) { valid = false; break; } } } } return valid; }
From source file:com.google.devtools.build.lib.query2.engine.RdepsFunction.java
/** * Compute the transitive closure of the universe, then breadth-first search from the argument * towards the universe while staying within the transitive closure. *//* w ww . j a v a 2 s . c o m*/ @Override public <T> void eval(QueryEnvironment<T> env, VariableContext<T> context, QueryExpression expression, List<Argument> args, Callback<T> callback) throws QueryException, InterruptedException { Set<T> universeValue = QueryUtil.evalAll(env, context, args.get(0).getExpression()); env.buildTransitiveClosure(expression, universeValue, Integer.MAX_VALUE); Predicate<T> universe = Predicates.in(env.getTransitiveClosure(universeValue)); eval(env, context, args.subList(1, args.size()), callback, universe); }
From source file:com.eucalyptus.cloudformation.ws.CloudFormationRequestLoggingFilter.java
@Override public Collection<String> apply(final Collection<String> parametersOrBody) { if (Iterables.tryFind(ACTION_NVPS, Predicates.in(parametersOrBody)).isPresent()) { final Iterable<String> templateBodyNVPs = Iterables.filter(parametersOrBody, Predicates.contains(TEMPLATE_BODY_PARAMETER_REGEX)); final Iterable<String> parametersNVPs = Iterables.filter(parametersOrBody, Predicates.contains(PARAMETERS_PARAMETER_REGEX)); if (!Iterables.isEmpty(templateBodyNVPs) || !Iterables.isEmpty(parametersNVPs)) { final ArrayList<String> parametersCopy = Lists.newArrayList(parametersOrBody); redactParameters(parametersCopy, templateBodyNVPs, TEMPLATE_BODY_PARAMETER_REGEX); redactParameters(parametersCopy, parametersNVPs, PARAMETERS_PARAMETER_REGEX); return parametersCopy; }/*from w ww.j a v a 2 s . c o m*/ } return parametersOrBody; }
From source file:com.kurtraschke.wmata.gtfsrealtime.services.WMATARouteMapperService.java
@Inject public void setBadRoutes(@Named("WMATA.badRoutes") String badRoutesString) { _badRoutes = badRoutesString.split(","); _matchBadRoutes = Predicates.in(Arrays.asList(_badRoutes)); }
From source file:org.jclouds.vcloud.director.testng.FormatApiResultsListener.java
private boolean methodInApiGroup(ITestResult res) { return Iterables.any(Arrays.asList(res.getMethod().getGroups()), Predicates.in(apis)); }