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:info.gehrels.voting.web.applicationState.CastBallotsState.java

public synchronized void deleteById(long ballotId) {
    Iterables.removeIf(firstTryCastBallots, hasId(ballotId));
    Iterables.removeIf(secondTryCastBallots, hasId(ballotId));
}

From source file:xml.entity.mutableelement.InternalElement.java

@Override
public Element value(final String value) {
    Iterables.removeIf(children(), Elements.byName("#text"));
    children().add(new Text(value, this.factory));
    return this;
}

From source file:org.obiba.onyx.quartz.core.engine.questionnaire.question.Attributes.java

/**
 * @param attributes/*from   w  ww .ja va 2s  . co m*/
 * @param namespace
 * @param name
 */
public static void removeAttributes(List<Attribute> attributes, String namespace, String name) {
    Iterables.removeIf(attributes, predicate(namespace, name));
}

From source file:com.google.devtools.kythe.analyzers.java.MiniAnchor.java

/**
 * Returns a new string with brackets added to {@code text} (escaping existing ones) and sorts
 * {@code miniAnchors} such that the ith {@link MiniAnchor} corresponds to the ith opening
 * bracket. Drops empty or negative-length spans.
 *
 * @see <a href="http://www.kythe.io/docs/schema/#doc">the Kythe schema section on doc nodes</a>
 * @param text the text to bracket/*from   w ww . jav  a 2 s  .  c  o m*/
 * @param posTransform a function that will be applied to transform offsets in {@code text} to
 *     anchor offsets
 * @param miniAnchors a mutable list of {@link MiniAnchor} instances to sort and filter. This list
 *     must support removal
 * @return {@code text} with brackets added and escaped as necessary.
 */
public static <T> String bracket(String text, PositionTransform posTransform, List<MiniAnchor<T>> miniAnchors) {
    Iterables.removeIf(miniAnchors, new Predicate<MiniAnchor<T>>() {
        @Override
        public boolean apply(MiniAnchor<T> a) {
            // Drop empty or negative-length spans. These are not useful for presentation or
            // are invalid.
            return a.begin >= a.end;
        }
    });
    Collections.sort(miniAnchors, new Comparator<MiniAnchor<T>>() {
        @Override
        public int compare(MiniAnchor<T> l, MiniAnchor<T> r) {
            return l.begin == r.begin ? r.end - l.end : l.begin - r.begin;
        }
    });
    StringBuilder bracketed = new StringBuilder(text.length() + miniAnchors.size() * 2);
    Iterator<MiniAnchor<T>> anchors = miniAnchors.iterator();
    MiniAnchor<T> nextAnchor = anchors.hasNext() ? anchors.next() : null;
    PriorityQueue<Integer> ends = new PriorityQueue<Integer>();
    for (int i = 0; i < text.length(); ++i) {
        int sourcePos = posTransform.transform(i);
        char c = text.charAt(i);
        while (!ends.isEmpty() && ends.peek() == sourcePos) {
            ends.poll();
            bracketed.append(']');
        }
        while (nextAnchor != null && nextAnchor.begin == sourcePos) {
            bracketed.append('[');
            ends.add(nextAnchor.end);
            nextAnchor = anchors.hasNext() ? anchors.next() : null;
        }
        if (c == '[' || c == ']' || c == '\\') {
            bracketed.append('\\');
        }
        bracketed.append(c);
    }
    for (int i = 0; i < ends.size(); ++i) {
        bracketed.append(']');
    }
    return bracketed.toString();
}

From source file:com.google.caliper.config.CaliperConfigLoader.java

private static ImmutableMap<String, String> mergeProperties(Map<String, String> commandLine,
        Map<String, String> user, Map<String, String> defaults) {
    Map<String, String> map = Maps.newHashMap(defaults);
    map.putAll(user); // overwrite and augment
    map.putAll(commandLine); // overwrite and augment
    Iterables.removeIf(map.values(), Predicates.equalTo(""));
    return ImmutableMap.copyOf(map);
}

From source file:org.obiba.onyx.quartz.core.engine.questionnaire.question.Attributes.java

/**
 * @param attributes//from  w  w w. j a  v  a 2  s.c  o m
 * @param namespace
 * @param name
 */
public static void removeAttributes(List<Attribute> attributes, String namespace, final String name,
        Locale locale) {
    Iterables.removeIf(attributes, predicate(namespace, name, locale));
}

From source file:org.apache.drill.exec.schema.ObjectSchema.java

@Override
public Iterable<? extends Field> removeUnreadFields() {
    final List<Field> removedFields = Lists.newArrayList();
    Iterables.removeIf(fields.values(), new Predicate<Field>() {
        @Override//  www .  jav  a2s. c  o  m
        public boolean apply(Field field) {
            if (!field.isRead()) {
                removedFields.add(field);
                return true;
            } else if (field.hasSchema()) {
                Iterables.addAll(removedFields, field.getAssignedSchema().removeUnreadFields());
            }

            return false;
        }
    });
    return removedFields;
}

From source file:de.cosmocode.commons.validation.TrueRule.java

@Override
public boolean removeIf(Iterable<? extends Object> removeFrom) {
    Preconditions.checkNotNull(removeFrom, "RemoveFrom");
    return Iterables.removeIf(removeFrom, this);
}

From source file:com.eucalyptus.reporting.domain.ReportingAccountDao.java

public ReportingAccount getReportingAccount(String accountId) {

    ReportingAccount searchAccount = new ReportingAccount();
    searchAccount.setId(accountId);/*  w  w  w  .  j  a  va 2s.c o m*/
    List<ReportingAccount> foundAccountList = Lists.newArrayList();

    EntityTransaction db = Entities.get(ReportingAccount.class);
    try {

        foundAccountList = (List<ReportingAccount>) Entities.query(searchAccount, true);

        db.commit();
    } catch (Exception ex) {
        LOG.error(ex, ex);
        foundAccountList.clear();
    } finally {
        if (db.isActive())
            db.rollback();
    }

    if (foundAccountList.isEmpty()) {
        return null;
    }

    Iterables.removeIf(foundAccountList, Predicates.isNull());
    return foundAccountList.get(0);

}

From source file:co.cask.cdap.common.namespace.InMemoryNamespaceClient.java

@Override
public void delete(final Id.Namespace namespaceId) throws Exception {
    Iterables.removeIf(namespaces, new Predicate<NamespaceMeta>() {
        @Override//  w ww  .java2  s .c  o  m
        public boolean apply(NamespaceMeta input) {
            return input.getName().equals(namespaceId.getId());
        }
    });
}