Example usage for com.google.common.collect Iterables removeIf

List of usage examples for com.google.common.collect Iterables removeIf

Introduction

In this page you can find the example usage for com.google.common.collect Iterables removeIf.

Prototype

public static <T> boolean removeIf(Iterable<T> removeFrom, Predicate<? super T> predicate) 

Source Link

Document

Removes, from an iterable, every element that satisfies the provided predicate.

Usage

From source file:task3.Task3.java

public static void main(String[] args) throws Throwable {
    JAXBContext jc = JAXBContext.newInstance("task3.book");
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    Catalog xdml = (Catalog) unmarshaller.unmarshal(new File("Book.xml"));
    xdml.getBook().remove(xdml.getBook().get(0));
    Iterables.removeIf(xdml.getBook(), new Predicate<Book>() {

        public boolean apply(Book t) {
            return (t.getGenre().contains("Fan"));
        }//from w w w .  j  a v  a2 s.c o m
    });
    xdml.getBook().get(0).setAuthor("Jarne Stroustrup");
    for (Book pos : xdml.getBook()) {
        System.out.println(pos.getAuthor() + " " + pos.getTitle());
    }
    System.out.println("Max elem=" + getMaxPrice(xdml.getBook()));
    System.out.println("Avrg price=" + getAvrgPrice(xdml.getBook()));
    System.out.println("Avrg price=" + getOldestBook(xdml.getBook()));
}

From source file:com.google.caliper.runner.CaliperRc.java

static CaliperRc create(Map<String, String> overrides, Map<String, String> defaults) {
    Map<String, String> map = Maps.newHashMap(defaults);
    map.putAll(overrides); // overwrite and augment
    Iterables.removeIf(map.values(), Predicates.equalTo(""));
    return new CaliperRc(map);
}

From source file:org.eclipse.sirius.common.tools.api.resource.ResourceMigrationMarker.java

/**
 * Clear the {@link ResourceMigrationMarker} from the resource.
 * //w  ww. j av  a  2s. co  m
 * @param res
 *            resource to clear.
 */
public static void clearMigrationMarker(Resource res) {
    Iterables.removeIf(res.eAdapters(), Predicates.instanceOf(ResourceMigrationMarker.class));
}

From source file:com.google.errorprone.refaster.testdata.PlaceholderTemplateExample.java

public void positiveExample(List<Integer> list) {
    Iterables.removeIf(list, new Predicate<Integer>() {

        @Override//  w w  w. j a  v a  2 s  .co  m
        public boolean apply(Integer input) {
            return input < 0;
        }
    });

}

From source file:com.google.errorprone.refaster.testdata.PlaceholderAllowsIdentityTemplateExample.java

public void positiveExample(List<Integer> list) {
    Iterables.removeIf(list, new Predicate<Integer>() {
        @Override/*  w  ww. j a v  a  2 s  .co m*/
        public boolean apply(Integer input) {
            return input < 0;
        }
    });
}

From source file:com.google.errorprone.refaster.testdata.PlaceholderAllowsIdentityTemplateExample.java

public void positiveIdentityExample(List<Boolean> list) {
    Iterables.removeIf(list, new Predicate<Boolean>() {
        @Override/*from  w ww.  j a v a 2s  .co m*/
        public boolean apply(Boolean input) {
            return input;
        }
    });
}

From source file:org.apache.gobblin.runtime.listeners.JobListeners.java

/**
 * Chains a given {@link List} of {@link JobListener}s into a single {@link JobListener}. The specified {@link JobListener}s
 * will all be executed in parallel.//w w w .  j  a va  2s  .co  m
 *
 * @param jobListeners is a {@link List} of {@link JobListener}s that need to be executed
 *
 * @return a {@link CloseableJobListener}, which is similar to {@link JobListener}, except
 * {@link CloseableJobListener#close()} will block until all {@link JobListener}s have finished their executions.
 */
public static CloseableJobListener parallelJobListener(List<JobListener> jobListeners) {
    Iterables.removeIf(jobListeners, Predicates.isNull());
    return new ParallelJobListener(jobListeners);
}

From source file:org.solovyev.android.messenger.entities.EntityAwareRemovedUpdater.java

@Nullable
@Override//  w  w w . ja va 2  s  .  c  o  m
public List<V> update(@Nonnull List<V> values) {
    if (values == ThreadSafeMultimap.NO_VALUE) {
        return null;
    } else {
        final List<V> result = ThreadSafeMultimap.copy(values);
        Iterables.removeIf(result, new Predicate<V>() {
            @Override
            public boolean apply(@Nullable V entityAware) {
                return entityAware != null && entityAware.getEntity().getEntityId().equals(removedEntityId);
            }
        });
        return result;
    }
}

From source file:se.crafted.chrisb.ecoCreature.events.mappers.AbstractEventMapper.java

protected static void addPlayerSkullToEvent(ItemDrop drop, Event event) {
    if (event instanceof PlayerKilledEvent) {
        PlayerKilledEvent playerKilledEvent = (PlayerKilledEvent) event;

        boolean hasSkull = Iterables.removeIf(drop.getItems(), new Predicate<ItemStack>() {

            @Override/* w  ww.j a v a 2  s .  co  m*/
            public boolean apply(ItemStack itemStack) {
                return itemStack != null && itemStack.getType() == Material.SKULL_ITEM;
            }
        });

        if (hasSkull) {
            playerKilledEvent.getDrops().add(createSkullItem(playerKilledEvent.getVictim().getName()));
        }
    }
}

From source file:com.google.errorprone.refaster.testdata.template.PlaceholderTemplate.java

@AfterTemplate
<E> void iterablesRemoveIf(Collection<E> collection) {
    Iterables.removeIf(collection, new Predicate<E>() {
        @Override/*  w ww.jav  a 2 s .c  om*/
        public boolean apply(E input) {
            return someBooleanCondition(input);
        }
    });
}