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.jfrog.build.extractor.BuildInfoExtractorUtils.java

public static Map<String, ?> filterStringEntries(Map<String, ?> map) {
    return Maps.filterValues(map, new Predicate<Object>() {
        public boolean apply(Object input) {
            return input != null && input instanceof String;
        }//from w  w w .  ja va2  s .co  m
    });
}

From source file:org.carrot2.core.ControllerUtils.java

/**
 * Perform all life cycle actions after processing is completed.
 *///w ww.  j  a v  a  2 s.com
@SuppressWarnings("unchecked")
public static void afterProcessing(IProcessingComponent processingComponent, Map<String, Object> attributes) {
    try {
        processingComponent.afterProcessing();

        final Map<String, Object> outputAttributesWithNulls = Maps.newHashMap();
        // Check if we need to do binding.
        if (processingComponent.getClass().getAnnotation(Bindable.class) != null) {
            AttributeBinder.get(processingComponent, outputAttributesWithNulls, Output.class, Processing.class);
        }
        attributes.putAll(Maps.filterValues(outputAttributesWithNulls, Predicates.notNull()));
    } catch (final InstantiationException e) {
        throw new ProcessingException("Attribute binding failed", e);
    }
}

From source file:org.auraframework.impl.adapter.ContextValueProvider.java

@Override
public Map<String, ?> getData() {
    AuraContext context = contextService.getCurrentContext();

    if (context == null) {
        contextService.getAllowedGlobals();
    }//w ww .  j av a  2  s . co m

    Predicate<AuraContext.GlobalValue> isNonNullFilter = new Predicate<AuraContext.GlobalValue>() {
        @Override
        public boolean apply(AuraContext.GlobalValue globalValue) {
            return globalValue.getValue() != null;
        }
    };

    return Maps.filterValues(context.getGlobals(), isNonNullFilter);
}

From source file:ninja.leaping.permissionsex.extrabackends.groupmanager.GroupManagerSubjectData.java

@Override
public Map<Set<Map.Entry<String, String>>, Map<String, String>> getAllOptions() {
    return Maps.filterValues(Maps.asMap(getActiveContexts(), this::getOptions),
            input -> input != null && !input.isEmpty());
}

From source file:org.apache.aurora.scheduler.updater.OneWayJobUpdater.java

private static <K, T> Set<K> filterByStatus(Map<K, InstanceUpdate<T>> instances,
        SideEffect.InstanceUpdateStatus status) {

    return ImmutableSet.copyOf(
            Maps.filterValues(instances, Predicates.compose(Predicates.equalTo(status), GET_STATE)).keySet());
}

From source file:org.lanternpowered.server.service.permission.LanternContextCalculator.java

private LoadingCache<RemoteSource, Set<Context>> buildAddressCache(final String contextKey,
        final Function<RemoteSource, InetAddress> function) {
    return Caffeine.newBuilder().weakKeys().build(key -> {
        final ImmutableSet.Builder<Context> builder = ImmutableSet.builder();
        final InetAddress addr = checkNotNull(function.apply(key), "addr");
        builder.add(new Context(contextKey, addr.getHostAddress()));
        //noinspection Guava,ConstantConditions
        for (String set : Maps
                .filterValues(Lantern.getGame().getGlobalConfig().getIpSets(), input -> input.test(addr))
                .keySet()) {//  w  w  w  . j  a  va 2  s . co  m
            builder.add(new Context(contextKey, set));
        }
        return builder.build();
    });
}

From source file:info.archinnov.achilles.context.CQLDaoContextBuilder.java

