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

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

Introduction

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

Prototype

public static <K, V> ImmutableMap<K, V> uniqueIndex(Iterator<V> values, Function<? super V, K> keyFunction) 

Source Link

Document

Returns a map with the given values , indexed by keys derived from those values.

Usage

From source file:org.sonar.server.computation.step.FeedComponentsCacheStep.java

private Map<String, ComponentDto> componentDtosByKey(List<ComponentDto> components) {
    return Maps.uniqueIndex(components, new NonNullInputFunction<ComponentDto, String>() {
        @Override/* w w w .j  ava2s  .  co m*/
        public String doApply(ComponentDto input) {
            return input.key();
        }
    });
}

From source file:de.metas.ui.web.material.cockpit.MaterialCockpitRowRepository.java

public IRowsData<MaterialCockpitRow> createRowsData(@NonNull final List<DocumentFilter> filters) {
    return new IRowsData<MaterialCockpitRow>() {
        private final ExtendedMemorizingSupplier<List<MaterialCockpitRow>> topLevelRows = //
                ExtendedMemorizingSupplier.of(() -> retrieveRows(filters));

        @Override//ww  w. j a  v  a2  s. c om
        public Map<DocumentId, MaterialCockpitRow> getDocumentId2TopLevelRows() {
            return Maps.uniqueIndex(topLevelRows.get(), row -> row.getId());
        }

        @Override
        public DocumentIdsSelection getDocumentIdsToInvalidate(
                @NonNull final TableRecordReferenceSet recordRefs) {
            final TableRecordReferenceSet recordRefsEligible = recordRefs
                    .filter(recordRef -> isEligibleRecordRef(recordRef));
            if (recordRefsEligible.isEmpty()) {
                return DocumentIdsSelection.EMPTY;
            }

            return getAllRows().stream().filter(row -> isRowMatching(row, recordRefsEligible))
                    .map(MaterialCockpitRow::getId).collect(DocumentIdsSelection.toDocumentIdsSelection());
        }

        @Override
        public void invalidateAll() {
            topLevelRows.forget();
        }
    };
}

From source file:org.sonar.server.test.ws.CoveredFilesAction.java

private Map<String, ComponentDto> buildComponentsByUuid(List<CoveredFileDoc> coveredFiles) {
    List<String> sourceFileUuids = Lists.transform(coveredFiles, new CoveredFileToFileUuidFunction());
    List<ComponentDto> components;
    try (DbSession dbSession = dbClient.openSession(false)) {
        components = dbClient.componentDao().selectByUuids(dbSession, sourceFileUuids);
    }//from w w w . j  a  v a  2 s.com
    return Maps.uniqueIndex(components, ComponentDto::uuid);
}

From source file:domper.config.ConfigEditorActivity.java

private Map<String, RecordItem<?>> extractRecordItems(Object configObject) {
    return Maps.uniqueIndex(RecordItemExtractor.extract(configObject), recordItemName);
}

From source file:fr.xebia.training.troubleshooting.TroubleshootingTrainingInfrastructureCreator.java

public void generateDocs() {
    Filter filter = new Filter("tag:TrainingSession", Lists.newArrayList("Troubleshooting"));
    List<Reservation> reservations = ec2.describeInstances(new DescribeInstancesRequest().withFilters(filter))
            .getReservations();/*from  w w w . ja v  a2 s.  c om*/
    Iterable<Instance> instances = AmazonAwsUtils.toEc2Instances(reservations);

    Iterable<Instance> runningInstances = Iterables.filter(instances,
            AmazonAwsUtils.PREDICATE_RUNNING_OR_PENDING_INSTANCE);
    runningInstances = AmazonAwsUtils.awaitForEc2Instances(runningInstances, ec2);

    Map<String, Instance> runningInstancesByInstanceId = Maps.uniqueIndex(runningInstances,
            AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID);

    List<String> runningInstanceIds = Lists.newArrayList(
            Iterables.transform(runningInstances, AmazonAwsFunctions.EC2_INSTANCE_TO_INSTANCE_ID));

    List<TagDescription> tags = ec2
            .describeTags(new DescribeTagsRequest().withFilters(new Filter("resource-id", runningInstanceIds)))
            .getTags();
    Map<String, Map<String, String>> tagsByInstanceId = new MapMaker()
            .makeComputingMap(new Function<String, Map<String, String>>() {
                @Override
                public Map<String, String> apply(String instanceId) {
                    return Maps.newHashMap();
                }
            });

    for (TagDescription tag : tags) {
        tagsByInstanceId.get(tag.getResourceId()).put(tag.getKey(), tag.getValue());
    }

    Map<String, Map<String, Object>> tomcatTagsPerTeamIdentifier = Maps.newHashMap();

    for (Map.Entry<String, Map<String, String>> entry : tagsByInstanceId.entrySet()) {
        String instanceId = entry.getKey();
        Map<String, String> instanceTags = entry.getValue();

        String teamIdentifier = instanceTags.get("TeamIdentifier");
        Instance tomcatInstance = runningInstancesByInstanceId.get(instanceId);

        Map<String, Object> tomcatTags = Maps.newHashMap();
        tomcatTags.putAll(instanceTags);
        tomcatTags.put("PublicDnsName", tomcatInstance.getPublicDnsName());
        tomcatTags.put("Instance", tomcatInstance);

        tomcatTagsPerTeamIdentifier.put(teamIdentifier, tomcatTags);
    }

    Map<String, Object> rootMap = Maps.newHashMap();
    rootMap.put("infrastructures", tomcatTagsPerTeamIdentifier);
    String wikiPage = FreemarkerUtils.generate(rootMap, "/fr/xebia/training/troubleshooting/wiki-page.ftl");
    System.out.println(wikiPage);
}

