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

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

Introduction

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

Prototype

public static <K, V> ImmutableMap<K, V> toMap(Iterator<K> keys, Function<? super K, V> valueFunction) 

Source Link

Document

Returns an immutable map whose keys are the distinct elements of keys and whose value for each key was computed by valueFunction .

Usage

From source file:io.v.baku.toolkit.blessings.BlessingsUtils.java

public static Permissions homogeneousPermissions(final Set<Tag> tags, final AccessList acl) {
    return new Permissions(Maps.toMap(Collections2.transform(tags, Tag::getValue), x -> acl));
}

From source file:org.jamocha.dn.compiler.ecblocks.partition.Partition.java

protected P remove(final S s, final BiFunction<Set<S>, Map<T, S>, P> ctor) {
    assert this.subSets.contains(s);
    final Set<S> subsets = SetReducer.without(this.subSets, s);
    final MapSubtractor<T, S> lookup = MapSubtractor.without(this.lookup,
            Maps.toMap(s.elements.values(), x -> s));
    return ctor.apply(subsets, lookup);
}

From source file:fi.hsl.parkandride.core.service.reporting.MaxUtilizationReportService.java

private Map<Long, Map<LocalDate, FacilityCapacity>> getFacilityCapacityHistory(Set<Long> facilityIds,
        LocalDate startDate, LocalDate endDate) {
    return Maps.toMap(facilityIds, id -> facilityHistoryService.getCapacityHistory(id, startDate, endDate));
}

From source file:com.android.tools.idea.wizard.ImportWizardModuleBuilder.java

protected void addSteps(WizardPath path) {
    Collection<ModuleWizardStep> steps = path.getSteps();
    mySteps.addAll(steps);
    myStepsToPath.putAll(Maps.toMap(steps, Functions.constant(path)));
}

From source file:fi.hsl.parkandride.core.service.reporting.MaxUtilizationReportService.java

private Map<MaxUtilizationReportKey, Integer> getFacilityUnavailableCapacity(ReportContext ctx,
        Map<Long, Map<LocalDate, FacilityCapacity>> capacityHistory) {
    Set<MaxUtilizationReportKeyWithDate> keysForUnavailableDates = capacityHistory.entrySet().stream()
            .flatMap(mappingEntry((id, val) -> val.entrySet().stream().flatMap(
                    mappingEntry((LocalDate date, FacilityCapacity capacity) -> capacity.unavailableCapacities
                            .stream().map((UnavailableCapacity uc) -> {
                                final MaxUtilizationReportKeyWithDate key = new MaxUtilizationReportKeyWithDate();
                                key.targetId = id;
                                key.facility = ctx.facilities.get(id);
                                key.date = date;
                                key.capacityType = uc.capacityType;
                                key.usage = uc.usage;
                                return key;
                            })))))/* w w  w.j av  a  2s.co m*/
            .collect(toSet());

    return Maps.toMap(keysForUnavailableDates, key -> {
        final FacilityCapacity currentCapacities = new FacilityCapacity(ctx.facilities.get(key.targetId));
        return capacityHistory.getOrDefault(key.targetId, emptyMap()).getOrDefault(key.date,
                currentCapacities).unavailableCapacities.stream()
                        .filter(uc -> uc.capacityType == key.capacityType).filter(uc -> uc.usage == key.usage)
                        .map(uc -> uc.capacity).findFirst().orElse(0);
    }).entrySet().stream().map(mappingKey((key, val) -> key.toReportKey())).collect(entriesToMap(Math::max));
}

From source file:eu.lp0.cursus.publish.html.XSLTHTMLGenerator.java

public Map<String, ByteSource> getCodePages() {
    return Maps.toMap(CODE_PAGES, new Function<String, ByteSource>() {
        @Override/*from ww w  . j a  v a 2 s .  c  o  m*/
        @Nullable
        public ByteSource apply(@Nullable String input) {
            return Resources.asByteSource(Resources.getResource(PackageConstants.RESOURCE_PATH + "/" + input)); //$NON-NLS-1$
        }
    });
}

From source file:io.prestosql.sql.planner.iterative.rule.test.PlanBuilder.java

public TopNNode topN(long count, List<Symbol> orderBy, PlanNode source) {
    return new TopNNode(idAllocator.getNextId(), source, count,
            new OrderingScheme(orderBy, Maps.toMap(orderBy, Functions.constant(SortOrder.ASC_NULLS_FIRST))),
            TopNNode.Step.SINGLE);//from  www.  j  a va2  s. co m
}

From source file:edu.mit.streamjit.impl.compiler2.ActorGroup.java

/**
 * Returns a map mapping each input Storage to the set of physical indices
 * read in that Storage during the given ActorGroup iteration.
 * @param iteration the iteration to simulate
 * @return a map of read physical indices
 *//*from   w w  w .ja va2  s .  c o  m*/
public ImmutableMap<Storage, ImmutableSortedSet<Integer>> reads(final int iteration) {
    return Maps.toMap(inputs(), (Storage input) -> reads(input, iteration));
}

