Example usage for com.google.common.base Predicates not

List of usage examples for com.google.common.base Predicates not

Introduction

In this page you can find the example usage for com.google.common.base Predicates not.

Prototype

public static <T> Predicate<T> not(Predicate<T> predicate) 

Source Link

Document

Returns a predicate that evaluates to true if the given predicate evaluates to false .

Usage

From source file:club.zhcs.swagger.SwaggerAutoConfiguration.java

@Bean
@ConditionalOnMissingBean// w  ww . j  a  va2 s.c  o  m
@ConditionalOnBean(UiConfiguration.class)
@ConditionalOnProperty(name = "swagger.enabled", matchIfMissing = true)
public List<Docket> createRestApi(SwaggerConfigurationProerties SwaggerConfigurationProerties) {
    ConfigurableBeanFactory configurableBeanFactory = (ConfigurableBeanFactory) beanFactory;
    List<Docket> docketList = Lists.newArrayList();

    // 
    if (SwaggerConfigurationProerties.getDocket().size() == 0) {
        ApiInfo apiInfo = new ApiInfoBuilder().title(SwaggerConfigurationProerties.getTitle())
                .description(SwaggerConfigurationProerties.getDescription())
                .version(SwaggerConfigurationProerties.getVersion())
                .license(SwaggerConfigurationProerties.getLicense())
                .licenseUrl(SwaggerConfigurationProerties.getLicenseUrl())
                .contact(new Contact(SwaggerConfigurationProerties.getContact().getName(),
                        SwaggerConfigurationProerties.getContact().getUrl(),
                        SwaggerConfigurationProerties.getContact().getEmail()))
                .termsOfServiceUrl(SwaggerConfigurationProerties.getTermsOfServiceUrl()).build();

        // base-path?
        // ?path?/**
        if (SwaggerConfigurationProerties.getBasePath().isEmpty()) {
            SwaggerConfigurationProerties.getBasePath().add("/**");
        }
        List<Predicate<String>> basePath = new ArrayList();
        for (String path : SwaggerConfigurationProerties.getBasePath()) {
            basePath.add(PathSelectors.ant(path));
        }

        // exclude-path?
        List<Predicate<String>> excludePath = Lists.newArrayList();
        for (String path : SwaggerConfigurationProerties.getExcludePath()) {
            excludePath.add(PathSelectors.ant(path));
        }

        Docket docketForBuilder = new Docket(DocumentationType.SWAGGER_2)
                .host(SwaggerConfigurationProerties.getHost()).apiInfo(apiInfo)
                .securitySchemes(Collections.singletonList(apiKey()))
                .securityContexts(Collections.singletonList(securityContext()))
                .globalOperationParameters(buildGlobalOperationParametersFromSwaggerConfigurationProerties(
                        SwaggerConfigurationProerties.getGlobalOperationParameters()));

        // ??
        if (!SwaggerConfigurationProerties.getApplyDefaultResponseMessages()) {
            buildGlobalResponseMessage(SwaggerConfigurationProerties, docketForBuilder);
        }

        Docket docket = docketForBuilder.select()
                .apis(RequestHandlerSelectors.basePackage(SwaggerConfigurationProerties.getBasePackage()))
                .paths(Predicates.and(Predicates.not(Predicates.or(excludePath)), Predicates.or(basePath)))
                .build();

        /* ignoredParameterTypes **/
        Class<?>[] array = new Class[SwaggerConfigurationProerties.getIgnoredParameterTypes().size()];
        Class<?>[] ignoredParameterTypes = SwaggerConfigurationProerties.getIgnoredParameterTypes()
                .toArray(array);
        docket.ignoredParameterTypes(ignoredParameterTypes);

        configurableBeanFactory.registerSingleton("defaultDocket", docket);
        docketList.add(docket);
        return docketList;
    }

    // 
    for (String groupName : SwaggerConfigurationProerties.getDocket().keySet()) {
        SwaggerConfigurationProerties.DocketInfo docketInfo = SwaggerConfigurationProerties.getDocket()
                .get(groupName);

        ApiInfo apiInfo = new ApiInfoBuilder()
                .title(docketInfo.getTitle().isEmpty() ? SwaggerConfigurationProerties.getTitle()
                        : docketInfo.getTitle())
                .description(
                        docketInfo.getDescription().isEmpty() ? SwaggerConfigurationProerties.getDescription()
                                : docketInfo.getDescription())
                .version(docketInfo.getVersion().isEmpty() ? SwaggerConfigurationProerties.getVersion()
                        : docketInfo.getVersion())
                .license(docketInfo.getLicense().isEmpty() ? SwaggerConfigurationProerties.getLicense()
                        : docketInfo.getLicense())
                .licenseUrl(docketInfo.getLicenseUrl().isEmpty() ? SwaggerConfigurationProerties.getLicenseUrl()
                        : docketInfo.getLicenseUrl())
                .contact(new Contact(
                        docketInfo.getContact().getName().isEmpty()
                                ? SwaggerConfigurationProerties.getContact().getName()
                                : docketInfo.getContact().getName(),
                        docketInfo.getContact().getUrl().isEmpty()
                                ? SwaggerConfigurationProerties.getContact().getUrl()
                                : docketInfo.getContact().getUrl(),
                        docketInfo.getContact().getEmail().isEmpty()
                                ? SwaggerConfigurationProerties.getContact().getEmail()
                                : docketInfo.getContact().getEmail()))
                .termsOfServiceUrl(docketInfo.getTermsOfServiceUrl().isEmpty()
                        ? SwaggerConfigurationProerties.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(SwaggerConfigurationProerties.getHost()).apiInfo(apiInfo)
                .securitySchemes(Collections.singletonList(apiKey()))
                .securityContexts(Collections.singletonList(securityContext()))
                .globalOperationParameters(assemblyGlobalOperationParameters(
                        SwaggerConfigurationProerties.getGlobalOperationParameters(),
                        docketInfo.getGlobalOperationParameters()));

        // ??
        if (!SwaggerConfigurationProerties.getApplyDefaultResponseMessages()) {
            buildGlobalResponseMessage(SwaggerConfigurationProerties, 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:dynamicrefactoring.domain.metadata.imp.ElementCatalog.java

@Override
public void addConditionToFilter(Predicate<K> condition) {
    for (Entry<Category, Set<K>> entry : classifiedElements.entrySet()) {
        Collection<K> toFilter = new HashSet<K>(
                Collections2.filter(entry.getValue(), Predicates.not(condition)));
        classifiedElements.get(entry.getKey()).removeAll(toFilter);
        filteredClassifiedElements.get(entry.getKey()).addAll(toFilter);
    }//from w w  w  .  ja  v  a2s  . com
    filter.add(condition);
}

From source file:org.apache.whirr.Cluster.java

public void removeInstancesMatching(Predicate<Instance> predicate) {
    instances = Sets.filter(instances, Predicates.not(predicate));
}

From source file:net.derquinse.bocas.AbstractGuavaCachingBocas.java

@Override
protected void putAll(Map<ByteString, MemoryByteSource> entries) {
    if (alwaysWrite) {
        bocas.putAll(entries.values());/*from w w w .  j ava2  s . c  om*/
    }
    final Map<K, MemoryByteSource> map = cache.asMap();
    final Map<K, MemoryByteSource> notCached = Maps.filterKeys(toInternalEntryMap(entries),
            Predicates.not(Predicates.in(map.keySet())));
    if (notCached.isEmpty()) {
        return;
    }
    if (!alwaysWrite) {
        bocas.putAll(notCached.values());
    }
    map.putAll(notCached);
}

From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java

public <R> ModelSchemaExtractionResult<R> extract(final ModelSchemaExtractionContext<R> extractionContext,
        ModelSchemaStore store, final ModelSchemaCache cache) {
    ModelType<R> type = extractionContext.getType();
    Class<? super R> clazz = type.getRawClass();
    if (isTarget(type)) {
        validateType(type, extractionContext);

        Iterable<Method> methods = Arrays.asList(clazz.getMethods());
        if (!clazz.isInterface()) {
            methods = filterIgnoredMethods(methods);
        }//  w ww. ja  v a  2 s  .  c  o m
        ImmutableListMultimap<String, Method> methodsByName = Multimaps.index(methods,
                new Function<Method, String>() {
                    public String apply(Method method) {
                        return method.getName();
                    }
                });

        ensureNoOverloadedMethods(extractionContext, methodsByName);

        List<ModelProperty<?>> properties = Lists.newLinkedList();
        List<Method> handled = Lists.newArrayListWithCapacity(clazz.getMethods().length);
        ReturnTypeSpecializationOrdering returnTypeSpecializationOrdering = new ReturnTypeSpecializationOrdering();

        for (String methodName : methodsByName.keySet()) {
            if (methodName.startsWith("get") && !methodName.equals("get")) {
                ImmutableList<Method> getterMethods = methodsByName.get(methodName);

                // The overload check earlier verified that all methods for are equivalent for our purposes
                // So, taking the first one with the most specialized return type is fine.
                Method sampleMethod = returnTypeSpecializationOrdering.max(getterMethods);

                boolean abstractGetter = Modifier.isAbstract(sampleMethod.getModifiers());

                if (sampleMethod.getParameterTypes().length != 0) {
                    throw invalidMethod(extractionContext, "getter methods cannot take parameters",
                            sampleMethod);
                }

                Character getterPropertyNameFirstChar = methodName.charAt(3);
                if (!Character.isUpperCase(getterPropertyNameFirstChar)) {
                    throw invalidMethod(extractionContext,
                            "the 4th character of the getter method name must be an uppercase character",
                            sampleMethod);
                }

                ModelType<?> returnType = ModelType.returnType(sampleMethod);

                String propertyNameCapitalized = methodName.substring(3);
                String propertyName = StringUtils.uncapitalize(propertyNameCapitalized);
                String setterName = "set" + propertyNameCapitalized;
                ImmutableList<Method> setterMethods = methodsByName.get(setterName);

                boolean isWritable = !setterMethods.isEmpty();
                if (isWritable) {
                    Method setter = setterMethods.get(0);

                    if (!abstractGetter) {
                        throw invalidMethod(extractionContext,
                                "setters are not allowed for non-abstract getters", setter);
                    }
                    validateSetter(extractionContext, returnType, setter);
                    handled.addAll(setterMethods);
                }

                if (abstractGetter) {
                    ImmutableSet<ModelType<?>> declaringClasses = ImmutableSet
                            .copyOf(Iterables.transform(getterMethods, new Function<Method, ModelType<?>>() {
                                public ModelType<?> apply(Method input) {
                                    return ModelType.of(input.getDeclaringClass());
                                }
                            }));

                    boolean unmanaged = Iterables.any(getterMethods, new Predicate<Method>() {
                        public boolean apply(Method input) {
                            return input.getAnnotation(Unmanaged.class) != null;
                        }
                    });

                    properties.add(ModelProperty.of(returnType, propertyName, isWritable, declaringClasses,
                            unmanaged));
                }
                handled.addAll(getterMethods);
            }
        }

        Iterable<Method> notHandled = Iterables.filter(methodsByName.values(),
                Predicates.not(Predicates.in(handled)));

        // TODO - should call out valid getters without setters
        if (!Iterables.isEmpty(notHandled)) {
            throw invalidMethods(extractionContext, "only paired getter/setter methods are supported",
                    notHandled);
        }

        Class<R> concreteClass = type.getConcreteClass();
        final ModelSchema<R> schema = createSchema(extractionContext, store, type, properties, concreteClass);
        Iterable<ModelSchemaExtractionContext<?>> propertyDependencies = Iterables.transform(properties,
                new Function<ModelProperty<?>, ModelSchemaExtractionContext<?>>() {
                    public ModelSchemaExtractionContext<?> apply(final ModelProperty<?> property) {
                        return toPropertyExtractionContext(extractionContext, property, cache);
                    }
                });

        return new ModelSchemaExtractionResult<R>(schema, propertyDependencies);
    } else {
        return null;
    }
}

From source file:com.cimr.boot.swagger.SwaggerAutoConfiguration.java

@Bean
@ConditionalOnMissingBean/*from   ww  w.j a  v a2  s  .  c  o 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)
                .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:org.eclipse.sirius.diagram.sequence.business.internal.query.SequenceDiagramQuery.java

/**
 * Get all {@link ISequenceEvent} of the current {@link SequenceDiagram} of
 * the specified {@link Lifeline}.//ww w .  j av a2s . co m
 * 
 * @param lifeline
 *            the specified {@link Lifeline}
 * 
 * @return the set of {@link ISequenceEvent} of the current
 *         {@link SequenceDiagram} of the specified {@link Lifeline}, sorted
 *         by range from lower to upper
 */
public Set<ISequenceEvent> getAllSequenceEventsOnLifeline(Lifeline lifeline) {
    Set<ISequenceEvent> allSequenceEventsOnLifeline = new TreeSet<ISequenceEvent>(new RangeComparator());
    for (ISequenceEvent sequenceEvent : Iterables.filter(getAllSequenceEvents(),
            Predicates.not(Predicates.instanceOf(Lifeline.class)))) {
        Option<Lifeline> lifelineOfSequenceEventOption = sequenceEvent.getLifeline();
        if (lifelineOfSequenceEventOption.some() && lifelineOfSequenceEventOption.get().equals(lifeline)) {
            allSequenceEventsOnLifeline.add(sequenceEvent);
        } else if (!lifelineOfSequenceEventOption.some()) {
            if (sequenceEvent instanceof Message) {
                Message message = (Message) sequenceEvent;
                Option<Lifeline> sourceLifelineOption = message.getSourceLifeline();
                Option<Lifeline> targetLifelineOption = message.getTargetLifeline();
                if (sourceLifelineOption.some() && sourceLifelineOption.get().equals(lifeline)) {
                    allSequenceEventsOnLifeline.add(message);
                } else if (targetLifelineOption.some() && targetLifelineOption.get().equals(lifeline)) {
                    allSequenceEventsOnLifeline.add(message);
                }
            } else if (sequenceEvent instanceof AbstractFrame) {
                AbstractFrame abstractFrame = (AbstractFrame) sequenceEvent;
                Collection<Lifeline> coveredLifelines = abstractFrame.computeCoveredLifelines();
                if (coveredLifelines.contains(lifeline)) {
                    allSequenceEventsOnLifeline.add(abstractFrame);
                }
            }
        }
    }
    return allSequenceEventsOnLifeline;
}

From source file:tile80.tile80.Tile80.java

/**
 * Self crunch with all tag it contains/*from w  w  w .  j  a v a  2s .com*/
 * @param world
 * @param event
 * @return 
 */
public Iterable<Tile80> crunch(World80 world, Set<String> event) {
    ImmutableSet.Builder<Tile80> ret = ImmutableSet.builder();
    Tile80 newTile = this;
    for (Behavior80 tag : getBehavior()) {
        Iterable<Tile80> tileLst = tag.crunch(newTile, world, event);
        newTile = findSelf(tileLst);
        for (Tile80 tile : FluentIterable.from(tileLst).filter(Predicates.not(Predicates.equalTo(newTile))))
            ret.add(tile);
        if (newTile.equals(nothing))
            break;
    }
    return ret.add(newTile).build();
}

From source file:org.apache.brooklyn.test.EntityTestUtils.java

/** alternate version of {@link #assertAttributeChangesEventually(Entity, AttributeSensor)} not using subscriptions and 
 * with simpler code, for comparison */
@Beta//from  w ww.  j a v a  2 s  . co m
public static <T> void assertAttributeChangesEventually2(final Entity entity,
        final AttributeSensor<T> attribute) {
    assertAttributeEventually(entity, attribute,
            Predicates.not(Predicates.equalTo(entity.getAttribute(attribute))));
}

From source file:com.facebook.buck.features.lua.AbstractNativeExecutableStarter.java

private ImmutableList<CxxPreprocessorInput> getTransitiveCxxPreprocessorInput(CxxPlatform cxxPlatform,
        Iterable<? extends CxxPreprocessorDep> deps) {
    ImmutableList.Builder<CxxPreprocessorInput> inputs = ImmutableList.builder();
    inputs.addAll(CxxPreprocessables.getTransitiveCxxPreprocessorInput(cxxPlatform, getActionGraphBuilder(),
            FluentIterable.from(deps).filter(BuildRule.class)));
    for (CxxPreprocessorDep dep : Iterables.filter(deps, Predicates.not(BuildRule.class::isInstance))) {
        inputs.add(dep.getCxxPreprocessorInput(cxxPlatform, getActionGraphBuilder()));
    }/*from   w  w  w .ja  v  a  2 s .co  m*/
    return inputs.build();
}