Example usage for java.util List removeIf

List of usage examples for java.util List removeIf

Introduction

In this page you can find the example usage for java.util List removeIf.

Prototype

default boolean removeIf(Predicate<? super E> filter) 

Source Link

Document

Removes all of the elements of this collection that satisfy the given predicate.

Usage

From source file:Main.java

public static void main(String[] args) {
    List<Integer> l = new ArrayList<Integer>();
    l.add(3);/*from   w  w  w  . j  a v  a  2 s .c  om*/
    l.add(2);
    l.add(1);
    l.add(4);
    l.removeIf(i -> {
        return i >= 3;//No return statement will break compilation
    });
    System.out.println(l);
}

From source file:io.github.jeddict.jpa.spec.validator.column.ForeignKeyValidator.java

/**
 * Remove empty/invalid ForeignKey/*from   w  w  w . j ava  2  s .  c om*/
 *
 * @param foreignKeys
 */
public static void filter(List<ForeignKey> foreignKeys) {
    foreignKeys.removeIf(ForeignKeyValidator::isEmpty);
}

From source file:io.github.jeddict.jpa.spec.validator.column.JoinColumnValidator.java

/**
 * Remove empty/invalid JoinColumn//w  ww .java 2s . c om
 *
 * @param columns
 */
public static void filter(List<JoinColumn> columns) {
    columns.removeIf(JoinColumnValidator::isEmpty);
}

From source file:io.github.jeddict.jpa.spec.validator.column.PrimaryKeyJoinColumnValidator.java

/**
 * Remove empty/invalid PrimaryKeyJoinColumn
 *
 * @param columns/*from   w  w  w.j  a  v  a2  s. c  om*/
 */
public static void filter(List<PrimaryKeyJoinColumn> columns) {
    columns.removeIf(PrimaryKeyJoinColumnValidator::isEmpty);
}

From source file:org.kie.jenkinsci.plugins.kieprbuildshelper.RepositoryLists.java

/**
 * TODO: this is an ugly hack. The dependency between repositories (or directly modules) should to be checked automatically for every build
 *//*from  w ww.  jav  a2s.c o m*/
public static List<Tuple<GitHubRepository, GitBranch>> filterOutUnnecessaryRepos(
        List<Tuple<GitHubRepository, GitBranch>> repos, GitHubRepository baseRepo) {
    // nothing depends on stuff from -tools repo
    repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "droolsjbpm-tools")));
    // no need to build docs as other repos do not depend on them
    repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "kie-docs")));

    if ("kie-docs".equals(baseRepo.getName())) {
        // we only need to build repos up to "guvnor" as that's what kie-docs-code depends on
        repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "kie-wb-playground")));
        repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "kie-wb-common")));
        repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "drools-wb")));
        repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "optaplanner-wb")));
        repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "jbpm-designer")));
        repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "jbpm-wb")));
        repos.removeIf(repo -> repo._1().equals(new GitHubRepository("kiegroup", "kie-wb-distributions")));
    }
    return repos;
}

From source file:org.alex73.osm.monitors.export.ReadChangesets.java

/**
 * ? changeset'  before  after.  after==null, ? ? ? ?? before.
 *///from w  w w  .  ja  v a  2s  .com
public static List<Changeset> retrieve(Set<Long> knownChangesetsBefore, Set<Long> knownChangesetsAfter)
        throws Exception {
    System.out.println("Retrieve changesets");
    CONTEXT = JAXBContext.newInstance(OsmChange.class, Osm.class);

    List<Changeset> forProcess = new ArrayList<>();

    read: for (long i = readLast(); i >= 0; i--) {
        List<Changeset> changesets = readSeq(i);

        changesets.removeIf(ch -> ch.getClosedAt() == null); // ? ?? ?

        if (changesets.isEmpty()) {
            continue;
        }

        // changesets from latest to previous
        sort(changesets);
        Collections.reverse(changesets);

        boolean beforeAfter = knownChangesetsAfter == null;
        for (Changeset ch : changesets) {
            if (!beforeAfter && knownChangesetsAfter.contains(ch.getId())) {
                //  changeset ?  after, ?   ? - 
                beforeAfter = true;
            }
            if (knownChangesetsBefore.contains(ch.getId())) {
                //  changeset ?  before,  ??  
                break read;
            }
            if (beforeAfter && !isOutside(ch)) {
                forProcess.add(ch);
            }
        }
    }

    sort(forProcess);
    return forProcess;
}

From source file:ch.cyberduck.core.aquaticprime.LicenseFactory.java

public static License find(final LicenseVerifierCallback callback) {
    try {/*  w ww  .  j av a2  s  .c  o  m*/
        final String clazz = preferences.getProperty("factory.licensefactory.class");
        try {
            final Class<LicenseFactory> name = (Class<LicenseFactory>) Class.forName(clazz);
            final List<License> list = new ArrayList<License>(name.newInstance().open());
            list.removeIf(key -> !key.verify(callback));
            if (list.isEmpty()) {
                return LicenseFactory.EMPTY_LICENSE;
            }
            return list.iterator().next();
        } catch (InstantiationException | ClassNotFoundException | IllegalAccessException e) {
            throw new FactoryException(e.getMessage(), e);
        }
    } catch (AccessDeniedException e) {
        log.warn(String.format("Failure finding receipt %s", e.getMessage()));
    }
    return LicenseFactory.EMPTY_LICENSE;
}

From source file:org.openhab.binding.ihc.internal.ChannelUtils.java

private static void removeChannelByUID(List<Channel> thingChannels, ChannelUID channelUIDtoRemove) {
    Predicate<Channel> channelPredicate = c -> c.getUID().getId().equals(channelUIDtoRemove.getId());
    thingChannels.removeIf(channelPredicate);
}

From source file:com.comphenix.protocol.events.PacketMetadata.java

public static <T> void set(Object packet, String key, T value) {
    Validate.notNull(key, "Null keys are not permitted!");

    if (META_CACHE == null) {
        createCache();//  w ww. ja  va2  s  .  c o m
    }

    List<MetaObject> packetMeta;

    try {
        packetMeta = META_CACHE.get(packet, ArrayList::new);
    } catch (ExecutionException ex) {
        // Not possible, but let's humor the array list constructor having an issue
        packetMeta = new ArrayList<>();
    }

    packetMeta.removeIf(meta -> meta.key.equals(key));
    packetMeta.add(new MetaObject<>(key, value));
    META_CACHE.put(packet, packetMeta);
}

From source file:org.jspare.forvertx.web.collector.HandlerCollector.java

@SuppressWarnings("unchecked")
private static List<Annotation> getHttpMethodsPresents(AnnotatedElement element) {

    List<Class<?>> filteredClazz = new ArrayList<>();
    filteredClazz.addAll(Arrays.asList(HttpMethodType.values()).stream().map(ht -> ht.getHttpMethodClass())
            .collect(Collectors.toList()));
    filteredClazz.removeIf(clazzHttpMethodType -> !element
            .isAnnotationPresent((Class<? extends Annotation>) clazzHttpMethodType));
    return filteredClazz.stream()
            .map(httpMethodClazz -> element.getAnnotation((Class<? extends Annotation>) httpMethodClazz))
            .collect(Collectors.toList());
}