public CQLDaoContext build(Map<Class<?>, EntityMeta> entityMetaMap, boolean hasSimpleCounter) {
    Map<Class<?>, PreparedStatement> insertPSMap = new HashMap<Class<?>, PreparedStatement>(
            Maps.transformValues(Maps.filterValues(entityMetaMap, excludeClusteredCounterFilter),
                    insertPSTransformer));

    Map<Class<?>, PreparedStatement> selectEagerPSMap = new HashMap<Class<?>, PreparedStatement>(
            Maps.transformValues(entityMetaMap, selectEagerPSTransformer));

    Map<Class<?>, Map<String, PreparedStatement>> removePSMap = new HashMap<Class<?>, Map<String, PreparedStatement>>(
            Maps.transformValues(entityMetaMap, removePSTransformer));

    Cache<StatementCacheKey, PreparedStatement> dynamicPSCache = CacheBuilder.newBuilder()
            .maximumSize(PREPARED_STATEMENT_LRU_CACHE_SIZE).build();

    Map<CQLQueryType, PreparedStatement> counterQueryMap;
    if (hasSimpleCounter) {
        counterQueryMap = queryGenerator.prepareSimpleCounterQueryMap(session);
    } else {//www  .ja  v  a  2s  .c o  m
        counterQueryMap = new HashMap<CQLQueryType, PreparedStatement>();
    }

    Map<Class<?>, Map<CQLQueryType, PreparedStatement>> clusteredCounterQueriesMap = new HashMap<Class<?>, Map<CQLQueryType, PreparedStatement>>(
            Maps.transformValues(Maps.filterValues(entityMetaMap, clusteredCounterFilter),
                    clusteredCounterTransformer));

    return new CQLDaoContext(insertPSMap, dynamicPSCache, selectEagerPSMap, removePSMap, counterQueryMap,
            clusteredCounterQueriesMap, session);
}

From source file:mysql5.MySQL5EventItemsDAO.java

@Override
public void storeItems(Player player) {
    //player.clearItemMaxThisCount();
    deleteItems(player);/*from w  ww . j a  v  a 2 s  .  c  om*/
    Map<Integer, MaxCountOfDay> itemsm = player.getItemMaxThisCounts();

    if (itemsm == null) {
        return;
    }

    Map<Integer, MaxCountOfDay> map = Maps.filterValues(itemsm, maxCountOfDay);
    final Iterator<Map.Entry<Integer, MaxCountOfDay>> iterator = map.entrySet().iterator();
    if (!iterator.hasNext()) {
        return;
    }
    Connection con = null;
    PreparedStatement st = null;
    try {
        con = DatabaseFactory.getConnection();
        con.setAutoCommit(false);
        st = con.prepareStatement(INSERT_QUERY);
        while (iterator.hasNext()) {
            Map.Entry<Integer, MaxCountOfDay> entry = iterator.next();
            st.setInt(1, player.getObjectId());
            st.setInt(2, entry.getKey());
            st.setInt(3, entry.getValue().getThisCount());
            st.addBatch();
        }
        st.executeBatch();
        con.commit();
        player.clearItemMaxThisCount();
    } catch (SQLException e) {
        log.error("Error while storing event_items for player " + player.getObjectId(), e);
    } finally {
        DatabaseFactory.close(st, con);
    }
}

From source file:com.eucalyptus.component.ComponentMessages.java

public static Collection<Class<? extends BaseMessage>> forComponent(ComponentId compId) {
    Class<? extends ComponentId> compIdClass = compId.getClass();
    if (!compIdMap.containsValue(compIdClass)) {
        return Collections.emptyList();
    } else {/*w ww.j  a  v  a  2  s  . c  o  m*/
        return Maps.filterValues((Map) compIdMap, Predicates.equalTo(compIdClass)).keySet();
    }
}

From source file:org.spongepowered.common.service.permission.SpongeContextCalculator.java

private LoadingCache<RemoteSource, Set<Context>> buildAddressCache(final String contextKey,
        final Function<RemoteSource, InetAddress> function) {
    return CacheBuilder.newBuilder().weakKeys().build(new CacheLoader<RemoteSource, Set<Context>>() {
        @Override//w  ww  . j av a 2s  . c o  m
        public Set<Context> load(RemoteSource key) throws Exception {
            ImmutableSet.Builder<Context> builder = ImmutableSet.builder();
            final InetAddress addr = checkNotNull(function.apply(key), "addr");
            builder.add(new Context(contextKey, addr.getHostAddress()));
            for (String set : Maps.filterValues(SpongeImpl.getGlobalConfig().getConfig().getIpSets(), input -> {
                return input.apply(addr);
            }).keySet()) {
                builder.add(new Context(contextKey, set));
            }
            return builder.build();
        }
    });
}