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:io.prestosql.orc.OrcRecordReader.java

public OrcRecordReader(Map<Integer, Type> includedColumns, OrcPredicate predicate, long numberOfRows,
        List<StripeInformation> fileStripes, List<ColumnStatistics> fileStats,
        List<StripeStatistics> stripeStats, OrcDataSource orcDataSource, long splitOffset, long splitLength,
        List<OrcType> types, Optional<OrcDecompressor> decompressor, int rowsInRowGroup,
        DateTimeZone hiveStorageTimeZone, HiveWriterVersion hiveWriterVersion, MetadataReader metadataReader,
        DataSize maxMergeDistance, DataSize tinyStripeThreshold, DataSize maxBlockSize,
        Map<String, Slice> userMetadata, AggregatedMemoryContext systemMemoryUsage,
        Optional<OrcWriteValidation> writeValidation, int initialBatchSize) {
    requireNonNull(includedColumns, "includedColumns is null");
    requireNonNull(predicate, "predicate is null");
    requireNonNull(fileStripes, "fileStripes is null");
    requireNonNull(stripeStats, "stripeStats is null");
    requireNonNull(orcDataSource, "orcDataSource is null");
    requireNonNull(types, "types is null");
    requireNonNull(decompressor, "decompressor is null");
    requireNonNull(hiveStorageTimeZone, "hiveStorageTimeZone is null");
    requireNonNull(userMetadata, "userMetadata is null");
    requireNonNull(systemMemoryUsage, "systemMemoryUsage is null");

    this.includedColumns = requireNonNull(includedColumns, "includedColumns is null");
    this.writeValidation = requireNonNull(writeValidation, "writeValidation is null");
    this.writeChecksumBuilder = writeValidation.map(validation -> createWriteChecksumBuilder(includedColumns));
    this.rowGroupStatisticsValidation = writeValidation
            .map(validation -> validation.createWriteStatisticsBuilder(includedColumns));
    this.stripeStatisticsValidation = writeValidation
            .map(validation -> validation.createWriteStatisticsBuilder(includedColumns));
    this.fileStatisticsValidation = writeValidation
            .map(validation -> validation.createWriteStatisticsBuilder(includedColumns));
    this.systemMemoryUsage = systemMemoryUsage.newAggregatedMemoryContext();

    // reduce the included columns to the set that is also present
    ImmutableSet.Builder<Integer> presentColumns = ImmutableSet.builder();
    ImmutableMap.Builder<Integer, Type> presentColumnsAndTypes = ImmutableMap.builder();
    OrcType root = types.get(0);//from  ww  w.  jav  a 2  s . c  o m
    for (Map.Entry<Integer, Type> entry : includedColumns.entrySet()) {
        // an old file can have less columns since columns can be added
        // after the file was written
        if (entry.getKey() < root.getFieldCount()) {
            presentColumns.add(entry.getKey());
            presentColumnsAndTypes.put(entry.getKey(), entry.getValue());
        }
    }
    this.presentColumns = presentColumns.build();

    this.maxBlockBytes = requireNonNull(maxBlockSize, "maxBlockSize is null").toBytes();

    // it is possible that old versions of orc use 0 to mean there are no row groups
    checkArgument(rowsInRowGroup > 0, "rowsInRowGroup must be greater than zero");

    // sort stripes by file position
    List<StripeInfo> stripeInfos = new ArrayList<>();
    for (int i = 0; i < fileStripes.size(); i++) {
        Optional<StripeStatistics> stats = Optional.empty();
        // ignore all stripe stats if too few or too many
        if (stripeStats.size() == fileStripes.size()) {
            stats = Optional.of(stripeStats.get(i));
        }
        stripeInfos.add(new StripeInfo(fileStripes.get(i), stats));
    }
    stripeInfos.sort(comparingLong(info -> info.getStripe().getOffset()));

    long totalRowCount = 0;
    long fileRowCount = 0;
    ImmutableList.Builder<StripeInformation> stripes = ImmutableList.builder();
    ImmutableList.Builder<Long> stripeFilePositions = ImmutableList.builder();
    if (predicate.matches(numberOfRows, getStatisticsByColumnOrdinal(root, fileStats))) {
        // select stripes that start within the specified split
        for (StripeInfo info : stripeInfos) {
            StripeInformation stripe = info.getStripe();
            if (splitContainsStripe(splitOffset, splitLength, stripe)
                    && isStripeIncluded(root, stripe, info.getStats(), predicate)) {
                stripes.add(stripe);
                stripeFilePositions.add(fileRowCount);
                totalRowCount += stripe.getNumberOfRows();
            }
            fileRowCount += stripe.getNumberOfRows();
        }
    }
    this.totalRowCount = totalRowCount;
    this.stripes = stripes.build();
    this.stripeFilePositions = stripeFilePositions.build();

    orcDataSource = wrapWithCacheIfTinyStripes(orcDataSource, this.stripes, maxMergeDistance,
            tinyStripeThreshold);
    this.orcDataSource = orcDataSource;
    this.splitLength = splitLength;

    this.fileRowCount = stripeInfos.stream().map(StripeInfo::getStripe)
            .mapToLong(StripeInformation::getNumberOfRows).sum();

    this.userMetadata = ImmutableMap.copyOf(Maps.transformValues(userMetadata, Slices::copyOf));

    this.currentStripeSystemMemoryContext = this.systemMemoryUsage.newAggregatedMemoryContext();
    // The streamReadersSystemMemoryContext covers the StreamReader local buffer sizes, plus leaf node StreamReaders'
    // instance sizes who use local buffers. SliceDirectStreamReader's instance size is not counted, because it
    // doesn't have a local buffer. All non-leaf level StreamReaders' (e.g. MapStreamReader, LongStreamReader,
    // ListStreamReader and StructStreamReader) instance sizes were not counted, because calling setBytes() in
    // their constructors is confusing.
    AggregatedMemoryContext streamReadersSystemMemoryContext = this.systemMemoryUsage
            .newAggregatedMemoryContext();

    stripeReader = new StripeReader(orcDataSource, decompressor, types, this.presentColumns, rowsInRowGroup,
            predicate, hiveWriterVersion, metadataReader, writeValidation);

    streamReaders = createStreamReaders(orcDataSource, types, hiveStorageTimeZone,
            presentColumnsAndTypes.build(), streamReadersSystemMemoryContext);
    maxBytesPerCell = new long[streamReaders.length];
    nextBatchSize = initialBatchSize;
}

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

