Example usage for java.util.function Predicate negate

List of usage examples for java.util.function Predicate negate

Introduction

In this page you can find the example usage for java.util.function Predicate negate.

Prototype

default Predicate<T> negate() 

Source Link

Document

Returns a predicate that represents the logical negation of this predicate.

Usage

From source file:com.github.anba.es6draft.util.TestGlobals.java

private static <T> Predicate<T> not(Predicate<T> p) {
    return p.negate();
}

From source file:de.se_rwth.langeditor.util.Misc.java

public static boolean removeFromClasspath(IJavaProject javaProject, Predicate<IClasspathEntry> predicate) {
    try {/* ww w .j  a v a2  s  .  c  o m*/
        IClasspathEntry[] oldClasspath = javaProject.getRawClasspath();
        List<IClasspathEntry> filteredClasspath = Arrays.stream(oldClasspath).filter(predicate.negate())
                .collect(Collectors.toList());
        IClasspathEntry[] newClasspath = filteredClasspath
                .toArray(new IClasspathEntry[filteredClasspath.size()]);
        javaProject.setRawClasspath(newClasspath, null);
        return oldClasspath.length > newClasspath.length;
    } catch (JavaModelException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.act.biointerpretation.l2expansion.L2FilteringDriver.java

private static L2PredictionCorpus applyFilter(L2PredictionCorpus corpus, Predicate<L2Prediction> filter,
        CommandLine cl, String filterOption) throws IOException {
    if (cl.hasOption(filterOption)) {
        if (cl.getOptionValue(filterOption).equals(APPLY_FILTER_NEGATED)) {
            return corpus.applyFilter(filter.negate());
        }/*from   w w w  . ja v  a 2 s .  c  o m*/
        return corpus.applyFilter(filter);
    }
    return corpus;
}

From source file:com.github.steveash.guavate.Guavate.java

/**
 * Returns a predicate that negates the original.
 * <p>/* ww w .ja  v a2 s  .  c o  m*/
 * The JDK provides {@link Predicate#negate()} however this requires a predicate.
 * Sometimes, it can be useful to have a static method to achieve this.
 * <pre>
 *  stream.filter(not(String::isEmpty))
 * </pre>
 * @param <R> the type of the object the predicate works on
 * @param predicate the predicate to negate
 * @return the negated predicate
 */
public static <R> Predicate<R> not(Predicate<R> predicate) {
    return predicate.negate();
}

From source file:org.graylog.plugins.pipelineprocessor.parser.errors.WrongNumberOfArgs.java

@JsonProperty("reason")
@Override/*from ww w.  j a  va  2 s  . c  o  m*/
public String toString() {
    final Predicate<ParameterDescriptor> optional = ParameterDescriptor::optional;
    return "Expected " + function.descriptor().params().stream().filter(optional.negate()).count()
            + " arguments but found " + argCount + " in call to function " + function.descriptor().name()
            + positionString();
}

From source file:alfio.manager.SpecialPriceManager.java

public List<SpecialPrice> loadSentCodes(String eventName, int categoryId, String username) {
    final Event event = eventManager.getSingleEvent(eventName, username);
    checkOwnership(categoryId, event, username);
    Predicate<SpecialPrice> p = SpecialPrice::notSent;
    return specialPriceRepository.findAllByCategoryId(categoryId).stream().filter(p.negate()).collect(toList());
}

From source file:com.daimler.spm.b2bacceleratoraddon.controllers.pages.AdvanceSearchPageController.java

protected String getPaginationUrlFromHttpRequest(final HttpServletRequest request) {
    final Map<String, String[]> requestParamMap = request.getParameterMap();
    final StringBuilder queryParamBuilder = new StringBuilder();
    final Predicate<Map.Entry<String, String[]>> predicate = entry -> PAGINATION_PARAM_REMOVAL_LOOKUP_TABLE
            .contains(entry.getKey().trim().toUpperCase());
    queryParamBuilder.append("?");
    requestParamMap.entrySet().stream().filter(predicate.negate()).forEach(entry -> queryParamBuilder.append(
            ((queryParamBuilder.length() > 1) ? "&" : "") + entry.getKey() + "=" + entry.getValue()[0]));

    return queryParamBuilder.toString();
}

From source file:it.greenvulcano.gvesb.iam.service.internal.GVUsersManager.java

@Override
public void updateUser(String username, UserInfo userInfo, Set<Role> grantedRoles, boolean enabled,
        boolean expired) throws UserNotFoundException, InvalidRoleException {
    User user = userRepository.get(username).orElseThrow(() -> new UserNotFoundException(username));
    user.setUserInfo(userInfo);/*from  w w w  .  j av  a 2  s. c  om*/
    user.setEnabled(enabled);
    user.setExpired(expired);
    user.clearRoles();
    if (grantedRoles != null) {

        Predicate<Role> roleIsValid = role -> Optional.ofNullable(role.getName()).orElse("")
                .matches(Role.ROLE_PATTERN);

        Optional<Role> notValidRole = grantedRoles.stream().filter(roleIsValid.negate()).findAny();
        if (notValidRole.isPresent()) {
            throw new InvalidRoleException(notValidRole.get().getName());
        }

        for (Role r : grantedRoles) {
            user.addRole(roleRepository.get(r.getName()).orElse(r));
        }

    }
    userRepository.add(user);
}

From source file:it.greenvulcano.configuration.BaseConfigurationManager.java

@Override
public Set<File> getHistory() throws IOException {
    Path history = getHistoryPath();
    if (Files.exists(history)) {

        Path currentConfigArchive = getConfigurationPath(getCurrentConfigurationName());
        Predicate<Path> currentConfig = p -> {
            try {
                return Files.isSameFile(p, currentConfigArchive);
            } catch (IOException e) {
                return false;
            }/*from  ww  w .j av a 2 s  .co m*/
        };

        return Files.list(history).filter(currentConfig.negate()).map(Path::toFile).collect(Collectors.toSet());
    }

    return new LinkedHashSet<>();
}

From source file:org.apache.nifi.remote.util.SiteToSiteRestApiClient.java

/**
 * Parse the comma-separated URLs string for the remote NiFi instances.
 * @return A set containing one or more URLs
 * @throws IllegalArgumentException when it fails to parse the URLs string,
 * URLs string contains multiple protocols (http and https mix),
 * or none of URL is specified.//from   ww w .  j  a  v a 2s  .  co m
 */
public static Set<String> parseClusterUrls(final String clusterUrlStr) {
    final Set<String> urls = new LinkedHashSet<>();
    if (clusterUrlStr != null && clusterUrlStr.length() > 0) {
        Arrays.stream(clusterUrlStr.split(",")).map(s -> s.trim()).filter(s -> s.length() > 0).forEach(s -> {
            validateUriString(s);
            urls.add(resolveBaseUrl(s).intern());
        });
    }

    if (urls.size() == 0) {
        throw new IllegalArgumentException("Cluster URL was not specified.");
    }

    final Predicate<String> isHttps = url -> url.toLowerCase().startsWith("https:");
    if (urls.stream().anyMatch(isHttps) && urls.stream().anyMatch(isHttps.negate())) {
        throw new IllegalArgumentException("Different protocols are used in the cluster URLs " + clusterUrlStr);
    }

    return Collections.unmodifiableSet(urls);
}