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:de.se_rwth.langeditor.modelstates.ModelStateAssembler.java

public void scheduleProjectRebuild(IProject project) {
    Set<IStorage> storages = Maps
            .filterValues(ResourceLocator.getStorages(), (projectValue -> projectValue == project)).keySet();

    storages.stream().map(scheduledRebuilds::get).filter(scheduledRebuild -> scheduledRebuild != null)
            .forEach(scheduledRebuild -> scheduledRebuild.cancel(false));

    executor.execute(() -> {/*from   w  w w  . ja va 2  s  .c  o  m*/
        try {
            rebuildProject(project, storages);
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}

From source file:mysql5.MySQL5PlayerCooldownsDAO.java

@Override
public void storePlayerCooldowns(final Player player) {
    deletePlayerCooldowns(player);//  ww  w  . java  2s.  c  o  m

    Map<Integer, Long> cooldowns = player.getSkillCoolDowns();
    if (cooldowns != null && cooldowns.size() > 0) {
        Map<Integer, Long> filteredCooldown = Maps.filterValues(cooldowns, cooldownPredicate);

        if (filteredCooldown.isEmpty()) {
            return;
        }

        Connection con = null;
        PreparedStatement st = null;
        try {
            con = DatabaseFactory.getConnection();
            con.setAutoCommit(false);
            st = con.prepareStatement(INSERT_QUERY);

            for (Map.Entry<Integer, Long> entry : filteredCooldown.entrySet()) {
                st.setInt(1, player.getObjectId());
                st.setInt(2, entry.getKey());
                st.setLong(3, entry.getValue());
                st.addBatch();
            }

            st.executeBatch();
            con.commit();

        } catch (SQLException e) {
            log.error("Can't save cooldowns for player " + player.getObjectId());
        } finally {
            DatabaseFactory.close(st, con);
        }
    }
}

From source file:com.twitter.common.collections.Multimaps.java

/**
 * Returns the set of keys associated with groups of a size greater than or equal to a given size.
 *
 * @param map The multimap to search.//  w  ww  .  j av a2 s  . com
 * @param minSize The minimum size to return associated keys for.
 * @param <K> The key type for the multimap.
 * @return The keys associated with groups of size greater than or equal to {@code minSize}.
 * @throws IllegalArgumentException if minSize < 0
 */
public static <K> Set<K> getLargeGroups(Multimap<K, ?> map, int minSize) {
    return Sets.newHashSet(Maps.filterValues(map.asMap(), new AtLeastSize(minSize)).keySet());
}

From source file:ai.grakn.migration.sql.SQLMigrator.java

/**
 * Convert values to be valid - removing nulls and changing to supported types
 * @param data data to make valid/*from w  w  w.  j  a v a 2  s  . co  m*/
 * @return valid data
 */
private Map<String, Object> convertToValidValues(Map<String, Object> data) {
    data = Maps.filterValues(data, Objects::nonNull);
    data = Maps.transformValues(data, this::convertToSupportedTypes);
    return data;
}

From source file:org.lilyproject.repository.impl.hbase.LilyRecordVariantFilter.java

private Map<String, String> getValuedDimensions() {
    return Maps.filterValues(variantProperties, new Predicate<String>() {
        @Override//from w  w w  . j  ava2s .  c  o  m
        public boolean apply(String input) {
            return input != null;
        }
    });
}

From source file:com.torodb.core.transaction.metainf.WrapperMutableMetaDocPart.java

public WrapperMutableMetaDocPart(ImmutableMetaDocPart wrapped,
        Consumer<WrapperMutableMetaDocPart> changeConsumer) {
    this.wrapped = wrapped;

    newFields = HashBasedTable.create();

    wrapped.streamFields().forEach((field) -> newFields.put(field.getName(), field.getType(), field));
    addedFields = new ArrayList<>();
    addedFieldsByIndetifiers = new HashMap<>();
    this.changeConsumer = changeConsumer;
    this.newScalars = new EnumMap<>(FieldType.class);
    indexesByIdentifier = new HashMap<>();
    wrapped.streamIndexes().forEach((docPartIndexindex) -> {
        indexesByIdentifier.put(docPartIndexindex.getIdentifier(),
                new Tuple2<>(docPartIndexindex, MetaElementState.NOT_CHANGED));
    });/*from  w ww . j av a  2 s  .  com*/
    aliveIndexesMap = Maps.filterValues(indexesByIdentifier, tuple -> tuple.v2().isAlive());
    addedMutableIndexes = new ArrayList<>();
}

From source file:com.palantir.atlasdb.keyvalue.impl.RowResults.java

public static Function<RowResult<byte[]>, RowResult<byte[]>> createFilterColumnValues(
        final Predicate<byte[]> keepValue) {
    return new Function<RowResult<byte[]>, RowResult<byte[]>>() {
        @Override/*from w  ww.  j ava  2s  .c o m*/
        public RowResult<byte[]> apply(RowResult<byte[]> row) {
            return RowResult.create(row.getRowName(), Maps.filterValues(row.getColumns(), keepValue));
        }
    };
}

From source file:mysql5.MySQL5ItemCooldownsDAO.java

@Override
public void storeItemCooldowns(Player player) {
    deleteItemCooldowns(player);/* www .j  a  v  a  2s.  com*/
    Map<Integer, ItemCooldown> itemCoolDowns = player.getItemCoolDowns();

    if (itemCoolDowns == null) {
        return;
    }

    Map<Integer, ItemCooldown> map = Maps.filterValues(itemCoolDowns, itemCooldownPredicate);
    final Iterator<Map.Entry<Integer, ItemCooldown>> 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, ItemCooldown> entry = iterator.next();
            st.setInt(1, player.getObjectId());
            st.setInt(2, entry.getKey());
            st.setInt(3, entry.getValue().getUseDelay());
            st.setLong(4, entry.getValue().getReuseTime());
            st.addBatch();
        }

        st.executeBatch();
        con.commit();
    } catch (SQLException e) {
        log.error("Error while storing item cooldows for player " + player.getObjectId(), e);
    } finally {
        DatabaseFactory.close(st, con);
    }
}

From source file:ai.grakn.test.engine.tasks.BackgroundTaskTestUtils.java

public static Multiset<TaskId> completableTasks(List<TaskState> tasks) {
    Map<TaskId, Long> tasksById = tasks.stream().collect(groupingBy(TaskState::getId, counting()));
    Set<TaskId> retriedTasks = Maps.filterValues(tasksById, count -> count != null && count > 1).keySet();

    Set<TaskId> completableTasks = Sets.newHashSet();
    Set<TaskId> visitedTasks = Sets.newHashSet();

    Set<TaskId> appearedTasks = Sets.newHashSet();

    tasks.forEach(task -> {//from  ww w . j a v a 2 s .c o m
        // A task is expected to complete only if:
        // 1. It has not already executed and failed
        // 2. it is not a failing task
        // 3. it is RUNNING or not being retried
        TaskId id = task.getId();
        boolean visited = visitedTasks.contains(id);
        boolean willFail = task.taskClass().equals(FailingMockTask.class);
        boolean isRunning = appearedTasks.contains(id);
        boolean isRetried = retriedTasks.contains(id);
        if (!visited && (isRunning || !isRetried)) {
            if (!willFail) {
                completableTasks.add(id);
            }
            visitedTasks.add(id);
        }
        appearedTasks.add(id);
    });

    return ImmutableMultiset.copyOf(completableTasks);
}

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

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