List of usage examples for com.google.common.collect Maps filterValues
@CheckReturnValue public static <K, V> BiMap<K, V> filterValues(BiMap<K, V> unfiltered, final Predicate<? super V> valuePredicate)
From source file:com.isotrol.impe3.freemarker.DefaultFreeMarkerService.java
/** * @see com.isotrol.impe3.freemarker.FreeMarkerService#decorateRenderModel(com.isotrol.impe3.api.component.RenderContext, * com.isotrol.impe3.api.component.TemplateModel) *///from www . j a va 2 s. c o m public void decorateRenderModel(RenderContext context, TemplateModel model) { // Img Uri if (!model.containsKey(IMG_URI) && imgUri != null) { model.put("imgUri", FreeMarker.uri(context, imgUri)); } final Map<String, Object> map = Maps.newHashMap(); for (Entry<String, Object> e : Maps.filterValues(model, Predicates.instanceOf(RenderingPhaseObject.class)) .entrySet()) { RenderingPhaseObject rpo = (RenderingPhaseObject) e.getValue(); Object val = rpo.apply(context); map.put(e.getKey(), val); } model.putAll(map); }
From source file:org.apache.bookkeeper.mledger.impl.ManagedLedgerFactoryImpl.java
/** * Helper for getting stats/*from w w w . j a v a 2 s .c o m*/ * * @return */ public Map<String, ManagedLedgerImpl> getManagedLedgers() { // Return a view of already created ledger by filtering futures not yet completed return Maps.filterValues(Maps.transformValues(ledgers, future -> future.getNow(null)), Predicates.notNull()); }
From source file:io.atomix.core.election.impl.DefaultLeaderElectorService.java
@Override public void evict(byte[] id) { try {/*from ww w .j a v a2 s . c om*/ List<LeadershipEvent<byte[]>> changes = Lists.newArrayList(); Set<String> topics = Maps .filterValues(elections, e -> e.candidates().stream().anyMatch(candidate -> Arrays.equals(candidate, id))) .keySet(); topics.forEach(topic -> { Leadership<byte[]> oldLeadership = leadership(topic); elections.compute(topic, (k, v) -> v.evict(id, termCounter(topic)::incrementAndGet)); Leadership<byte[]> newLeadership = leadership(topic); if (!Objects.equal(oldLeadership, newLeadership)) { notifyLeadershipChange(topic, oldLeadership, newLeadership); } }); } catch (Exception e) { getLogger().error("State machine operation failed", e); throw Throwables.propagate(e); } }
From source file:com.cinchapi.concourse.server.storage.temp.Limbo.java
/** * Calculate the browsable view of {@code key} at {@code timestamp} using * prior {@code context} as if it were also a part of the Buffer. * //from w w w . ja v a2 s . co m * @param key * @param timestamp * @param context * @return a possibly empty Map of data */ public Map<TObject, Set<Long>> browse(String key, long timestamp, Map<TObject, Set<Long>> context) { if (timestamp >= getOldestWriteTimestamp()) { for (Iterator<Write> it = iterator(); it.hasNext();) { Write write = it.next(); if (write.getKey().toString().equals(key) && write.getVersion() <= timestamp) { Set<Long> records = context.get(write.getValue().getTObject()); if (records == null) { records = Sets.newLinkedHashSet(); context.put(write.getValue().getTObject(), records); } if (write.getType() == Action.ADD) { records.add(write.getRecord().longValue()); } else { records.remove(write.getRecord().longValue()); } } else if (write.getVersion() > timestamp) { break; } else { continue; } } } return Maps.newTreeMap((SortedMap<TObject, Set<Long>>) Maps.filterValues(context, emptySetFilter)); }
From source file:com.google.cloud.dataflow.sdk.util.KeyedStateCache.java
public void flushTo(Windmill.WorkItemCommitRequest.Builder outputBuilder) throws IOException { // Make sure that we've done lookups for the tag-writes, tag-deletes, and tag-list-deletes. try {//from ww w.j a v a 2 s . c o m tagCache.getAll(localTagUpdates.keySet()); tagListCache.getAll(Maps.filterValues(localTagListUpdates, IS_DELETE_TAG_LIST).keySet()); } catch (ExecutionException e) { Throwables.propagateIfInstanceOf(e.getCause(), IOException.class); throw Throwables.propagate(e.getCause()); } // Flush the local tag and tag list updates to the commit request for (Map.Entry<CodedTupleTag<?>, TagUpdates<?>> update : localTagUpdates.entrySet()) { update.getValue().flushTo(update.getKey(), outputBuilder); } for (Map.Entry<CodedTupleTag<?>, TagListUpdates<?>> update : localTagListUpdates.entrySet()) { update.getValue().flushTo(update.getKey(), outputBuilder); } // Clear the caches and local updates tagCache.invalidateAll(); tagListCache.invalidateAll(); localTagUpdates.clear(); localTagListUpdates.clear(); }
From source file:uk.ac.open.kmi.iserve.discovery.disco.impl.SparqlIndexedLogicConceptMatcher.java
/** * Obtain all the matching resources with the URI of {@code origin} within the range of MatchTypes provided, both inclusive. * * @param origin URI to match/*from w ww . j a va 2 s .c o m*/ * @param minType the minimum MatchType we want to obtain * @param maxType the maximum MatchType we want to obtain * @return a Map containing indexed by the URI of the matching resource and containing the particular {@code MatchResult}. If no * result is found the Map should be empty not null. */ @Override public synchronized Map<URI, MatchResult> listMatchesWithinRange(URI origin, MatchType minType, MatchType maxType) { if (origin == null || minType == null | maxType == null) { return ImmutableMap.of(); } Function<MatchResult, MatchType> getTypeFunction = new Function<MatchResult, MatchType>() { @Override public MatchType apply(@Nullable MatchResult matchResult) { if (matchResult != null) { return matchResult.getMatchType(); } return null; } }; // Get all the matches Map<URI, MatchResult> matches = this.indexedMatches.get(origin); // Return an immutable map out of the filtered view. Drop copyOf to obtain a live view if (matches != null) { return ImmutableMap.copyOf(Maps.filterValues(matches, MatchResultPredicates.withinRange(minType, BoundType.CLOSED, maxType, BoundType.CLOSED))); } else { return ImmutableMap.of(); } }
From source file:io.hops.transaction.context.BaseEntityContext.java
final Collection<Entity> get(Predicate<ContextEntity> pred) { Map<Key, ContextEntity> filtered = Maps.filterValues(contextEntities, pred); Collection<Entity> transformed = Maps.transformValues(filtered, new Function<ContextEntity, Entity>() { @Override//ww w . jav a 2 s . c o m public Entity apply(ContextEntity input) { return input.getEntity(); } }).values(); return Collections2.filter(transformed, Predicates.notNull()); }
From source file:com.blackducksoftware.bdio.model.AbstractModel.java
AbstractModel(Type type, Iterable<ModelField<M, ?>> fields) {
types = ImmutableSet.of(type);
data = Maps.filterValues(new ModelMap<>(self(), fields), Predicates.notNull());
}
From source file:com.isotrol.impe3.core.config.ConfigurationDefinition.java
/** * Returns the required configuration parameters. * @return The required configuration parameters. *//* w ww . ja va 2 s.com*/ public Map<String, Item> getRequiredParameters() { return Maps.filterValues(parameters, IS_REQUIRED); }
From source file:com.b2international.snowowl.snomed.datastore.id.memory.DefaultSnomedIdentifierService.java
@Override public void deprecate(final Set<String> componentIds) { LOGGER.debug("Deprecating {} component IDs.", componentIds.size()); final Map<String, SctId> sctIds = getSctIds(componentIds); final Map<String, SctId> problemSctIds = ImmutableMap.copyOf(Maps.filterValues(sctIds, Predicates.<SctId>not(Predicates.or(SctId::isAssigned, SctId::isPublished, SctId::isDeprecated)))); if (!problemSctIds.isEmpty()) { throw new SctIdStatusException( "Cannot deprecate %s component IDs because they are not assigned, published, or already deprecated.", problemSctIds);/* ww w . j av a 2 s. c o m*/ } final Map<String, SctId> assignedOrPublishedSctIds = ImmutableMap .copyOf(Maps.filterValues(sctIds, Predicates.or(SctId::isAssigned, SctId::isPublished))); for (final SctId sctId : assignedOrPublishedSctIds.values()) { sctId.setStatus(IdentifierStatus.DEPRECATED.getSerializedName()); } putSctIds(assignedOrPublishedSctIds); }