Example usage for com.google.common.collect Multimaps transformEntries

List of usage examples for com.google.common.collect Multimaps transformEntries

Introduction

In this page you can find the example usage for com.google.common.collect Multimaps transformEntries.

Prototype

public static <K, V1, V2> ListMultimap<K, V2> transformEntries(ListMultimap<K, V1> fromMap,
        EntryTransformer<? super K, ? super V1, V2> transformer) 

Source Link

Document

Returns a view of a ListMultimap whose values are derived from the original multimap's entries.

Usage

From source file:org.zalando.logbook.QueryParameters.java

public QueryParameters obfuscate(final Obfuscator obfuscator) {
    return new QueryParameters(Multimaps.transformEntries(parameters, obfuscator::obfuscate));
}

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:eu.esdihumboldt.hale.common.align.migrate.impl.DefaultCellMigrator.java

@Override
public MutableCell updateCell(final Cell originalCell, final AlignmentMigration migration,
        final MigrationOptions options, SimpleLog log) {
    MutableCell result = new DefaultCell(originalCell);

    SimpleLog cellLog = SimpleLog.all(log, new CellLog(result, CELL_LOG_CATEGORY));

    final AtomicBoolean replacedEntities = new AtomicBoolean(false);

    EntryTransformer<String, Entity, Entity> entityTransformer = new EntryTransformer<String, Entity, Entity>() {

        @Override//w  ww  .j  a  v a2  s .c o m
        public Entity transformEntry(String key, Entity value) {
            EntityDefinition org = value.getDefinition();

            Optional<EntityDefinition> replace = migration.entityReplacement(org, cellLog);

            EntityDefinition entity = replace.orElse(org);
            // FIXME what about null replacements / removals?

            if (!Objects.equal(entity, org)) {
                replacedEntities.set(true);
            }

            if (entity instanceof PropertyEntityDefinition) {
                return new DefaultProperty((PropertyEntityDefinition) entity);
            } else if (entity instanceof TypeEntityDefinition) {
                return new DefaultType((TypeEntityDefinition) entity);
            } else {
                throw new IllegalStateException("Invalid entity definition for creating entity");
            }
        }
    };

    // update source entities
    if (options.updateSource() && result.getSource() != null && !result.getSource().isEmpty()) {
        result.setSource(
                ArrayListMultimap.create(Multimaps.transformEntries(result.getSource(), entityTransformer)));
    }

    // update target entities
    if (options.updateTarget() && result.getTarget() != null && !result.getTarget().isEmpty()) {
        result.setTarget(
                ArrayListMultimap.create(Multimaps.transformEntries(result.getTarget(), entityTransformer)));
    }

    // TODO anything else?

    postUpdateCell(result, options, replacedEntities.get(), cellLog);

    return result;
}

From source file:org.apache.james.rrt.memory.MemoryRecipientRewriteTable.java

@Override
protected Map<String, Mappings> getAllMappingsInternal() throws RecipientRewriteTableException {
    if (mappingEntries.isEmpty()) {
        return null;
    }//from  w ww  .  j  ava 2 s.co  m
    Map<String, Collection<Mappings>> userMappingsMap = Multimaps
            .transformEntries(Multimaps.index(mappingEntries, new Function<InMemoryMappingEntry, String>() {
                public String apply(InMemoryMappingEntry mappingEntry) {
                    return mappingEntry.asKey();
                }
            }), new Maps.EntryTransformer<String, InMemoryMappingEntry, Mappings>() {
                public Mappings transformEntry(String s, InMemoryMappingEntry mappingEntry) {
                    return MappingsImpl.fromRawString(mappingEntry.getMapping());
                }
            }).asMap();
    return Maps.transformEntries(userMappingsMap,
            new Maps.EntryTransformer<String, Collection<Mappings>, Mappings>() {
                public Mappings transformEntry(String s, Collection<Mappings> mappingsList) {
                    Mappings result = MappingsImpl.empty();
                    for (Mappings mappings : mappingsList) {
                        result = result.union(mappings);
                    }
                    return result;
                }
            });
}