From source file:ch.ethz.system.mt.tpch.TpchTable.java

private TpchTable(String tableName, TpchColumn<E>[] columns) {
    this.tableName = tableName;
    this.columns = ImmutableList.copyOf(columns);
    this.columnsByName = Maps.uniqueIndex(this.columns, columnNameGetter());
}

From source file:de.metas.ui.web.view.ViewResult.java

/**+
 * View and loaded page constructor/* w ww. ja  v a2 s .  com*/
 */
@Builder
private ViewResult(@NonNull final IView view, @NonNull final Integer firstRow,
        @NonNull final Integer pageLength, @NonNull final List<DocumentQueryOrderBy> orderBys,
        @Nullable final List<DocumentId> rowIds, @Nullable final List<? extends IViewRow> rows,
        @Nullable final List<ViewResultColumn> columnInfos) {
    this.viewId = view.getViewId();
    this.profileId = view.getProfileId();
    this.parentViewId = view.getParentViewId();
    this.viewDescription = view.getDescription();
    this.size = view.size();
    this.queryLimit = view.getQueryLimit();
    this.queryLimitHit = view.isQueryLimitHit();

    stickyFilters = ImmutableList.copyOf(view.getStickyFilters());
    filters = ImmutableList.copyOf(view.getFilters());
    this.orderBys = ImmutableList.copyOf(orderBys);

    //
    // Page
    if (rowIds == null && rows == null) {
        throw new IllegalArgumentException("rowIds or rows shall not be null");
    }
    this.firstRow = firstRow;
    this.pageLength = pageLength;
    this.rowIds = rowIds != null ? ImmutableList.copyOf(rowIds) : null;
    this.page = rows != null ? ImmutableList.copyOf(rows) : null;
    this.columnInfosByFieldName = columnInfos != null
            ? Maps.uniqueIndex(columnInfos, ViewResultColumn::getFieldName)
            : ImmutableMap.of();
}

From source file:org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer.java

public NetconfMessageTransformer(final SchemaContext schemaContext, final boolean strictParsing,
        final BaseSchema baseSchema) {
    this.counter = new MessageCounter();
    this.schemaContext = schemaContext;
    parserFactory = DomToNormalizedNodeParserFactory.getInstance(XmlUtils.DEFAULT_XML_CODEC_PROVIDER,
            schemaContext, strictParsing);
    mappedRpcs = Maps.uniqueIndex(schemaContext.getOperations(), QNAME_FUNCTION);
    mappedNotifications = Multimaps.index(schemaContext.getNotifications(), QNAME_NOREV_FUNCTION);
    this.baseSchema = baseSchema;
}

From source file:org.pentaho.di.trans.dataservice.validation.DataServiceStepValidation.java

private Map<String, StepMeta> stepMetaMap(TransMeta transMeta) {
    return Maps.uniqueIndex(transMeta.getSteps(), new Function<StepMeta, String>() {
        @Override// www . j  a  va2 s .  c  o  m
        public String apply(StepMeta stepMeta) {
            return stepMeta.getName();
        }
    });
}

From source file:org.sonar.server.qualityprofile.ws.QProfileCompareAction.java

@Override
public void handle(Request request, Response response) throws Exception {
    String leftKey = request.mandatoryParam(PARAM_LEFT_KEY);
    String rightKey = request.mandatoryParam(PARAM_RIGHT_KEY);

    QProfileComparisonResult result = comparator.compare(leftKey, rightKey);

    List<Rule> referencedRules = ruleService.getByKeys(result.collectRuleKeys());
    Map<RuleKey, Rule> rulesByKey = Maps.uniqueIndex(referencedRules,
            new NonNullInputFunction<Rule, RuleKey>() {
                @Override/*from   ww  w. j a  v a  2  s  .co  m*/
                protected RuleKey doApply(Rule input) {
                    return input.key();
                }
            });

    writeResult(response.newJsonWriter(), result, rulesByKey);
}