List of usage examples for com.google.common.base Predicates not
public static <T> Predicate<T> not(Predicate<T> predicate)
From source file:cn.howardliu.gear.spring.boot.autoconfigure.SwaggerAutoConfiguration.java
@Bean @ConditionalOnMissingBean/*ww w. j a va 2 s . co m*/ @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).securityContexts(Collections.singletonList(securityContext())) .globalOperationParameters(buildGlobalOperationParametersFromSwaggerProperties( swaggerProperties.getGlobalOperationParameters())); if ("BasicAuth".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { docketForBuilder.securitySchemes(Collections.singletonList(basicAuth())); } else if (!"None".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { docketForBuilder.securitySchemes(Collections.singletonList(apiKey())); } // ?? 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).securityContexts(Collections.singletonList(securityContext())) .globalOperationParameters( assemblyGlobalOperationParameters(swaggerProperties.getGlobalOperationParameters(), docketInfo.getGlobalOperationParameters())); if ("BasicAuth".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { docketForBuilder.securitySchemes(Collections.singletonList(basicAuth())); } else if (!"None".equalsIgnoreCase(swaggerProperties.getAuthorization().getType())) { docketForBuilder.securitySchemes(Collections.singletonList(apiKey())); } // ?? 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.google.devtools.build.lib.util.FileType.java
/** * A filter for Iterable<? extends HasFileType> that returns everything except the specified file * type.//from www . jav a 2s.co m */ public static <T extends HasFilename> Iterable<T> except(final Iterable<T> items, FileType fileType) { return Iterables.filter(items, Predicates.not(typeMatchingPredicateFor(fileType))); }
From source file:com.facebook.buck.lua.AbstractNativeExecutableStarter.java
private ImmutableList<CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform, Iterable<? extends CxxPreprocessorDep> deps) throws NoSuchBuildTargetException { ImmutableList.Builder<CxxPreprocessorInput> inputs = ImmutableList.builder(); inputs.addAll(CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, FluentIterable.from(deps).filter(BuildRule.class))); for (CxxPreprocessorDep dep : Iterables.filter(deps, Predicates.not(BuildRule.class::isInstance))) { inputs.add(dep.getCxxPreprocessorInput(cxxPlatform, HeaderVisibility.PUBLIC)); }//from w w w. ja v a2 s . c o m return inputs.build(); }
From source file:org.apache.brooklyn.util.core.osgi.BundleMaker.java
/** create a copy of the given ZIP as a JAR with the given manifest, returning the new temp file */ public File copyAddingManifest(File f, Manifest mf) { File f2 = Os.newTempFile(f.getName(), "zip"); ZipOutputStream zout = null;//from www. jav a 2s . c o m ZipFile zf = null; try { zout = new JarOutputStream(new FileOutputStream(f2), mf); writeZipEntriesFromFile(zout, f, Predicates.not(Predicates.equalTo(MANIFEST_PATH))); } catch (IOException e) { throw Exceptions.propagateAnnotated("Unable to read " + f + " when looking for manifest", e); } finally { Streams.closeQuietly(zf); Streams.closeQuietly(zout); } return f2; }
From source file:ezbake.data.graph.blueprints.visibility.PropertyFilter.java
/** * Filter an iterable of properties, rejecting the values for which the * contained context has any of the given permissions. Return an iterable * of values that this token does <em>not</em> have any of the given * permissions on.//w w w .ja v a 2 s . c o m * * @param values iterable of values * @param permissions list of permissions to check * @return iterable of values that this token does not have any of the * permissions for. */ public Iterable<Map<String, Object>> reject(Iterable<Map<String, Object>> values, Permission... permissions) { return Iterables.filter(values, Predicates.not(hasAnyPermissionPredicate(permissions))); }
From source file:eu.numberfour.n4js.ui.containers.NfarStorageMapper.java
private void updateCache(IN4JSEclipseProject project) { Set<URI> libArchives = knownLibArchives.get(project.getLocation()); if (libArchives != null) { Map<URI, Set<URI>> filteredMap = Maps.filterKeys(knownLibArchives, Predicates.not(Predicates.equalTo(project.getLocation()))); Set<URI> remainingLibs = Sets.newHashSet(Iterables.concat(filteredMap.values())); for (URI archive : libArchives) { if (!remainingLibs.contains(archive)) { knownEntries.remove(archive); }/* w w w . ja v a 2s . c o m*/ } } if (project.exists()) { libArchives = Sets.newHashSetWithExpectedSize(3); List<? extends IN4JSArchive> libraries = project.getLibraries(); for (IN4JSArchive archive : libraries) { URI location = archive.getLocation(); libArchives.add(location); if (!knownEntries.containsKey(location)) { Set<URI> entryURIs = Sets.newHashSet(); traverseArchive(archive, entryURIs); knownEntries.put(location, Collections.unmodifiableSet(entryURIs)); } } knownLibArchives.put(project.getLocation(), libArchives); } else { knownLibArchives.remove(project.getLocation()); } }
From source file:com.facebook.buck.model.BuildTargets.java
/** * Propagate a build target's flavors in a certain domain to a list of other build targets. * * @param domain the flavor domain to be propagated. * @param buildTarget the build target containing the flavors to be propagated * @param deps list of BuildTargets to propagate the flavors to. If a target already contains * one or more flavors in domain, it is left unchanged. * @return the list of BuildTargets with any flavors propagated. *//* ww w . ja v a 2s .co m*/ public static FluentIterable<BuildTarget> propagateFlavorsInDomainIfNotPresent(FlavorDomain<?> domain, BuildTarget buildTarget, FluentIterable<BuildTarget> deps) { if (domain.containsAnyOf(buildTarget.getFlavors())) { FluentIterable<BuildTarget> targetsWithFlavorsAlready = deps .filter(BuildTargets.containsFlavors(domain)); FluentIterable<BuildTarget> targetsWithoutFlavors = deps .filter(Predicates.not(BuildTargets.containsFlavors(domain))); deps = targetsWithFlavorsAlready.append(BuildTargets.propagateFlavorDomains(buildTarget, ImmutableSet.of(domain), targetsWithoutFlavors)); } return deps; }
From source file:com.twitter.aurora.scheduler.http.SchedulerzRole.java
private IQuota getNonProdConsumption(String role) { FluentIterable<ITaskConfig> tasks = FluentIterable .from(Storage.Util.weaklyConsistentFetchTasks(storage, Query.roleScoped(role).active())) .transform(Tasks.SCHEDULED_TO_INFO).filter(Predicates.not(Tasks.IS_PRODUCTION)); return Quotas.fromTasks(tasks); }
From source file:org.fabrician.enabler.predicates.ContainerPredicates.java
/** * Returns a predicate for filtering-in container instances NOT in "running" state. * @param state/* w w w . j ava 2 s . c o m*/ * the state of container */ public static Predicate<Container> notRunning(final State state) { return Predicates.not(running(state)); }
From source file:org.immutables.generator.SourceOrdering.java
/** * While we have {@link SourceOrdering}, there's still a problem: We have inheritance hierarchy * and/*from ww w . j a va 2 s. c om*/ * we want to have all defined or inherited accessors returned as members of target type, like * {@link Elements#getAllMembers(TypeElement)}, but we need to have them properly and stably * sorted. * This implementation doesn't try to correctly resolve order for accessors inherited from * different supertypes(interfaces), just something that stable and reasonable wrt source ordering * without handling complex cases. * @param elements the elements utility * @param types the types utility * @param type the type to traverse * @return provider of all accessors in source order and mapping */ public static AccessorProvider getAllAccessorsProvider(final Elements elements, final Types types, final TypeElement type) { class CollectedOrdering extends Ordering<Element> { class Intratype { Ordering<String> ordering; int rank; } final Map<String, Intratype> accessorOrderings = Maps.newLinkedHashMap(); final List<TypeElement> linearizedTypes = Lists.newArrayList(); final Predicate<String> accessorNotYetInOrderings = Predicates .not(Predicates.in(accessorOrderings.keySet())); final ArrayListMultimap<String, TypeElement> accessorMapping = ArrayListMultimap.create(); CollectedOrdering() { traverse(type); traverseObjectForInterface(); } private void traverseObjectForInterface() { if (type.getKind() == ElementKind.INTERFACE) { traverse(elements.getTypeElement(Object.class.getName())); } } void traverse(@Nullable TypeElement element) { if (element == null) { return; } collectEnclosing(element); traverse(asTypeElement(element.getSuperclass())); for (TypeMirror implementedInterface : element.getInterfaces()) { traverse(asTypeElement(implementedInterface)); } } @Nullable TypeElement asTypeElement(TypeMirror type) { if (type.getKind() == TypeKind.DECLARED) { return (TypeElement) ((DeclaredType) type).asElement(); } return null; } void collectEnclosing(TypeElement type) { FluentIterable<String> accessorsInType = FluentIterable .from(SourceOrdering.getEnclosedElements(type)).filter(IsParameterlessNonstatic.PREDICATE) .transform(ToSimpleName.FUNCTION); for (String accessor : accessorsInType) { accessorMapping.put(accessor, type); } List<String> accessors = accessorsInType.filter(accessorNotYetInOrderings).toList(); Intratype intratype = new Intratype(); intratype.rank = linearizedTypes.size(); intratype.ordering = Ordering.explicit(accessors); for (String name : accessors) { accessorOrderings.put(name, intratype); } linearizedTypes.add(type); } @Override public int compare(Element left, Element right) { String leftKey = ToSimpleName.FUNCTION.apply(left); String rightKey = ToSimpleName.FUNCTION.apply(right); Intratype leftIntratype = accessorOrderings.get(leftKey); Intratype rightIntratype = accessorOrderings.get(rightKey); if (leftIntratype == null || rightIntratype == null) { // FIXME figure out why it happens (null) return Boolean.compare(leftIntratype == null, rightIntratype == null); } return leftIntratype == rightIntratype ? leftIntratype.ordering.compare(leftKey, rightKey) : Integer.compare(leftIntratype.rank, rightIntratype.rank); } } final CollectedOrdering ordering = new CollectedOrdering(); return new AccessorProvider() { ImmutableListMultimap<String, TypeElement> accessorMapping = ImmutableListMultimap .copyOf(ordering.accessorMapping); ImmutableList<ExecutableElement> sortedList = FluentIterable .from(ElementFilter.methodsIn(elements.getAllMembers(type))) .filter(IsParameterlessNonstatic.PREDICATE).toSortedList(ordering); @Override public ImmutableListMultimap<String, TypeElement> accessorMapping() { return accessorMapping; } @Override public ImmutableList<ExecutableElement> get() { return sortedList; } }; }