Example usage for com.google.common.collect Maps filterValues

List of usage examples for com.google.common.collect Maps filterValues

Introduction

In this page you can find the example usage for com.google.common.collect Maps filterValues.

Prototype

@CheckReturnValue
public static <K, V> BiMap<K, V> filterValues(BiMap<K, V> unfiltered,
        final Predicate<? super V> valuePredicate) 

Source Link

Document

Returns a bimap containing the mappings in unfiltered whose values satisfy a predicate.

Usage

From source file:org.onosproject.store.ecmap.EventuallyConsistentMapImpl.java

@Override
public void clear() {
    checkState(!destroyed, destroyedMessage);
    Maps.filterValues(items, MapValue::isAlive).forEach((k, v) -> remove(k));
}

From source file:com.cinchapi.concourse.server.storage.temp.Buffer.java

@Override
public Map<String, Set<TObject>> select(long record, long timestamp, Map<String, Set<TObject>> context) {
    for (Iterator<Write> it = iterator(record, timestamp); it.hasNext();) {
        Write write = it.next();//ww w  .  jav  a  2s. c o  m
        Set<TObject> values;
        values = context.get(write.getKey().toString());
        if (values == null) {
            values = Sets.newHashSet();
            context.put(write.getKey().toString(), values);
        }
        if (write.getType() == Action.ADD) {
            values.add(write.getValue().getTObject());
        } else {
            values.remove(write.getValue().getTObject());
        }
    }
    return Maps.newTreeMap((SortedMap<String, Set<TObject>>) Maps.filterValues(context, emptySetFilter));
}

From source file:org.onosproject.store.ecmap.EventuallyConsistentMapImpl.java

@Override
public Set<K> keySet() {
    checkState(!destroyed, destroyedMessage);
    return Maps.filterValues(items, MapValue::isAlive).keySet();
}

From source file:org.linagora.linshare.ldap.JScriptLdapQuery.java

/**
 * Filtering database LDAP attributes map to get only attributes needed for
 * build a user.//www.  ja  va2 s  .  c  om
 * 
 * @return
 */
private Map<String, LdapAttribute> getLdapDbAttribute() {
    Map<String, LdapAttribute> dbAttributes = domainPattern.getAttributes();
    Predicate<LdapAttribute> completionFilter = new Predicate<LdapAttribute>() {
        public boolean apply(LdapAttribute attr) {
            return attr.getEnable();
        }
    };

    Map<String, LdapAttribute> filterValues = Maps.filterValues(dbAttributes, completionFilter);
    return filterValues;
}

From source file:org.onosproject.store.ecmap.EventuallyConsistentMapImpl.java

@Override
public Collection<V> values() {
    checkState(!destroyed, destroyedMessage);
    return Collections2.transform(Maps.filterValues(items, MapValue::isAlive).values(), MapValue::get);
}

From source file:org.tzi.use.uml.mm.MModel.java

public Collection<MClassInvariant> classInvariants(boolean onlyActive) {
    if (onlyActive) {
        return Maps.filterValues(fClassInvariants, new Predicate<MClassInvariant>() {
            @Override/*w  w  w.  ja  va 2  s  .com*/
            public boolean apply(MClassInvariant input) {
                return input.isActive();
            }
        }).values();
    } else {
        return fClassInvariants.values();
    }
}

From source file:com.cinchapi.concourse.server.storage.temp.Limbo.java

@Override
public Set<Long> search(String key, String query) {
    Map<Long, Set<Value>> rtv = Maps.newHashMap();
    String[] needle = TStrings.stripStopWordsAndTokenize(query.toLowerCase());
    if (needle.length > 0) {
        for (Iterator<Write> it = getSearchIterator(key); it.hasNext();) {
            Write write = it.next();/* ww  w . j  a v a2s. c o  m*/
            Value value = write.getValue();
            long record = write.getRecord().longValue();
            if (isPossibleSearchMatch(key, write, value)) {
                /*
                 * NOTE: It is not enough to merely check if the stored text
                 * contains the query because the Database does infix
                 * indexing/searching, which has some subtleties:
                 * 1. Stop words are removed from the both stored indices
                 * and the search query
                 * 2. A query and document are considered to match if the
                 * document contains a sequence of terms where each term or
                 * a substring of the term matches the term in the same
                 * relative position of the query.
                 */
                // CON-10: compare lowercase for case insensitive search
                String stored = (String) (value.getObject());
                String[] haystack = TStrings.stripStopWordsAndTokenize(stored.toLowerCase());
                if (haystack.length > 0 && TStrings.isInfixSearchMatch(needle, haystack)) {
                    Set<Value> values = rtv.get(record);
                    if (values == null) {
                        values = Sets.newHashSet();
                        rtv.put(record, values);
                    }
                    if (write.getType() == Action.REMOVE) {
                        values.remove(value);
                    } else {
                        values.add(value);
                    }

                }
            }
        }
    }
    // FIXME sort search results based on frequency (see
    // SearchRecord#search())
    return newLinkedHashMap(Maps.filterValues(rtv, emptySetFilter)).keySet();
}

From source file:com.palantir.atlasdb.transaction.impl.SnapshotTransaction.java

private SortedMap<byte[], RowResult<byte[]>> filterRowResults(String tableName, Map<Cell, Value> rawResults,
        Map<Cell, byte[]> result) {
    getWithPostfiltering(tableName, rawResults, result, Value.GET_VALUE);
    Map<Cell, byte[]> filterDeletedValues = Maps.filterValues(result, Predicates.not(Value.IS_EMPTY));
    return RowResults.viewOfSortedMap(Cells.breakCellsUpByRow(filterDeletedValues));
}

From source file:org.onosproject.store.ecmap.EventuallyConsistentMapImpl.java

@Override
public Set<Map.Entry<K, V>> entrySet() {
    checkState(!destroyed, destroyedMessage);
    return Maps.filterValues(items, MapValue::isAlive).entrySet().stream()
            .map(e -> Pair.of(e.getKey(), e.getValue().get())).collect(Collectors.toSet());
}

From source file:org.jfrog.teamcity.agent.BaseBuildInfoExtractor.java

private void gatherBuildInfoParams(Map<String, String> allParamMap, Map propertyReceiver,
        final String propPrefix, final String... propTypes) {
    Map<String, String> filteredProperties = Maps.filterKeys(allParamMap, new Predicate<String>() {
        public boolean apply(String key) {
            if (StringUtils.isNotBlank(key)) {
                if (key.startsWith(propPrefix)) {
                    return true;
                }//w w w .  j  av a 2s .  com
                for (String propType : propTypes) {
                    if (key.startsWith(propType + propPrefix)) {
                        return true;
                    }
                }
            }
            return false;
        }
    });
    filteredProperties = Maps.filterValues(filteredProperties, new Predicate<String>() {
        public boolean apply(String value) {
            return StringUtils.isNotBlank(value);
        }
    });

    for (Map.Entry<String, String> entryToAdd : filteredProperties.entrySet()) {
        String key = entryToAdd.getKey();
        for (String propType : propTypes) {
            key = StringUtils.remove(key, propType);
        }
        key = StringUtils.remove(key, propPrefix);
        propertyReceiver.put(key, entryToAdd.getValue());
    }
}