@Override
public <E1 extends Exception, E2 extends Exception> Map<SkyKey, ValueOrException2<E1, E2>> getValuesOrThrow(
        Iterable<SkyKey> depKeys, Class<E1> exceptionClass1, Class<E2> exceptionClass2)
        throws InterruptedException {
    return Maps.transformValues(
            getValuesOrThrow(depKeys, exceptionClass1, exceptionClass2, BottomException.class),
            makeSafeDowncastToVOE2Function(exceptionClass1, exceptionClass2));
}

From source file:org.jclouds.joyent.cloudapi.v6_5.domain.Machine.java

/**
 * Any "extra" metadata this machine has
 * /*from ww  w.j  a v a  2s .com*/
 * <h4>note</h4>
 * 
 * metadata can contain arbitrarily complex values. If the value has structure, you should use
 * {@link #getMetadataAsJsonLiterals}
 * 
 */
public Map<String, String> getMetadata() {
    return Maps.transformValues(metadata, Functions.compose(Functions.toStringFunction(), unquoteString));
}

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

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

    Map<Set<Entry<String, String>>, DataEntry> newValue = Maps.transformValues(this.contexts,
            dataEntry -> dataEntry == null ? null : dataEntry.withoutPermissions());
    return newData(newValue);
}

From source file:org.obm.imap.archive.services.MailboxProcessing.java

private Map<Year, MessageSet> mapByYear(Mailbox mailbox, MessageSet messageSet)
        throws ImapSelectException, MailboxNotFoundException {
    if (messageSet.isEmpty()) {
        return ImmutableMap.of();
    }/*from w w w.jav  a2s  .co m*/

    mailbox.select();
    Year year = guessRangeYear(mailbox, messageSet);
    MessageSet otherYears = searchOutOfYearMessages(mailbox, messageSet, year);

    HashMap<Year, MessageSet> messageSetsByYear = Maps.newHashMap(Maps.transformValues(
            Multimaps.index(mailbox.fetchInternalDate(otherYears), new YearFromInternalDate()).asMap(),
            new CreateMessageSet<>()));
    messageSetsByYear.put(year, messageSet.remove(otherYears));
    return messageSetsByYear;
}

From source file:co.cask.cdap.gateway.handlers.log.MockLogReader.java

