Example usage for com.google.common.collect Maps transformValues

List of usage examples for com.google.common.collect Maps transformValues

Introduction

In this page you can find the example usage for com.google.common.collect Maps transformValues.

Prototype

@GwtIncompatible("NavigableMap")
public static <K, V1, V2> NavigableMap<K, V2> transformValues(NavigableMap<K, V1> fromMap,
        Function<? super V1, V2> function) 

Source Link

Document

Returns a view of a navigable map where each value is transformed by a function.

Usage

From source file:org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataTreeShard.java

@VisibleForTesting
Map<DOMDataTreeIdentifier, DOMDataTreeShard> getChildShards() {
    return ImmutableMap.copyOf(Maps.transformValues(childShards, ChildShardContext::getShard));
}

From source file:com.eucalyptus.auth.Permissions.java

public static Map<String, String> evaluateHostKeys() throws AuthException {
    try {// ww  w.  j a  va 2s  .c om
        return Maps.transformValues(Keys.getKeyInstances(Key.EvaluationConstraint.ReceivingHost), Keys.value());
    } catch (RuntimeException e) {
        throw Exceptions.rethrow(e, AuthException.class);
    }
}

From source file:io.druid.server.http.InfoResource.java

@GET
@Path("/rules")
@Produces("application/json")
public Response getRules() {
    // FUGLY, backwards compatibility
    // This will def. be removed as part of the next release
    return Response.ok()
            .entity(Maps.transformValues(databaseRuleManager.getAllRules(), new Function<List<Rule>, Object>() {
                @Override/*  w  w  w  .ja  va 2  s  .co m*/
                public Object apply(List<Rule> rules) {
                    return Lists.transform(rules, new Function<Rule, Object>() {
                        @Override
                        public Object apply(Rule rule) {
                            if (rule instanceof LoadRule) {
                                Map<String, Object> newRule = jsonMapper.convertValue(rule,
                                        new TypeReference<Map<String, Object>>() {
                                        });
                                Set<String> tiers = Sets
                                        .newHashSet(((LoadRule) rule).getTieredReplicants().keySet());
                                tiers.remove(DruidServer.DEFAULT_TIER);
                                String tier = DruidServer.DEFAULT_TIER;
                                if (!tiers.isEmpty()) {
                                    tier = tiers.iterator().next();
                                }

                                newRule.put("tier", tier);
                                newRule.put("replicants", ((LoadRule) rule).getNumReplicants(tier));

                                return newRule;
                            }
                            return rule;
                        }
                    });
                }
            })).build();
}

From source file:ninja.leaping.permissionsex.backend.memory.MemorySubjectData.java

@Override
public Map<Set<Entry<String, String>>, List<Entry<String, String>>> getAllParents() {
    return Maps.filterValues(
            Maps.transformValues(contexts,
                    dataEntry -> dataEntry == null ? null
                            : dataEntry.parents == null ? null
                                    : Lists.transform(dataEntry.parents, Util::subjectFromString)),
            v -> v != null);//from w w  w .ja va  2  s. co  m
}

From source file:ninja.leaping.permissionsex.backend.memory.MemoryOptionSubjectData.java

@Override
public ImmutableOptionSubjectData clearPermissions() {
    if (this.contexts.isEmpty()) {
        return this;
    }/*from ww w  .  j av a 2s. c  o  m*/

    Map<Set<Entry<String, String>>, DataEntry> newValue = Maps.transformValues(this.contexts,
            new Function<DataEntry, DataEntry>() {
                @Nullable
                @Override
                public DataEntry apply(@Nullable DataEntry dataEntry) {
                    return dataEntry == null ? null : dataEntry.withoutPermissions();
                }
            });
    return newData(newValue);
}

From source file:org.graylog2.security.ldap.LdapSettingsImpl.java

@Nonnull
@SuppressWarnings("unchecked")
@Override/*from w w w .j  a  va2  s  .c  om*/
public Map<String, String> getGroupMapping() {
    final BasicDBList groupMappingList = (BasicDBList) fields.get(GROUP_MAPPING_LIST);
    final Map<String, String> groupMapping;

    if (groupMappingList == null) {
        // pre-2.0 storage format, convert after read
        // should actually have been converted during start, but let's play safe here
        groupMapping = (Map<String, String>) fields.get(GROUP_MAPPING);
    } else {
        groupMapping = Maps.newHashMapWithExpectedSize(groupMappingList.size());
        for (Object entry : groupMappingList) {
            final DBObject field = (DBObject) entry;

            groupMapping.put((String) field.get(LDAP_GROUP_MAPPING_NAMEKEY),
                    (String) field.get(LDAP_GROUP_MAPPING_ROLEKEY));
        }
    }
    if (groupMapping == null || groupMapping.isEmpty()) {
        return Collections.emptyMap();
    } else {
        // we store role ids, but the outside world uses role names to identify them
        try {
            final Map<String, Role> idToRole = roleService.loadAllIdMap();
            return Maps.newHashMap(Maps.transformValues(groupMapping, Roles.roleIdToNameFunction(idToRole)));
        } catch (NotFoundException e) {
            LOG.error("Unable to load role mapping");
            return Collections.emptyMap();
        }
    }
}

From source file:ninja.leaping.permissionsex.backend.sql.SqlSubjectData.java

