Example usage for java.util.function Predicate Predicate

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

Introduction

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

Prototype

Predicate

Source Link

Usage

From source file:de.vandermeer.skb.commons.Predicates.java

/**
 * Returns a predicate that returns true if a given pair is a translation for a specified target or source.
 * If target and source are null, the predicate will return false. If the target is not null, the predicate will
 * return true if the pair is a translation for the target. If the source is not null, the predicate will return
 * true if the pair is a translation for the source.
 * @param <SOURCE> source (left) of pair
 * @param <TARGET> target (right) of pair
 * @param <P> a pair of source and target
 * @param target the target to evaluate, null if the source should be used
 * @param source the source to evaluate, null if the target should be used
 * @return the predicate//  w w w .j  ava2s  .c  om
 */
public final static <SOURCE, TARGET, P extends Skb_Pair<SOURCE, TARGET>> Predicate<P> IS_TRANSLATION_FOR(
        final TARGET target, final SOURCE source) {
    return new Predicate<P>() {
        @Override
        public boolean test(P pair) {
            if (target == null && source == null) {
                return false;
            }
            if (target != null && target.equals(pair.rhs())) {
                return true;
            }
            if (source != null && source.equals(pair.lhs())) {
                return true;
            }
            return false;
        }
    };
}

From source file:de.msg.repository.RouteRepositoryImpl.java

@Override
public Iterable<Route> findByDeparture(String departure) {
    return StreamSupport.stream(driver.getRouteList().spliterator(), false).filter(new Predicate<Route>() {
        @Override//from  w  w w .j  a  va  2 s  .  co  m
        public boolean test(Route route) {
            return route.getDeparture().equals(departure);
        }
    }).collect(Collectors.toList());
}

From source file:freemarker.GoodsController.java

@RequestMapping(value = "/goods", method = RequestMethod.GET)
@ResponseBody/*  w w  w . j a  v  a 2 s  .  c o  m*/
public List get(final Good good) {
    final Stream<Good> goodStream = goods.stream().filter(new Predicate<Good>() {
        public boolean test(Good g) {
            boolean isOK = true;
            if (good.getName() != null && good.getName() != "") {
                if (!g.getName().equals(good.getName()))
                    isOK = false;
            }
            if (good.getPrice() != null && good.getPrice() != "") {
                if (!g.getPrice().equals(good.getPrice()))
                    isOK = false;
            }
            if (good.getRecommend() != null && good.getRecommend() != "") {
                if (!g.getRecommend().equals(good.getRecommend()))
                    isOK = false;
            }
            return isOK;
        }
    });
    return Arrays.asList(goodStream.toArray());
}

From source file:io.gravitee.management.rest.resource.AbstractResource.java

protected boolean isUserInRole(String role) {
    return SecurityContextHolder.getContext().getAuthentication().getAuthorities().stream()
            .anyMatch(new Predicate<GrantedAuthority>() {
                @Override/*from w w  w. ja v  a 2 s  . c  o  m*/
                public boolean test(GrantedAuthority grantedAuthority) {
                    return grantedAuthority.getAuthority().equalsIgnoreCase(role);
                }
            });
}

From source file:org.lendingclub.mercator.aws.ShadowAttributeRemover.java

public void removeTagAttributes(String label, JsonNode desired, JsonNode cache) {
    removeAttributes(label, desired, cache, new Predicate<String>() {

        @Override/* w  w w  .j  av a2 s  .  c  o  m*/
        public boolean test(String t) {
            return t.startsWith("aws_tag_");
        }

    });
}

From source file:com.bombardier.plugin.utils.FilePathUtils.java

/**
 * Used to read test cases from a list - line by line.
 * //ww w . j  a  va 2s.c o m
 * @param file
 *            the {@link Path} to the file
 * @return An {@link List} containing all test cases.
 * @throws IOException
 * @since 1.0
 */
public static List<String> readTextFileByLines(FilePath file) throws Exception {
    List<String> list = Files.readAllLines(Paths.get(file.absolutize().toURI()), StandardCharsets.UTF_8);
    list.removeIf(new Predicate<String>() {
        @Override
        public boolean test(String arg0) {
            return !StringUtils.isNotBlank(arg0);
        }
    });
    return list;
}

From source file:jease.cms.service.Relocator.java

private List<Content> searchContent(final String target) {
    return Database.query(Content.class, new Predicate<Content>() {
        public boolean test(Content obj) {
            return obj.getFulltext().indexOf(target) != -1;
        }/*w w  w  .j  a  v  a2 s  .co m*/
    });
}

From source file:ch.cyberduck.core.serializer.ProfileDictionary.java

public Profile deserialize(Object serialized) {
    final Deserializer<String> dict = deserializer.create(serialized);
    final String protocol = dict.stringForKey("Protocol");
    if (StringUtils.isNotBlank(protocol)) {
        final Protocol parent = protocols.forName(protocols.find(new Predicate<Protocol>() {
            @Override//from w w  w. j a  v a  2  s.  co m
            public boolean test(final Protocol protocol) {
                return true;
            }
        }), protocol, null);
        if (null == parent) {
            log.error(String.format("Unknown protocol %s in profile", protocol));
            return null;
        }
        return new Profile(parent, dict);
    }
    log.error("Missing protocol in profile");
    return null;
}

From source file:nl.pinniq.web.service.ScheduledTask.java

/**
 * Removes a worker process from the work package
 * @param id of the worker process/*from   w w w  .j  ava2 s  .c  o  m*/
 */
public void removeWork(String id) {
    Predicate<ProcessRunnable> filter = new Predicate<ProcessRunnable>() {
        @Override
        public boolean test(ProcessRunnable t) {
            return id.equalsIgnoreCase(t.getProcessId());
        }
    };
    work.remove(work.removeIf(filter));
}

From source file:com.dtolabs.rundeck.core.authorization.RuleEvaluator.java

public static List<AclRule> narrowContext(final AclRuleSet ruleSet, final AclSubject subject,
        final Set<Attribute> environment) {
    return ruleSet.getRules().stream().filter(new Predicate<AclRule>() {
        @Override//ww  w . jav a 2s .c  om
        public boolean test(final AclRule rule) {
            return matchesContexts(rule, subject, environment);
        }
    }).collect(Collectors.toList());

}