From source file:com.b2international.snowowl.snomed.datastore.converter.SnomedConceptConverter.java

@Override
protected SnomedConcept toResource(final SnomedConceptDocument input) {
    final SnomedConcept result = new SnomedConcept();
    result.setStorageKey(input.getStorageKey());
    result.setActive(input.isActive());//from   w w w.j a v a  2 s .co  m
    result.setDefinitionStatus(toDefinitionStatus(input.isPrimitive()));
    result.setEffectiveTime(toEffectiveTime(input.getEffectiveTime()));
    result.setId(input.getId());
    result.setModuleId(input.getModuleId());
    result.setIconId(input.getIconId());
    result.setReleased(input.isReleased());
    result.setSubclassDefinitionStatus(toSubclassDefinitionStatus(input.isExhaustive()));
    result.setScore(input.getScore());

    // XXX: Core reference set information will not be included if the expand option is not set
    if (expand().containsKey(SnomedConcept.Expand.REFERENCE_SET)
            && input.getRefSetStorageKey() != CDOUtils.NO_STORAGE_KEY) {
        result.setReferenceSet(getReferenceSetConverter().toResource(input));
    }

    if (input.getAncestors() != null) {
        result.setAncestorIds(input.getAncestors().toArray());
    }

    if (input.getParents() != null) {
        result.setParentIds(input.getParents().toArray());
    }

    if (input.getStatedParents() != null) {
        result.setStatedParentIds(input.getStatedParents().toArray());
    }

    if (input.getStatedAncestors() != null) {
        result.setStatedAncestorIds(input.getStatedAncestors().toArray());
    }

    if (expand().containsKey(SnomedConcept.Expand.PREFERRED_DESCRIPTIONS)
            || expand().containsKey(SnomedConcept.Expand.PREFERRED_TERM)
            || expand().containsKey(SnomedConcept.Expand.FULLY_SPECIFIED_NAME)) {
        List<SnomedDescription> preferredDescriptions = input.getPreferredDescriptions().stream()
                .map(description -> {
                    SnomedDescription preferredDescription = new SnomedDescription(description.getId());
                    preferredDescription.setStorageKey(description.getStorageKey());
                    preferredDescription.setConceptId(result.getId());
                    preferredDescription.setTerm(description.getTerm());
                    preferredDescription.setTypeId(description.getTypeId());
                    preferredDescription.setAcceptabilityMap(
                            Maps.toMap(description.getLanguageRefSetIds(), any -> Acceptability.PREFERRED));
                    return preferredDescription;
                }).collect(Collectors.toList());
        result.setPreferredDescriptions(new SnomedDescriptions(preferredDescriptions, null, null,
                preferredDescriptions.size(), preferredDescriptions.size()));
    }

    return result;
}

From source file:com.google.api.tools.framework.processors.merger.Merger.java

/**
 * Returns the given config aspects as list of group of aspects in merge dependency order.
 * This performs a 'longest path layering' algorithm by placing aspects at different levels
 * (layers). First place all sink nodes at level-1 and then each node n is placed at level
 * level-p+1, where p is the longest path from n to sink. Aspects in each level are independent of
 * each other and can only depend on aspects in lower levels.
 * Detailed algorithm : 13.3.2 Layer Assignment Algorithms :
 * https://cs.brown.edu/~rt/gdhandbook/chapters/hierarchical.pdf
 *///from ww  w  .j  a  v  a2  s . c o m
private static List<Set<ConfigAspect>> sortForMerge(Iterable<ConfigAspect> aspects) {
    Map<Class<? extends ConfigAspect>, ConfigAspect> aspectsByType = HashBiMap
            .create(Maps.toMap(aspects, new Function<ConfigAspect, Class<? extends ConfigAspect>>() {
                @Override
                public Class<? extends ConfigAspect> apply(ConfigAspect aspect) {
                    return aspect.getClass();
                }
            })).inverse();
    List<Class<? extends ConfigAspect>> visiting = Lists.newArrayList();
    Map<ConfigAspect, Integer> aspectsToLevel = Maps.newLinkedHashMap();
    for (ConfigAspect aspect : aspects) {
        assignLevelToAspect(aspect, aspectsByType, visiting, aspectsToLevel);
    }
    Map<Integer, Set<ConfigAspect>> aspectsByLevel = Maps.newLinkedHashMap();
    for (ConfigAspect aspect : aspectsToLevel.keySet()) {
        Integer aspectLevel = aspectsToLevel.get(aspect);
        if (!aspectsByLevel.containsKey(aspectLevel)) {
            aspectsByLevel.put(aspectLevel, Sets.<ConfigAspect>newLinkedHashSet());
        }
        aspectsByLevel.get(aspectLevel).add(aspect);
    }
    List<Set<ConfigAspect>> aspectListByLevels = Lists.newArrayList();
    for (int level = 1; level <= aspectsByLevel.size(); ++level) {
        aspectListByLevels.add(aspectsByLevel.get(level));
    }
    return aspectListByLevels;
}