com.google.common.collect.Maps#filterValues ( )源码实例Demo

下面列出了com.google.common.collect.Maps#filterValues ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xian   文件: PathChildrenCache.java
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);
}
 
源代码2 项目: levelup-java-examples   文件: FilterMapByValues.java
@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"));
}
 
源代码3 项目: java-study   文件: GuavaTest.java
/**
 * 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}
}
 
源代码4 项目: binnavi   文件: SectionContainerBackend.java
/**
 * 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());
}
 
源代码5 项目: proctor   文件: InMemoryProctorStore.java
@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()
    );
}
 
源代码6 项目: pinlater   文件: PinLaterRedisBackend.java
@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())];
}
 
源代码7 项目: proctor   文件: TestUnitTestGroupsManager.java
@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());
}
 
源代码8 项目: curator   文件: PathChildrenCache.java
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);
}
 
源代码9 项目: teku   文件: Eth1DataCache.java
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);
}
 
源代码10 项目: aion-germany   文件: MySQL5PlayerCooldownsDAO.java
@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);
		}
	}
}
 
源代码11 项目: aion-germany   文件: MySQL5EventItemsDAO.java
@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);
	}
}
 
源代码12 项目: aion-germany   文件: SiegeService.java
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;
		}
	});
}
 
源代码13 项目: cloudstack   文件: Utils.java
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();
}
 
源代码14 项目: nomulus   文件: TaskQueueHelper.java
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))));
}
 
源代码15 项目: tracecompass   文件: CounterDataProvider.java
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();
}
 
源代码16 项目: aion-germany   文件: MySQL5ItemCooldownsDAO.java
@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);
	}
}
 
源代码17 项目: intellij   文件: BlazeIdeInterfaceState.java
public BlazeIdeInterfaceState filter(Predicate<TargetKey> targetsToKeep) {
  BiMap<String, TargetKey> filteredBiMap =
      Maps.filterValues(ideInfoFileToTargetKey, targetsToKeep::test);
  return new BlazeIdeInterfaceState(
      Maps.filterKeys(ideInfoFileState, filteredBiMap::containsKey), filteredBiMap);
}
 
源代码18 项目: gatk   文件: JunctionTreeLinkedDeBruijnGraph.java
@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);
}
 
源代码19 项目: gatk   文件: JunctionTreeLinkedDeBruijnGraph.java
private void pruneNode(final int threshold) {
    childrenNodes = Maps.filterValues( childrenNodes, node -> node.getEvidenceCount() >= threshold);
    childrenNodes.forEach((edge, node) -> node.pruneNode(threshold));
}
 
源代码20 项目: gatk   文件: JunctionTreeLinkedDeBruijnGraph.java
/**
 * 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);
}