Java Code Examples for com.google.common.collect.Maps#filterValues()
The following examples show how to use
com.google.common.collect.Maps#filterValues() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PathChildrenCache.java From xian with Apache License 2.0 | 6 votes |
private boolean hasUninitialized(Map<String, ChildData> localInitialSet) { if ( localInitialSet == null ) { return false; } Map<String, ChildData> uninitializedChildren = Maps.filterValues ( localInitialSet, new Predicate<ChildData>() { @Override public boolean apply(ChildData input) { return (input == NULL_CHILD_DATA); // check against ref intentional } } ); return (uninitializedChildren.size() != 0); }
Example 2
Source File: PathChildrenCache.java From curator with Apache License 2.0 | 6 votes |
private boolean hasUninitialized(Map<String, ChildData> localInitialSet) { if ( localInitialSet == null ) { return false; } Map<String, ChildData> uninitializedChildren = Maps.filterValues ( localInitialSet, new Predicate<ChildData>() { @Override public boolean apply(ChildData input) { return (input == NULL_CHILD_DATA); // check against ref intentional } } ); return (uninitializedChildren.size() != 0); }
Example 3
Source File: TestUnitTestGroupsManager.java From proctor with Apache License 2.0 | 6 votes |
@Test public void testNestedClasses() throws Exception { final Map<String, String> declaredContext = UtilMethods.getProctorSpecification(SPECIFICATION_RESOURCE).getProvidedContext(); final Map<String, String> innerClassTypes = Maps.filterValues(declaredContext, new Predicate<String>() { @Override public boolean apply(final String subfrom) { return subfrom.contains("$"); } }); assertFalse( "Sample groups need to contain at least one inner class type", innerClassTypes.isEmpty()); final ProvidedContext providedContext = ProctorUtils.convertContextToTestableMap(declaredContext); assertFalse( "Expected the provided context to be populated since no class-not-found-error should have been thrown", providedContext.getContext().isEmpty()); }
Example 4
Source File: PinLaterRedisBackend.java From pinlater with Apache License 2.0 | 6 votes |
@VisibleForTesting public static Map.Entry<String, RedisPools> getRandomShard( final ImmutableMap<String, RedisPools> shardMap, final HealthChecker healthChecker, final Random random, final boolean healthyOnly) { Map<String, RedisPools> filteredShardMap; if (healthyOnly) { filteredShardMap = Maps.filterValues(shardMap, new Predicate<RedisPools>() { @Override public boolean apply(@Nullable RedisPools redisPools) { return healthChecker.isServerLive(redisPools.getHost(), redisPools.getPort()); } }); if (filteredShardMap.size() == 0) { return null; } } else { filteredShardMap = shardMap; } return (Map.Entry) filteredShardMap.entrySet().toArray()[ random.nextInt(filteredShardMap.size())]; }
Example 5
Source File: InMemoryProctorStore.java From proctor with Apache License 2.0 | 6 votes |
@Override public synchronized TestMatrixVersion getTestMatrix(final String revisionId) throws StoreException { final Map<String, Optional<TestDefinition>> allTests = getHistoryFromRevision(revisionId) .filter(r -> r.testEdit != null) .collect(Collectors.toMap( r -> r.testEdit.testName, r -> Optional.ofNullable(r.testEdit.definition), // returning null causes runtime error (a, b) -> a // pick up the latest update of the test )); final Revision revision = getUpdateRecord(revisionId).revision; return new TestMatrixVersion( new TestMatrixDefinition( Maps.filterValues( Maps.transformValues(allTests, x -> x.orElse(null)), Objects::nonNull ) // remove deleted tests ), revision.getDate(), revision.getRevision(), revision.getMessage(), revision.getAuthor() ); }
Example 6
Source File: SectionContainerBackend.java From binnavi with Apache License 2.0 | 6 votes |
/** * Loads all sections from the database. * * @return The list of all sections. * @throws CouldntLoadDataException Thrown if the list of sections could not be determined. */ protected List<Section> loadSections() throws CouldntLoadDataException { final Map<Section, Integer> sectionToComment = provider.loadSections(module); final Map<Section, Integer> sectionWithCommemnt = Maps.filterValues(sectionToComment, new Predicate<Integer>() { @Override public boolean apply(final Integer commentId) { return commentId != null; } }); final CommentManager manager = CommentManager.get(provider); final HashMap<Integer, ArrayList<IComment>> typeInstanceTocomments = provider.loadMultipleCommentsById(sectionWithCommemnt.values()); for (final Entry<Section, Integer> entry : sectionWithCommemnt.entrySet()) { manager .initializeSectionComment(entry.getKey(), typeInstanceTocomments.get(entry.getValue())); } return Lists.newArrayList(sectionToComment.keySet()); }
Example 7
Source File: GuavaTest.java From java-study with Apache License 2.0 | 6 votes |
/** * Map的过滤 * 例如:查找该集合中大于20岁的人 */ private static void filtedMap(){ Map<String,Integer> map=new HashMap<String,Integer>(); map.put("张三", 19); map.put("李四", 20); map.put("王五", 21); Map<String,Integer> filtedmap =Maps.filterValues(map, new Predicate<Integer>(){ @Override public boolean apply(Integer age) { return age>20; } }); System.out.println("Map:"+map); //Map:{张三=19, 李四=20, 王五=21} System.out.println("filtedmap:"+filtedmap);//filtedmap:{王五=21} }
Example 8
Source File: FilterMapByValues.java From levelup-java-examples with Apache License 2.0 | 6 votes |
@Test public void filter_map_by_values_guava () { Predicate<String> endsWithR = new Predicate<String>() { @Override public boolean apply(String input) { return input.endsWith("r"); } }; Map<Integer, String> torskMeetings = Maps.filterValues(MONTHS, endsWithR); logger.info(torskMeetings); assertThat(torskMeetings.values(), contains( "September", "October", "November", "December")); }
Example 9
Source File: SiegeService.java From aion-germany with GNU General Public License v3.0 | 5 votes |
public Map<Integer, ArtifactLocation> getFortressArtifacts() { return Maps.filterValues(artifacts, new Predicate<ArtifactLocation>() { @Override public boolean apply(@Nullable ArtifactLocation input) { return input != null && input.getOwningFortress() != null; } }); }
Example 10
Source File: Utils.java From cloudstack with Apache License 2.0 | 5 votes |
public static <K, V> Map getImmutableMap(Map<K, V> map) { Map<K, V> filteredMap = Maps.filterValues(map, new Predicate<V>() { public boolean apply(final V input) { return input != null; } }); return ImmutableMap.<K, V>builder().putAll(filteredMap).build(); }
Example 11
Source File: TaskQueueHelper.java From nomulus with Apache License 2.0 | 5 votes |
public Map<String, Object> toMap() { Map<String, Object> builder = new HashMap<>(); builder.put("taskName", taskName); builder.put("url", url); builder.put("method", method); builder.put("headers", headers.asMap()); builder.put("params", params.asMap()); builder.put("payload", payload); builder.put("tag", tag); builder.put("etaDelta", etaDelta); builder.put("etaDeltaLowerBound", etaDeltaLowerBound); builder.put("etaDeltaUpperBound", etaDeltaUpperBound); return Maps.filterValues(builder, not(in(asList(null, "", Collections.EMPTY_MAP)))); }
Example 12
Source File: MySQL5EventItemsDAO.java From aion-germany with GNU General Public License v3.0 | 5 votes |
@Override public void storeItems(Player player) { // player.clearItemMaxThisCount(); deleteItems(player); 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); } }
Example 13
Source File: CounterDataProvider.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private @Nullable Collection<IYModel> internalFetch(ITmfStateSystem ss, Map<String, Object> fetchParameters, @Nullable IProgressMonitor monitor) throws StateSystemDisposedException { SelectedCounterQueryFilter filter = createCounterQuery(fetchParameters); if (filter == null) { return null; } long stateSystemEndTime = ss.getCurrentEndTime(); Collection<Long> times = extractRequestedTimes(ss, filter, stateSystemEndTime); Map<Long, Integer> entries = Maps.filterValues(getSelectedEntries(filter), q -> ss.getSubAttributes(q, false).isEmpty()); TreeMultimap<Integer, ITmfStateInterval> countersIntervals = TreeMultimap.create(Comparator.naturalOrder(), Comparator.comparingLong(ITmfStateInterval::getStartTime)); Iterable<@NonNull ITmfStateInterval> query2d = ss.query2D(entries.values(), times); for (ITmfStateInterval interval : query2d) { if (monitor != null && monitor.isCanceled()) { return null; } countersIntervals.put(interval.getAttribute(), interval); } ImmutableList.Builder<IYModel> ySeries = ImmutableList.builder(); for (Entry<Long, Integer> entry : entries.entrySet()) { if (monitor != null && monitor.isCanceled()) { return null; } int quark = entry.getValue(); double[] yValues = buildYValues(countersIntervals.get(quark), filter); String seriesName = getTrace().getName() + '/' + ss.getFullAttributePath(quark); ySeries.add(new YModel(entry.getKey(), seriesName, yValues)); } return ySeries.build(); }
Example 14
Source File: Eth1DataCache.java From teku with Apache License 2.0 | 5 votes |
private NavigableMap<UnsignedLong, Eth1Data> getVotesToConsider( final UnsignedLong slot, final UnsignedLong genesisTime, final Eth1Data dataFromState) { return Maps.filterValues( eth1ChainCache.subMap( eth1VotingPeriod.getSpecRangeLowerBound(slot, genesisTime), true, eth1VotingPeriod.getSpecRangeUpperBound(slot, genesisTime), true), eth1Data -> eth1Data.getDeposit_count().compareTo(dataFromState.getDeposit_count()) >= 0); }
Example 15
Source File: MySQL5PlayerCooldownsDAO.java From aion-germany with GNU General Public License v3.0 | 5 votes |
@Override public void storePlayerCooldowns(final Player player) { deletePlayerCooldowns(player); 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); } } }
Example 16
Source File: JunctionTreeLinkedDeBruijnGraph.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
@VisibleForTesting // Test method for returning all existing junction trees. public Map<MultiDeBruijnVertex, ThreadingTree> getReadThreadingJunctionTrees(boolean pruned) { return pruned ? Maps.filterValues( Collections.unmodifiableMap(readThreadingJunctionTrees), n -> n.isEmptyTree()) : Collections.unmodifiableMap(readThreadingJunctionTrees); }
Example 17
Source File: JunctionTreeLinkedDeBruijnGraph.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
private void pruneNode(final int threshold) { childrenNodes = Maps.filterValues( childrenNodes, node -> node.getEvidenceCount() >= threshold); childrenNodes.forEach((edge, node) -> node.pruneNode(threshold)); }
Example 18
Source File: BlazeIdeInterfaceState.java From intellij with Apache License 2.0 | 4 votes |
public BlazeIdeInterfaceState filter(Predicate<TargetKey> targetsToKeep) { BiMap<String, TargetKey> filteredBiMap = Maps.filterValues(ideInfoFileToTargetKey, targetsToKeep::test); return new BlazeIdeInterfaceState( Maps.filterKeys(ideInfoFileState, filteredBiMap::containsKey), filteredBiMap); }
Example 19
Source File: MySQL5ItemCooldownsDAO.java From aion-germany with GNU General Public License v3.0 | 4 votes |
@Override public void storeItemCooldowns(Player player) { deleteItemCooldowns(player); 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); } }
Example 20
Source File: JunctionTreeLinkedDeBruijnGraph.java From gatk with BSD 3-Clause "New" or "Revised" License | 2 votes |
/** * Traverse all of the junction trees in the graph and remove branches supported by < minimumEdgeWeight edges recursively. * This will also handle pruning of trees that are uninformative (i.e. empty roots). * * @param minimumEdgeWeight minimum edge weight below which branches are removed */ public void pruneJunctionTrees(final int minimumEdgeWeight) { readThreadingJunctionTrees.forEach((key, value) -> value.getRootNode().pruneNode(minimumEdgeWeight)); readThreadingJunctionTrees = Maps.filterValues( readThreadingJunctionTrees, ThreadingTree::isEmptyTree); }