@Override
public Map<Set<Entry<String, String>>, Integer> getAllDefaultValues() {
    return Maps.filterValues(Maps.transformValues(segments,
            dataEntry -> dataEntry == null ? null : dataEntry.getPermissionDefault()), v -> v != null);
}

From source file:com.facebook.buck.features.go.GoTestDescription.java

@Override
public BuildRule createBuildRule(BuildRuleCreationContextWithTargetGraph context, BuildTarget buildTarget,
        BuildRuleParams params, GoTestDescriptionArg args) {
    GoPlatform platform = GoDescriptors.getPlatformForRule(getGoToolchain(), this.goBuckConfig, buildTarget,
            args);/*from   w  w w.j a v  a  2  s .  c  om*/

    ActionGraphBuilder graphBuilder = context.getActionGraphBuilder();
    SourcePathRuleFinder ruleFinder = new SourcePathRuleFinder(graphBuilder);
    SourcePathResolver pathResolver = DefaultSourcePathResolver.from(ruleFinder);
    ProjectFilesystem projectFilesystem = context.getProjectFilesystem();

    GoTestCoverStep.Mode coverageMode;
    ImmutableSortedSet.Builder<BuildRule> extraDeps = ImmutableSortedSet.naturalOrder();
    ImmutableSet.Builder<SourcePath> srcs;
    ImmutableMap<String, Path> coverVariables;

    ImmutableSet.Builder<SourcePath> rawSrcs = ImmutableSet.builder();
    rawSrcs.addAll(args.getSrcs());
    if (args.getLibrary().isPresent()) {
        GoLibraryDescriptionArg libraryArg = graphBuilder
                .requireMetadata(args.getLibrary().get(), GoLibraryDescriptionArg.class).get();

        rawSrcs.addAll(libraryArg.getSrcs());
    }
    if (args.getCoverageMode().isPresent()) {
        coverageMode = args.getCoverageMode().get();
        GoTestCoverStep.Mode coverage = coverageMode;

        GoTestCoverSource coverSource = (GoTestCoverSource) graphBuilder.computeIfAbsent(
                buildTarget.withAppendedFlavors(InternalFlavor.of("gen-cover")),
                target -> new GoTestCoverSource(target, projectFilesystem, ruleFinder, pathResolver, platform,
                        rawSrcs.build(), platform.getCover(), coverage));

        coverVariables = coverSource.getVariables();
        srcs = ImmutableSet.builder();
        srcs.addAll(coverSource.getCoveredSources()).addAll(coverSource.getTestSources());
        extraDeps.add(coverSource);
    } else {
        srcs = rawSrcs;
        coverVariables = ImmutableMap.of();
        coverageMode = GoTestCoverStep.Mode.NONE;
    }

    if (buildTarget.getFlavors().contains(TEST_LIBRARY_FLAVOR)) {
        return createTestLibrary(buildTarget, projectFilesystem,
                params.copyAppendingExtraDeps(extraDeps.build()), graphBuilder, srcs.build(), args, platform);
    }

    GoBinary testMain = createTestMainRule(buildTarget, projectFilesystem,
            params.copyAppendingExtraDeps(extraDeps.build()), graphBuilder, srcs.build(), coverVariables,
            coverageMode, args, platform);
    graphBuilder.addToIndex(testMain);

    StringWithMacrosConverter macrosConverter = StringWithMacrosConverter.builder().setBuildTarget(buildTarget)
            .setCellPathResolver(context.getCellPathResolver()).setExpanders(MACRO_EXPANDERS).build();

    return new GoTest(buildTarget, projectFilesystem,
            params.withDeclaredDeps(ImmutableSortedSet.of(testMain)).withoutExtraDeps(), testMain,
            args.getLabels(), args.getContacts(),
            args.getTestRuleTimeoutMs().map(Optional::of).orElse(
                    goBuckConfig.getDelegate().getView(TestBuckConfig.class).getDefaultTestRuleTimeoutMs()),
            ImmutableMap
                    .copyOf(Maps.transformValues(args.getEnv(), x -> macrosConverter.convert(x, graphBuilder))),
            args.getRunTestSeparately(), args.getResources(), coverageMode);
}

From source file:com.google.devtools.build.skyframe.AbstractSkyFunctionEnvironment.java

@Override
public <E1 extends Exception, E2 extends Exception, E3 extends Exception, E4 extends Exception> Map<SkyKey, ValueOrException4<E1, E2, E3, E4>> getValuesOrThrow(
        Iterable<SkyKey> depKeys, Class<E1> exceptionClass1, Class<E2> exceptionClass2,
        Class<E3> exceptionClass3, Class<E4> exceptionClass4) throws InterruptedException {
    return Maps.transformValues(
            getValuesOrThrow(depKeys, exceptionClass1, exceptionClass2, exceptionClass3, exceptionClass4,
                    BottomException.class),
            makeSafeDowncastToVOE4Function(exceptionClass1, exceptionClass2, exceptionClass3, exceptionClass4));
}

From source file:org.sosy_lab.java_smt.basicimpl.FormulaCreator.java

/**
 * Wrapper for {@link #extractVariablesAndUFs(Formula, boolean)} which unwraps both input and
 * output.//from  w ww.j  av a 2  s.  c om
 */
public Map<String, TFormulaInfo> extractVariablesAndUFs(final TFormulaInfo pFormula, final boolean extractUFs) {
    return Maps.transformValues(extractVariablesAndUFs(encapsulateWithTypeOf(pFormula), extractUFs),
            this::extractInfo);
}