private void generateLogs(LoggingContext loggingContext, Id.Program id, ProgramRunStatus runStatus)
        throws InterruptedException {
    String entityId = LoggingContextHelper.getEntityId(loggingContext).getValue();
    RunId runId = null;/*from  w  w  w. j  a va  2  s.  c  o m*/
    Long stopTs = null;
    for (int i = 0; i < MAX; ++i) {
        // Setup run id for event with ids >= 20
        if (i == 20) {
            runId = RunIds.generate(TimeUnit.SECONDS.toMillis(getMockTimeSecs(i)));
        } else if (i == 60 && runStatus != ProgramRunStatus.RUNNING
                && runStatus != ProgramRunStatus.SUSPENDED) {
            // Record stop time for run for 60th event, but still continue to record run in the other logging events.
            stopTs = getMockTimeSecs(i);
        }

        LoggingEvent event = new LoggingEvent("co.cask.Test",
                (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME),
                i % 2 == 0 ? Level.ERROR : Level.WARN, entityId + "<img>-" + i, null, null);
        event.setTimeStamp(TimeUnit.SECONDS.toMillis(getMockTimeSecs(i)));

        // Add runid to logging context
        Map<String, String> tagMap = Maps
                .newHashMap(Maps.transformValues(loggingContext.getSystemTagsMap(), TAG_TO_STRING_FUNCTION));
        if (runId != null && i % 2 == 0) {
            tagMap.put(ApplicationLoggingContext.TAG_RUNID_ID, runId.getId());
        }
        event.setMDCPropertyMap(tagMap);
        logEvents.add(new LogEvent(event, new LogOffset(i, i)));
    }

    long startTs = RunIds.getTime(runId, TimeUnit.SECONDS);
    if (id != null) {
        //noinspection ConstantConditions
        runRecordMap.put(id, new RunRecord(runId.getId(), startTs, stopTs, runStatus, null, null));
        store.setStart(id, runId.getId(), startTs);
        if (stopTs != null) {
            store.setStop(id, runId.getId(), stopTs, runStatus);
        }
    }
}

From source file:com.tyro.oss.pact.spring4.pact.consumer.ReturnExpect.java

private void assertRequestHeaders(HttpHeaders actualHeaders, Object requestObject,
        Map<String, Matcher<? super List<String>>> additionalExpectedHeaders) {
    Map<String, Matcher<? super List<String>>> expectedHeaders = new HashMap<>();

    if (requestObject != null && requestObject instanceof HttpEntity) {
        HttpEntity httpEntity = (HttpEntity) requestObject;
        HttpHeaders headers = httpEntity.getHeaders();
        Map<String, Matcher<List<String>>> stringMatcherMap = Maps.transformValues(headers,
                new Function<List<String>, Matcher<List<String>>>() {
                    @Override//from  w ww . j  av  a  2 s. c o m
                    public Matcher<List<String>> apply(List<String> input) {
                        return is(input);
                    }
                });
        expectedHeaders.putAll(stringMatcherMap);
    }

    expectedHeaders.putAll(additionalExpectedHeaders);

    Set<String> headerNames = expectedHeaders.keySet();
    for (String headerName : headerNames) {
        Matcher<? super List<String>> headerValuesMatcher = expectedHeaders.get(headerName);
        assertThat(format("Contains header %s", headerName), actualHeaders.containsKey(headerName), is(true));
        assertThat(format("'%s' header value fails assertion", headerName), actualHeaders.get(headerName),
                headerValuesMatcher);
    }
}

From source file:org.apache.metron.stellar.common.shell.DefaultStellarShellExecutor.java

/**
 * Returns all variables that have been defined.  Unlike 'getState' this unwraps
 * the VariableResult so that we have the actual value.
 *
 * @return All variables that have been defined.
 *///from w w  w .j  a v a2  s . c o m
public Map<String, Object> getVariables() {
    return Maps.transformValues(variables, (v) -> v.getResult());
}

From source file:com.palantir.atlasdb.keyvalue.partition.map.DynamicPartitionMapImpl.java

/**
 * Convert bare endpoints to EndpointsWithNormalStatus.
 *
 * @param map//from www .  j  av  a 2s .c om
 * @return
 */
private static CycleMap<byte[], EndpointWithStatus> toRing(NavigableMap<byte[], KeyValueEndpoint> map) {
    NavigableMap<byte[], EndpointWithStatus> transformedMap = Maps.transformValues(map,
            new Function<KeyValueEndpoint, EndpointWithStatus>() {
                @Override
                public EndpointWithStatus apply(@Nullable KeyValueEndpoint input) {
                    return new EndpointWithNormalStatus(input);
                }
            });
    // Make a mutable copy of the immutable result.
    return CycleMap.wrap(Maps.newTreeMap(transformedMap));
}

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

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