List of usage examples for com.google.common.base Predicates and
public static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T> second)
From source file:com.cimr.boot.swagger.SwaggerAutoConfiguration.java
@Bean @ConditionalOnMissingBean/*from ww w .ja va 2s . com*/ @ConditionalOnBean(UiConfiguration.class) @ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true) public List<Docket> createRestApi(SwaggerProperties swaggerProperties) { ConfigurableBeanFactory configurableBeanFactory = (ConfigurableBeanFactory) beanFactory; List<Docket> docketList = new LinkedList<>(); // if (swaggerProperties.getDocket().size() == 0) { ApiInfo apiInfo = new ApiInfoBuilder().title(swaggerProperties.getTitle()) .description(swaggerProperties.getDescription()).version(swaggerProperties.getVersion()) .license(swaggerProperties.getLicense()).licenseUrl(swaggerProperties.getLicenseUrl()) .contact(new Contact(swaggerProperties.getContact().getName(), swaggerProperties.getContact().getUrl(), swaggerProperties.getContact().getEmail())) .termsOfServiceUrl(swaggerProperties.getTermsOfServiceUrl()).build(); // base-path? // ?path?/** if (swaggerProperties.getBasePath().isEmpty()) { swaggerProperties.getBasePath().add("/**"); } List<Predicate<String>> basePath = new ArrayList(); for (String path : swaggerProperties.getBasePath()) { basePath.add(PathSelectors.ant(path)); } // exclude-path? List<Predicate<String>> excludePath = new ArrayList(); for (String path : swaggerProperties.getExcludePath()) { excludePath.add(PathSelectors.ant(path)); } Docket docketForBuilder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost()) .apiInfo(apiInfo) .securitySchemes(buildSecuritySchemeFromSwaggerProperties( swaggerProperties.getSecuritySchemesParameters())) .globalOperationParameters(buildGlobalOperationParametersFromSwaggerProperties( swaggerProperties.getGlobalOperationParameters())); // ?? if (!swaggerProperties.getApplyDefaultResponseMessages()) { buildGlobalResponseMessage(swaggerProperties, docketForBuilder); } Docket docket = docketForBuilder.select() .apis(RequestHandlerSelectors.basePackage(swaggerProperties.getBasePackage())) .paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath))) .build(); /** ignoredParameterTypes **/ Class[] array = new Class[swaggerProperties.getIgnoredParameterTypes().size()]; Class[] ignoredParameterTypes = swaggerProperties.getIgnoredParameterTypes().toArray(array); docket.ignoredParameterTypes(ignoredParameterTypes); configurableBeanFactory.registerSingleton("defaultDocket", docket); docketList.add(docket); return docketList; } // for (String groupName : swaggerProperties.getDocket().keySet()) { SwaggerProperties.DocketInfo docketInfo = swaggerProperties.getDocket().get(groupName); ApiInfo apiInfo = new ApiInfoBuilder() .title(docketInfo.getTitle().isEmpty() ? swaggerProperties.getTitle() : docketInfo.getTitle()) .description(docketInfo.getDescription().isEmpty() ? swaggerProperties.getDescription() : docketInfo.getDescription()) .version(docketInfo.getVersion().isEmpty() ? swaggerProperties.getVersion() : docketInfo.getVersion()) .license(docketInfo.getLicense().isEmpty() ? swaggerProperties.getLicense() : docketInfo.getLicense()) .licenseUrl(docketInfo.getLicenseUrl().isEmpty() ? swaggerProperties.getLicenseUrl() : docketInfo.getLicenseUrl()) .contact(new Contact( docketInfo.getContact().getName().isEmpty() ? swaggerProperties.getContact().getName() : docketInfo.getContact().getName(), docketInfo.getContact().getUrl().isEmpty() ? swaggerProperties.getContact().getUrl() : docketInfo.getContact().getUrl(), docketInfo.getContact().getEmail().isEmpty() ? swaggerProperties.getContact().getEmail() : docketInfo.getContact().getEmail())) .termsOfServiceUrl( docketInfo.getTermsOfServiceUrl().isEmpty() ? swaggerProperties.getTermsOfServiceUrl() : docketInfo.getTermsOfServiceUrl()) .build(); // base-path? // ?path?/** if (docketInfo.getBasePath().isEmpty()) { docketInfo.getBasePath().add("/**"); } List<Predicate<String>> basePath = new ArrayList(); for (String path : docketInfo.getBasePath()) { basePath.add(PathSelectors.ant(path)); } // exclude-path? List<Predicate<String>> excludePath = new ArrayList(); for (String path : docketInfo.getExcludePath()) { excludePath.add(PathSelectors.ant(path)); } Docket docketForBuilder = new Docket(DocumentationType.SWAGGER_2).host(swaggerProperties.getHost()) .apiInfo(apiInfo).globalOperationParameters( assemblyGlobalOperationParameters(swaggerProperties.getGlobalOperationParameters(), docketInfo.getGlobalOperationParameters())); // ?? if (!swaggerProperties.getApplyDefaultResponseMessages()) { buildGlobalResponseMessage(swaggerProperties, docketForBuilder); } Docket docket = docketForBuilder.groupName(groupName).select() .apis(RequestHandlerSelectors.basePackage(docketInfo.getBasePackage())) .paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath))) .build(); /** ignoredParameterTypes **/ Class[] array = new Class[docketInfo.getIgnoredParameterTypes().size()]; Class[] ignoredParameterTypes = docketInfo.getIgnoredParameterTypes().toArray(array); docket.ignoredParameterTypes(ignoredParameterTypes); configurableBeanFactory.registerSingleton(groupName, docket); docketList.add(docket); } return docketList; }
From source file:com.eucalyptus.compute.common.internal.vm.VmInstances.java
/** * List instances that are not done and match the given owner/predicate. * * @param ownerFullName The owning user or account * @param predicate The predicate to match * @return The matching instances//from www . ja v a2 s .c o m * @see com.eucalyptus.compute.common.internal.vm.VmInstance.VmStateSet#DONE */ public static List<VmInstance> list(@Nullable OwnerFullName ownerFullName, @Nullable Predicate<? super VmInstance> predicate) { return list(ownerFullName, Restrictions.not(VmInstance.criterion(VmInstance.VmStateSet.DONE.array())), Collections.<String, String>emptyMap(), Predicates.and(VmInstance.VmStateSet.DONE.not(), checkPredicate(predicate)), false); }
From source file:com.facebook.litho.testing.viewtree.ViewTreeAssert.java
private ImmutableList<View> getPathToVisibleSimilarText(final String text) { return actual.findChild(Predicates.and(isVisible(), hasTextMatchingPredicate(new Predicate<String>() { @Override/* ww w .j a v a 2 s . com*/ public boolean apply(@Nullable final String input) { final int maxEditDistance = Math.max(3, text.length() / 4); return LevenshteinDistance.getLevenshteinDistance(text, input, maxEditDistance) <= maxEditDistance; } })), ViewPredicates.isVisible()); }
From source file:org.eclipse.viatra.query.patternlanguage.ui.contentassist.PatternLanguageProposalProvider.java
@Override public void completePatternCall_PatternRef(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { /*//from ww w . j a v a 2 s . c om * filter not local, private patterns (private patterns in other resources) this information stored in the * userdata of the EObjectDescription EObjectDescription only created for not local eObjects, so check for * resource equality is unnecessary. */ lookupCrossReference(((CrossReference) assignment.getTerminal()), context, acceptor, Predicates.and(featureDescriptionPredicate, new Predicate<IEObjectDescription>() { @Override public boolean apply(IEObjectDescription input) { return !("true".equals(input.getUserData("private"))); } })); }
From source file:com.android.builder.internal.packaging.IncrementalPackager.java
/** * Updates files in the archive.//from w w w . ja v a 2s . c om * * @param updates the updates to perform * @throws IOException failed to update the archive */ private void updateFiles(@NonNull Set<PackagedFileUpdate> updates) throws IOException { Preconditions.checkNotNull(mApkCreator, "mApkCreator == null"); Iterable<String> deletedPaths = Iterables .transform( Iterables .filter(updates, Predicates.compose(Predicates.equalTo(FileStatus.REMOVED), PackagedFileUpdate.EXTRACT_STATUS)), PackagedFileUpdate.EXTRACT_NAME); for (String deletedPath : deletedPaths) { mApkCreator.deleteFile(deletedPath); } Predicate<PackagedFileUpdate> isNewOrChanged = Predicates.compose( Predicates.or(Predicates.equalTo(FileStatus.NEW), Predicates.equalTo(FileStatus.CHANGED)), PackagedFileUpdate.EXTRACT_STATUS); Function<PackagedFileUpdate, File> extractBaseFile = Functions.compose(RelativeFile.EXTRACT_BASE, PackagedFileUpdate.EXTRACT_SOURCE); Iterable<PackagedFileUpdate> newOrChangedNonArchiveFiles = Iterables.filter(updates, Predicates.and(isNewOrChanged, Predicates.compose(Files.isDirectory(), extractBaseFile))); for (PackagedFileUpdate rf : newOrChangedNonArchiveFiles) { mApkCreator.writeFile(rf.getSource().getFile(), rf.getName()); } Iterable<PackagedFileUpdate> newOrChangedArchiveFiles = Iterables.filter(updates, Predicates.and(isNewOrChanged, Predicates.compose(Files.isFile(), extractBaseFile))); Iterable<File> archives = Iterables.transform(newOrChangedArchiveFiles, extractBaseFile); Set<String> names = Sets .newHashSet(Iterables.transform(newOrChangedArchiveFiles, PackagedFileUpdate.EXTRACT_NAME)); /* * Build the name map. The name of the file in the filesystem (or zip file) may not * match the name we want to package it as. See PackagedFileUpdate for more information. */ Map<String, String> pathNameMap = Maps.newHashMap(); for (PackagedFileUpdate archiveUpdate : newOrChangedArchiveFiles) { pathNameMap.put(archiveUpdate.getSource().getOsIndependentRelativePath(), archiveUpdate.getName()); } for (File arch : Sets.newHashSet(archives)) { mApkCreator.writeZip(arch, pathNameMap::get, name -> !names.contains(name)); } }
From source file:com.google.devtools.build.lib.query2.RdepsUnboundedVisitor.java
@Override protected Visit getVisitResult(Iterable<DepAndRdep> depAndRdeps) throws InterruptedException { Collection<SkyKey> validRdeps = new ArrayList<>(); // Multimap of dep to all the reverse deps in this visitation. Used to filter out the // disallowed deps. Multimap<SkyKey, SkyKey> reverseDepMultimap = ArrayListMultimap.create(); for (DepAndRdep depAndRdep : depAndRdeps) { // The "roots" of our visitation (see #preprocessInitialVisit) have a null 'dep' field. if (depAndRdep.dep == null) { validRdeps.add(depAndRdep.rdep); } else {//from ww w. j a v a 2 s .c o m reverseDepMultimap.put(depAndRdep.dep, depAndRdep.rdep); } } Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap = env .makePackageKeyToTargetKeyMap(Iterables.concat(reverseDepMultimap.values())); Set<PackageIdentifier> pkgIdsNeededForTargetification = packageKeyToTargetKeyMap.keySet().stream() .map(SkyQueryEnvironment.PACKAGE_SKYKEY_TO_PACKAGE_IDENTIFIER).collect(toImmutableSet()); packageSemaphore.acquireAll(pkgIdsNeededForTargetification); try { // Filter out disallowed deps. We cannot defer the targetification any further as we do not // want to retrieve the rdeps of unwanted nodes (targets). if (!reverseDepMultimap.isEmpty()) { Collection<Target> filteredTargets = env.filterRawReverseDepsOfTransitiveTraversalKeys( reverseDepMultimap.asMap(), packageKeyToTargetKeyMap); filteredTargets.stream().map(SkyQueryEnvironment.TARGET_TO_SKY_KEY).forEachOrdered(validRdeps::add); } } finally { packageSemaphore.releaseAll(pkgIdsNeededForTargetification); } ImmutableList<SkyKey> uniqueValidRdeps = validRdeps.stream().filter(validRdepUniquifier::unique) .collect(ImmutableList.toImmutableList()); // Retrieve the reverse deps as SkyKeys and defer the targetification and filtering to next // recursive visitation. ImmutableList.Builder<DepAndRdep> depAndRdepsToVisitBuilder = ImmutableList.builder(); env.graph .getReverseDeps( uniqueValidRdeps) .entrySet() .forEach(reverseDepsEntry -> depAndRdepsToVisitBuilder.addAll(Iterables.transform( Iterables.filter(reverseDepsEntry.getValue(), Predicates.and(SkyQueryEnvironment.IS_TTV, universe)), rdep -> new DepAndRdep(reverseDepsEntry.getKey(), rdep)))); return new Visit(/*keysToUseForResult=*/ uniqueValidRdeps, /*keysToVisit=*/ depAndRdepsToVisitBuilder.build()); }
From source file:com.google.devtools.build.lib.query2.RdepsBoundedVisitor.java
@Override protected Visit getVisitResult(Iterable<DepAndRdepAtDepth> depAndRdepAtDepths) throws InterruptedException { Map<SkyKey, Integer> shallowestRdepDepthMap = new HashMap<>(); depAndRdepAtDepths.forEach(depAndRdepAtDepth -> shallowestRdepDepthMap .merge(depAndRdepAtDepth.depAndRdep.rdep, depAndRdepAtDepth.rdepDepth, Integer::min)); Collection<SkyKey> validRdeps = new ArrayList<>(); // Multimap of dep to all the reverse deps in this visitation. Used to filter out the // disallowed deps. Multimap<SkyKey, SkyKey> reverseDepMultimap = ArrayListMultimap.create(); for (DepAndRdepAtDepth depAndRdepAtDepth : depAndRdepAtDepths) { // The "roots" of our visitation (see #preprocessInitialVisit) have a null 'dep' field. if (depAndRdepAtDepth.depAndRdep.dep == null) { validRdeps.add(depAndRdepAtDepth.depAndRdep.rdep); } else {// w w w . j a v a 2s .c om reverseDepMultimap.put(depAndRdepAtDepth.depAndRdep.dep, depAndRdepAtDepth.depAndRdep.rdep); } } Multimap<SkyKey, SkyKey> packageKeyToTargetKeyMap = env .makePackageKeyToTargetKeyMap(Iterables.concat(reverseDepMultimap.values())); Set<PackageIdentifier> pkgIdsNeededForTargetification = packageKeyToTargetKeyMap.keySet().stream() .map(SkyQueryEnvironment.PACKAGE_SKYKEY_TO_PACKAGE_IDENTIFIER).collect(toImmutableSet()); packageSemaphore.acquireAll(pkgIdsNeededForTargetification); try { // Filter out disallowed deps. We cannot defer the targetification any further as we do not // want to retrieve the rdeps of unwanted nodes (targets). if (!reverseDepMultimap.isEmpty()) { Collection<Target> filteredTargets = env.filterRawReverseDepsOfTransitiveTraversalKeys( reverseDepMultimap.asMap(), packageKeyToTargetKeyMap); filteredTargets.stream().map(SkyQueryEnvironment.TARGET_TO_SKY_KEY).forEachOrdered(validRdeps::add); } } finally { packageSemaphore.releaseAll(pkgIdsNeededForTargetification); } ImmutableList<SkyKey> uniqueValidRdeps = validRdeps.stream().filter(validRdep -> validRdepMinDepthUniquifier .uniqueAtDepthLessThanOrEqualTo(validRdep, shallowestRdepDepthMap.get(validRdep))) .collect(ImmutableList.toImmutableList()); // Don't bother getting the rdeps of the rdeps that are already at the depth bound. Iterable<SkyKey> uniqueValidRdepsBelowDepthBound = Iterables.filter(uniqueValidRdeps, uniqueValidRdep -> shallowestRdepDepthMap.get(uniqueValidRdep) < depth); // Retrieve the reverse deps as SkyKeys and defer the targetification and filtering to next // recursive visitation. Map<SkyKey, Iterable<SkyKey>> unfilteredRdepsOfRdeps = env.graph .getReverseDeps(uniqueValidRdepsBelowDepthBound); ImmutableList.Builder<DepAndRdepAtDepth> depAndRdepAtDepthsToVisitBuilder = ImmutableList.builder(); unfilteredRdepsOfRdeps.entrySet().forEach(entry -> { SkyKey rdep = entry.getKey(); int depthOfRdepOfRdep = shallowestRdepDepthMap.get(rdep) + 1; Streams.stream(entry.getValue()).filter(Predicates.and(SkyQueryEnvironment.IS_TTV, universe)) .forEachOrdered(rdepOfRdep -> { depAndRdepAtDepthsToVisitBuilder .add(new DepAndRdepAtDepth(new DepAndRdep(rdep, rdepOfRdep), depthOfRdepOfRdep)); }); }); return new Visit(/*keysToUseForResult=*/ uniqueValidRdeps, /*keysToVisit=*/ depAndRdepAtDepthsToVisitBuilder.build()); }
From source file:net.sf.qualitycheck.immutableobject.domain.Imports.java
/** * Filters primitive types, types without a package declaration and duplicates and returns them as new instance of * {@code Imports}./* ww w .j a v a 2 s. c om*/ * * @return new instance of {@code Imports} */ @Nonnull public Imports filter() { return new Imports( Sets.newHashSet(Collections2.filter(imports, Predicates.and(IGNORE_JAVA_LANG, IGNORE_UNDEFINED)))); }
From source file:com.ardor3d.input.control.FirstPersonControl.java
public void setupMouseTriggers(final LogicalLayer layer, final boolean dragOnly) { // Mouse look final Predicate<TwoInputStates> someMouseDown = Predicates.or(TriggerConditions.leftButtonDown(), Predicates.or(TriggerConditions.rightButtonDown(), TriggerConditions.middleButtonDown())); final Predicate<TwoInputStates> dragged = Predicates.and(TriggerConditions.mouseMoved(), someMouseDown); final TriggerAction dragAction = new TriggerAction() { // Test boolean to allow us to ignore first mouse event. First event can wildly vary based on platform. private boolean firstPing = true; public void perform(final Canvas source, final TwoInputStates inputStates, final double tpf) { final MouseState mouse = inputStates.getCurrent().getMouseState(); if (mouse.getDx() != 0 || mouse.getDy() != 0) { if (!firstPing) { FirstPersonControl.this.rotate(source.getCanvasRenderer().getCamera(), -mouse.getDx(), -mouse.getDy()); } else { firstPing = false;//w w w .j av a 2s . c o m } } } }; _mouseTrigger = new InputTrigger(dragOnly ? dragged : TriggerConditions.mouseMoved(), dragAction); layer.registerTrigger(_mouseTrigger); }
From source file:forge.quest.QuestUtilCards.java
/** * A predicate that takes into account the Quest Format (if any). * @param source//ww w .j a v a 2s. c o m * the predicate to be added to the format predicate. * @return the composite predicate. */ public Predicate<PaperCard> applyFormatFilter(Predicate<PaperCard> source) { return qc.getFormat() == null ? source : Predicates.and(source, qc.getFormat().getFilterPrinted()); }