List of usage examples for com.google.common.collect Maps transformEntries
@GwtIncompatible("NavigableMap") public static <K, V1, V2> NavigableMap<K, V2> transformEntries(NavigableMap<K, V1> fromMap, EntryTransformer<? super K, ? super V1, V2> transformer)
From source file:org.onosproject.cluster.impl.MembershipManager.java
@Override public Collection<MembershipGroup> getGroups() { Map<Version, Set<Member>> groups = Maps.newHashMap(); clusterService.getNodes().stream().map(this::toMemberId) .forEach(member -> groups.computeIfAbsent(member.version(), k -> Sets.newHashSet()).add(member)); return Maps.transformEntries(groups, MembershipGroup::new).values(); }
From source file:com.tjackiw.graylog2.plugin.jira.callback.JiraAlarmCallback.java
@Override public Map<String, Object> getAttributes() { return Maps.transformEntries(configuration.getSource(), new Maps.EntryTransformer<String, Object, Object>() { @Override/*from w w w .ja va2 s.c o m*/ public Object transformEntry(String key, Object value) { if (CK_PASSWORD.equals(key)) { return "****"; } return value; } }); }
From source file:com.arcbees.bourseje.server.services.VoteService.java
private Collection<CandidateResult> createResultsFromGroupedVotes( Map<Long, Collection<VoteItem>> groupedVotes) { return Maps.transformEntries(groupedVotes, new Maps.EntryTransformer<Long, Collection<VoteItem>, CandidateResult>() { @Override/*from ww w . ja v a2s.c om*/ public CandidateResult transformEntry(Long candidateId, Collection<VoteItem> voteItems) { return new CandidateResult(candidateId, voteItems.size()); } }).values(); }
From source file:com.shopzilla.hadoop.repl.HadoopREPL.java
protected Map<Call, Command> buildCommandMappings() { final Map<Call, Command> commands = ImmutableMap.<Call, Command>builder() .putAll(new SessionCommandProvider().apply(sessionState)) .putAll(new FSShellCommandProvider().apply(sessionState)).build(); return ImmutableMap.<Call, Command>builder().putAll(commands) .put(call("help", new DeferredStringsCompleter<Map<Call, Command>>(commandMappings, new Function<Map<Call, Command>, TreeSet<String>>() { @Override public TreeSet<String> apply(final Map<Call, Command> calls) { return Sets.newTreeSet(Maps.transformEntries(commandMappings, new Maps.EntryTransformer<Call, Command, String>() { @Override public String transformEntry(final Call key, final Command value) { return key.commandName(); } }).values()); }/*from ww w.ja va 2 s . com*/ })), new Command() { @Override public void execute(final CommandInvocation call, final SessionState sessionState) throws REPL.ExitSignal { if (call.args().length != 1) { sessionState.output("Usage: help [command]"); } else { final String command = call.args()[0]; if (commandMappings.containsKey(call(command))) { final Usage usage = commandMappings.get(call(command)).usage(sessionState); sessionState.output("Displaying help for \"%s\":\n", command); sessionState.outputUsage(usage); } else { sessionState.error("Unknown command \"%s\"", command); } } } @Override public Usage usage(final SessionState sessionState) { return new Usage("help", "Displays help / usage information for the given command ", "<command>"); } }) .build(); }
From source file:com.viadeo.kasper.core.component.event.eventbus.MessageHandler.java
@SuppressWarnings("unused") public void handleMessage(EventMessage eventMessage) { metricRegistry.counter(HANDLE_MESSAGE_COUNT_METRIC).inc(); metricRegistry.histogram(HANDLE_MESSAGE_TIME_METRIC).update(timeTaken(eventMessage)); MDC.setContextMap(Maps.transformEntries(eventMessage.getMetaData(), new Maps.EntryTransformer<String, Object, String>() { @Override/*from w w w .j a v a2 s .com*/ public String transformEntry(String key, Object value) { return String.valueOf(value); } })); try { if (enabledMessageHandling) { eventListener.handle(eventMessage); } } catch (Exception t) { metricRegistry.counter(HANDLE_MESSAGE_ERROR_METRIC).inc(); LOGGER.warn("failed to handle event message by '{}'", eventListener.getClass().getName(), t); throw new MessageHandlerException(eventListener.getClass(), t); } }
From source file:org.apache.james.http.jetty.JettyHttpServer.java
private ServletHandler buildServletHandler(Configuration configuration) { ServletHandler servletHandler = new ServletHandler(); BiConsumer<String, ServletHolder> addServletMapping = (path, servletHolder) -> servletHandler .addServletWithMapping(servletHolder, path); BiConsumer<String, Collection<FilterHolder>> addFilterMappings = (path, filterHolders) -> filterHolders .stream().forEachOrdered(filterHolder -> servletHandler.addFilterWithMapping(filterHolder, path, EnumSet.of(DispatcherType.REQUEST))); Maps.transformEntries(configuration.getMappings(), this::toServletHolder).forEach(addServletMapping); Multimaps.transformEntries(configuration.getFilters(), this::toFilterHolder).asMap() .forEach(addFilterMappings); return servletHandler; }
From source file:com.madvay.tools.android.perf.common.Table.java
public Table<AggregateRow> groupAndAggregate(final String groupByColumn, final String weightColumn, final AggregationType aggregationType) { final RowAdapter<T> adapter = getAdapter(); final boolean groupNumeric = adapter.types .get(adapter.columns.indexOf(groupByColumn)) == RowAdapter.CoerceType.NUMERIC; boolean weightNumeric = adapter.types .get(adapter.columns.indexOf(weightColumn)) == RowAdapter.CoerceType.NUMERIC; ImmutableListMultimap<Object, T> indexed = Multimaps.index(rows, new Function<T, Object>() { @Override// ww w . ja v a 2s . c om public Object apply(T input) { return adapter.get(input, groupByColumn).toString(); } }); Map<Object, Long> map = Maps.transformEntries(Multimaps.asMap(indexed), new Maps.EntryTransformer<Object, List<T>, Long>() { @Override public Long transformEntry(Object key, List<T> value) { switch (aggregationType) { case COUNT: return (long) value.size(); case SUM: { long l = 0; for (T t : value) { l += Long.parseLong(adapter.get(t, weightColumn).toString()); } return l; } case UNIQUE: { Set<String> set = new HashSet<>(); for (T t : value) { set.add(adapter.get(t, weightColumn).toString()); } return (long) set.size(); } } throw new IllegalArgumentException(); } }); List<AggregateRow> newRows = Lists.newArrayList( Iterables.transform(map.entrySet(), new Function<Map.Entry<Object, Long>, AggregateRow>() { @Override public AggregateRow apply(Map.Entry<Object, Long> input) { return new AggregateRow(input.getValue(), input.getKey()); } })); Table<AggregateRow> ret = new Table<AggregateRow>(newRows) { final RowAdapter<AggregateRow> adap = new AggregateRow.Adapter(groupNumeric); @Override public RowAdapter<AggregateRow> getAdapter() { return adap; } }; return ret; }
From source file:org.apache.aurora.scheduler.updater.OneWayJobUpdater.java
/** * Creates a new one-way updater./*from ww w . ja v a2 s. c o m*/ * * @param strategy The strategy to decide which instances to update after a state change. * @param maxFailedInstances Maximum tolerated failures before the update is considered failed. * @param instanceEvaluators Evaluate the state of individual instances, and decide what actions * must be taken to update them. */ OneWayJobUpdater(UpdateStrategy<K> strategy, int maxFailedInstances, Map<K, StateEvaluator<T>> instanceEvaluators) { this.strategy = requireNonNull(strategy); this.maxFailedInstances = maxFailedInstances; requireNonNull(instanceEvaluators); this.instances = ImmutableMap.copyOf(Maps.transformEntries(instanceEvaluators, (key, value) -> new InstanceUpdate<>("Instance " + key, value))); }
From source file:com.google.devtools.build.skyframe.NotifyingGraph.java
@Override public Map<SkyKey, NodeEntry> createIfAbsentBatch(Iterable<SkyKey> keys) { for (SkyKey key : keys) { graphListener.accept(key, EventType.CREATE_IF_ABSENT, Order.BEFORE, null); }//from ww w . j a va 2 s .c om return Maps.transformEntries(getProcessableDelegate().createIfAbsentBatch(keys), wrapEntry); }
From source file:org.kuali.coeus.sys.framework.rule.KcMaintenanceDocumentRuleBase.java
protected boolean verifyOjbRelationships() { final List<DataObjectRelationship> ojbRelationships = getKcPersistenceStructureService() .getRelationshipsTo(getNewBo().getClass()); for (DataObjectRelationship relationship : ojbRelationships) { if (!relationshipDeleteVerificationIgnores().contains(relationship.getParentClass())) { final Map<String, Object> criteria = Maps.transformEntries( relationship.getParentToChildReferences(), new Maps.EntryTransformer<String, String, Object>() { @Override public Object transformEntry(String key, String value) { try { return PropertyUtils.getProperty(getNewBo(), value); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new RuntimeException(e); }//w ww.j av a 2 s .c o m } }); if (getBoService().countMatching(relationship.getParentClass(), criteria) > 0) { getGlobalVariableService().getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, KeyConstants.ERROR_DELETION_BLOCKED); return false; } } } return true; }