List of usage examples for com.google.common.base Predicates in
public static <T> Predicate<T> in(Collection<? extends T> target)
From source file:com.google.caliper.runner.Instrument.java
@Inject void setOptions(@InstrumentOptions ImmutableMap<String, String> options) { this.options = ImmutableMap.copyOf(Maps.filterKeys(options, Predicates.in(instrumentOptions()))); }
From source file:net.automatalib.util.graphs.ShortestPaths.java
public static <N, E> Iterable<Path<N, E>> shortestPaths(IndefiniteGraph<N, E> graph, N start, int limit, Collection<?> targets) { return shortestPaths(graph, start, limit, Predicates.in(targets)); }
From source file:org.jclouds.ec2.suppliers.DescribeRegionsForConfiguredRegions.java
@Singleton @Region/*from ww w . j a v a2s.c om*/ @Override public Map<String, Supplier<URI>> get() { Set<String> regionWhiteList = regions.get(); Map<String, URI> regionToUris = client.describeRegions(); if (regionWhiteList.size() > 0) regionToUris = Maps.filterKeys(regionToUris, Predicates.in(regionWhiteList)); return Maps.transformValues(regionToUris, Suppliers2.<URI>ofInstanceFunction()); }
From source file:org.jclouds.atmos.functions.ParseUserMetadataFromHeaders.java
public UserMetadata apply(HttpResponse from) { checkNotNull(from, "http response"); Map<String, String> meta = Maps.filterKeys( getMetaMap(checkNotNull(from.getFirstHeaderOrNull(AtmosHeaders.META), AtmosHeaders.META)), Predicates.not(Predicates.in(SYS_KEYS))); Map<String, String> listableMeta = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META) != null) ? getMetaMap(from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_META)) : ImmutableMap.<String, String>of(); Iterable<String> tags = (from.getFirstHeaderOrNull(AtmosHeaders.TAGS) != null) ? Splitter.on(", ").split(from.getFirstHeaderOrNull(AtmosHeaders.TAGS)) : ImmutableSet.<String>of(); Iterable<String> listableTags = (from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS) != null) ? Splitter.on(", ").split(from.getFirstHeaderOrNull(AtmosHeaders.LISTABLE_TAGS)) : ImmutableSet.<String>of(); return new UserMetadata(meta, listableMeta, tags, listableTags); }
From source file:net.automatalib.util.automata.transout.MealyFilter.java
/** * Returns a Mealy machine with all transitions removed that have one of the specified output values. The resulting * Mealy machine will not contain any unreachable states. * /*w w w. j a v a 2s .co m*/ * @param in the input Mealy machine * @param inputs the input alphabet * @param outputs the outputs to remove * @return a Mealy machine with all transitions removed that have one of the specified outputs. */ public static <I, O> CompactMealy<I, O> pruneTransitionsWithOutput(MealyMachine<?, I, ?, O> in, Alphabet<I> inputs, Collection<? super O> outputs) { return filterByOutput(in, inputs, Predicates.not(Predicates.in(outputs))); }
From source file:eu.lp0.cursus.xml.data.entity.DataXMLRace.java
public DataXMLRace(Race race, Set<Pilot> pilots) { super(race);/*from w w w. jav a 2 s .c o m*/ name = race.getName(); description = race.getDescription(); if (!race.getAttendees().isEmpty()) { attendees = new ArrayList<DataXMLRaceAttendee>(race.getAttendees().size()); for (RaceAttendee attendee : Maps.filterKeys(race.getAttendees(), Predicates.in(pilots)).values()) { attendees.add(new DataXMLRaceAttendee(attendee)); } } Collections.sort(attendees); }
From source file:org.apache.james.mpt.api.ImapFeatures.java
public boolean supports(Feature... features) { Preconditions.checkNotNull(features); ImmutableSet<Feature> requestedFeatures = ImmutableSet.copyOf(features); return FluentIterable.from(requestedFeatures).allMatch(Predicates.in(supportedFeatures)); }
From source file:com.google.caliper.runner.instrument.Instrument.java
@VisibleForTesting @Inject/* ww w . ja v a 2 s. c om*/ public void setOptions(@InstrumentOptions ImmutableMap<String, String> options) { this.options = ImmutableMap.copyOf(Maps.filterKeys(options, Predicates.in(instrumentOptions()))); }
From source file:com.ning.atlas.components.aws.RDSProvisioner.java
@Override public String perform(Host node, Uri<? extends Component> uri, Deployment d) throws Exception { AtlasConfiguration config = AtlasConfiguration.global(); Credentials creds = new AWS.Credentials(); creds.setAccessKey(config.lookup("aws.key").get()); creds.setSecretKey(config.lookup("aws.secret").get()); final RDSApi rdsApi = AWS.rdsApi(creds); Maybe<String> existing_id = d.getSpace().get(node.getId(), "instance-id"); if (existing_id.isKnown()) { Instance instance = rdsApi.getInstanceApi().get(existing_id.getValue()); if (instance != null && !Predicates.in(ImmutableSet.of(Instance.Status.DELETING, Instance.Status.FAILED)) .apply(instance.getStatus())) return "already exists"; }//from ww w .j a va 2 s.c om log.info("Started provisioning %s, this could take a while", node.getId().toExternalForm()); RDSConfig cfg = new ConfigurationObjectFactory(new MapConfigSource(uri.getParams())).build(RDSConfig.class); String name = "db-" + UUID.randomUUID().toString(); InstanceRequest.Builder<?> requestBuilder = InstanceRequest.builder().instanceClass(cfg.getInstanceClass()) .allocatedStorageGB(cfg.getStorageSize()).engine(cfg.getEngine()).masterUsername(cfg.getUsername()) .masterPassword(cfg.getPassword()); String license_model = uri.getParams().containsKey("license_model") ? uri.getParams().get("license_model") : "general-public-license"; requestBuilder.licenseModel(license_model); Maybe<String> db_name = Maybe.elideNull(uri.getParams().get("name")); if (db_name.isKnown()) { requestBuilder.name(db_name.getValue()); } Maybe<String> sec_group = Maybe.elideNull(uri.getParams().get("security_group")); if (sec_group.isKnown()) { AWS.waitForRDSSecurityGroup(sec_group.getValue(), d.getSpace(), 1, TimeUnit.MINUTES); requestBuilder.securityGroup(sec_group.getValue()); } Instance newInstance = rdsApi.getInstanceApi().create(name, requestBuilder.build()); RetryablePredicate<Instance> instanceAvailable = new RetryablePredicate<Instance>( new Predicate<Instance>() { @Override public boolean apply(Instance input) { Instance refreshed = rdsApi.getInstanceApi().get(input.getId()); return refreshed.getStatus() == Instance.Status.AVAILABLE && refreshed.getEndpoint().isPresent(); } }, 600, 1, 1, TimeUnit.SECONDS); if (!instanceAvailable.apply(newInstance)) throw new IllegalStateException("instance never hit state AVAILABLE!: " + newInstance); Instance instance = rdsApi.getInstanceApi().get(newInstance.getId()); Database database = new Database(); database.setHost(instance.getEndpoint().get().getHostText()); database.setPort(instance.getEndpoint().get().getPort()); database.setPassword(cfg.getPassword()); database.setUsername(cfg.getUsername()); database.setName(instance.getName().or("")); d.getSpace().store(node.getId(), database); Map<String, String> attrs = Maps.newHashMap(); attrs.put("port", instance.getEndpoint().get().getPort() + ""); attrs.put("instanceId", instance.getId()); attrs.put("instanceClass", instance.getInstanceClass()); attrs.put("name", instance.getName().or("")); attrs.put("engine", instance.getEngine()); attrs.put("engineVersion", instance.getEngineVersion()); attrs.put("password", cfg.getPassword()); attrs.put("username", cfg.getUsername()); attrs.put("storageSize", String.valueOf(cfg.getStorageSize())); attrs.put("host", instance.getEndpoint().get().getHostText()); log.info("Finished provisioning %s", node.getId().toExternalForm()); // TODO save to space somehow d.getSpace().store(node.getId(), new Server(instance.getEndpoint().get().getHostText())); d.getSpace().store(node.getId(), "instance-id", instance.getId()); d.getSpace().store(node.getId(), "extra-atlas-attributes", new ObjectMapper().writeValueAsString(attrs)); return "cool beans"; }
From source file:gov.nasa.jpf.constraints.util.ExpressionRestrictionVisitor.java
@Override public Expression<?> visit(QuantifierExpression q, Predicate<? super Variable<?>> data) { Predicate<Variable<?>> newPred = Predicates.or(Predicates.in(q.getBoundVariables()), data); Expression<?> exp = visit(q.getBody(), newPred); return (exp != null) ? q.duplicate(new Expression[] { exp }) : null; }