List of usage examples for com.google.common.base Predicates in
public static <T> Predicate<T> in(Collection<? extends T> target)
From source file:pkmntv.logic.TypeEffect.java
public static Map getResistantEffectMap() { return Maps.filterValues(TYPE_MAP, Predicates.in(RESISTANCE_FACTORS)); }
From source file:org.jclouds.util.Multimaps2.java
public static <K, V> Multimap<K, V> withoutKeys(Multimap<K, V> fromMultimap, Set<K> keys) { return Multimaps.<K, V>filterKeys(fromMultimap, Predicates.not(Predicates.in(keys))); }
From source file:gov.nasa.jpf.constraints.util.ExpressionRestrictor.java
public Expression restrict(Expression e) { Expression result = e;// w w w.j av a 2 s. c o m try { result = ExpressionUtil.restrict(result, Predicates.in(variables)); } catch (MixedParamsException ex) { mixedParams = true; } return result; }
From source file:org.jclouds.openstack.nova.v2_0.predicates.SecurityGroupPredicates.java
/** * matches name of the given security group against a list * * @param names//from w ww. j a v a2 s . co m * @return predicate that matches one of the names */ public static Predicate<SecurityGroup> nameIn(final Set<String> names) { checkNotNull(names, "names must be defined"); return new Predicate<SecurityGroup>() { @Override public boolean apply(SecurityGroup ext) { return Predicates.in(names).apply(ext.getName()); } @Override public String toString() { return "nameIn(" + names + ")"; } }; }
From source file:co.cask.cdap.common.lang.ProgramClassLoader.java
/** * Constructs an instance that load classes from the given directory for the given program type. * <p/>//from w w w . j a va 2 s . c o m * The URLs for class loading are: * <p/> * <pre> * [dir] * [dir]/*.jar * [dir]/lib/*.jar * </pre> */ public static ProgramClassLoader create(File unpackedJarDir, ClassLoader parentClassLoader, @Nullable ProgramType programType) throws IOException { Set<String> visibleResources = ProgramResources.getVisibleResources(programType); ImmutableSet.Builder<String> visiblePackages = ImmutableSet.builder(); for (String resource : visibleResources) { if (resource.endsWith(".class")) { int idx = resource.lastIndexOf('/'); // Ignore empty package if (idx > 0) { visiblePackages.add(resource.substring(0, idx)); } } } ClassLoader filteredParent = new FilterClassLoader(Predicates.in(visibleResources), Predicates.in(visiblePackages.build()), parentClassLoader); return new ProgramClassLoader(unpackedJarDir, filteredParent); }
From source file:co.cask.tigon.lang.ClassLoaders.java
public static ProgramClassLoader newProgramClassLoader(File unpackedJarDir, Iterable<String> apiResourceList) throws IOException { Predicate<String> predicate = Predicates.in(Sets.newHashSet(apiResourceList)); ClassLoader filterParent = Objects.firstNonNull(Thread.currentThread().getContextClassLoader(), ClassLoaders.class.getClassLoader()); return new ProgramClassLoader(unpackedJarDir, new FilterClassLoader(predicate, filterParent)); }
From source file:com.facebook.buck.apple.FatBinaryInfos.java
/** * Inspect the given build target and return information about it if its a fat binary. * * @return non-empty when the target represents a fat binary. * @throws com.facebook.buck.util.HumanReadableException * when the target is a fat binary but has incompatible flavors. *///from ww w .j a v a 2 s . c o m public static Optional<FatBinaryInfo> create( final Map<Flavor, AppleCxxPlatform> platformFlavorsToAppleCxxPlatforms, BuildTarget target) { ImmutableList<ImmutableSortedSet<Flavor>> thinFlavorSets = generateThinFlavors( platformFlavorsToAppleCxxPlatforms.keySet(), target.getFlavors()); if (thinFlavorSets.size() <= 1) { // Actually a thin binary return Optional.absent(); } if (!Sets.intersection(target.getFlavors(), FORBIDDEN_BUILD_ACTIONS).isEmpty()) { throw new HumanReadableException("%s: Fat binaries is only supported when building an actual binary.", target); } Predicate<Flavor> isPlatformFlavor = Predicates.in(platformFlavorsToAppleCxxPlatforms.keySet()); AppleCxxPlatform representativePlatform = null; AppleSdk sdk = null; for (SortedSet<Flavor> flavorSet : thinFlavorSets) { AppleCxxPlatform platform = Preconditions.checkNotNull( platformFlavorsToAppleCxxPlatforms.get(Iterables.find(flavorSet, isPlatformFlavor))); if (sdk == null) { sdk = platform.getAppleSdk(); representativePlatform = platform; } else if (sdk != platform.getAppleSdk()) { throw new HumanReadableException( "%s: Fat binaries can only be generated from binaries compiled for the same SDK.", target); } } FatBinaryInfo.Builder builder = FatBinaryInfo.builder().setFatTarget(target) .setRepresentativePlatform(Preconditions.checkNotNull(representativePlatform)); BuildTarget platformFreeTarget = target.withoutFlavors(platformFlavorsToAppleCxxPlatforms.keySet()); for (SortedSet<Flavor> flavorSet : thinFlavorSets) { builder.addThinTargets(platformFreeTarget.withFlavors(flavorSet)); } return Optional.of(builder.build()); }
From source file:com.eucalyptus.tokens.ws.TokensRequestLoggingFilter.java
@Override public Collection<String> apply(final Collection<String> parametersOrBody) { if (Iterables.tryFind(ACTION_NVPS, Predicates.in(parametersOrBody)).isPresent()) { return parametersOrBody.stream() .map(parameterAndValue -> parameterAndValue.startsWith(WEB_ID_TOKEN_PARAMETER) ? WEB_ID_TOKEN_PARAMETER_REDACTED : parameterAndValue) .collect(Collectors.toList()); }//from w w w . ja v a 2 s .c o m return parametersOrBody; }
From source file:eu.lp0.cursus.scoring.scores.impl.GenericOverallPointsData.java
@Override protected int calculateOverallPoints(Pilot pilot) { int points = 0; // Add race points but not discards for (Entry<Race, Integer> racePoints : Maps.filterKeys(scores.getRacePoints(pilot), Predicates.not(Predicates.in(scores.getDiscardedRaces(pilot)))).entrySet()) { points += racePoints.getValue(); }/*w ww .j a v a 2 s. c o m*/ // Add all penalties (this includes race penalties) points += scores.getOverallPenalties(pilot); if (points < 0) { points = 0; } return points; }
From source file:co.cask.cdap.internal.app.runtime.plugin.PluginClassLoader.java
static ClassLoader createParent(ClassLoader templateClassLoader) { // Find the ProgramClassLoader from the template ClassLoader ClassLoader programClassLoader = templateClassLoader; while (programClassLoader != null && !(programClassLoader instanceof ProgramClassLoader)) { programClassLoader = programClassLoader.getParent(); }/*from w w w . jav a2s . c o m*/ // This shouldn't happen Preconditions.checkArgument(programClassLoader != null, "Cannot find ProgramClassLoader"); // Package filtered classloader of the template classloader, which only classes in "Export-Packages" are loadable. Manifest manifest = ((ProgramClassLoader) programClassLoader).getManifest(); Set<String> exportPackages = ManifestFields.getExportPackages(manifest); ClassLoader filteredTemplateClassLoader = new PackageFilterClassLoader(templateClassLoader, Predicates.in(exportPackages)); // The lib Classloader needs to be able to see all cdap api classes as well. // In this way, parent ClassLoader of the plugin ClassLoader will load class from the parent of the // template program class loader (which is a filtered CDAP classloader), // followed by template export-packages, then by a plugin lib jars. return new CombineClassLoader(programClassLoader.getParent(), ImmutableList.of(filteredTemplateClassLoader)); }