Example usage for com.google.common.collect ImmutableMap entrySet

List of usage examples for com.google.common.collect ImmutableMap entrySet

Introduction

In this page you can find the example usage for com.google.common.collect ImmutableMap entrySet.

Prototype

public final ImmutableSet<Entry<K, V>> entrySet() 

Source Link

Usage

From source file:com.facebook.buck.io.WatchmanWatcher.java

@VisibleForTesting
static ImmutableMap<Path, WatchmanQuery> createQueries(ImmutableMap<Path, ProjectWatch> projectWatches,
        ImmutableSet<PathOrGlobMatcher> ignorePaths, Set<Capability> watchmanCapabilities) {
    ImmutableMap.Builder<Path, WatchmanQuery> watchmanQueryBuilder = ImmutableMap.builder();
    for (Map.Entry<Path, ProjectWatch> entry : projectWatches.entrySet()) {
        watchmanQueryBuilder.put(entry.getKey(),
                createQuery(entry.getValue(), ignorePaths, watchmanCapabilities));
    }//w  w w  . j a  v  a 2  s . c  o m
    return watchmanQueryBuilder.build();
}

From source file:com.google.devtools.build.java.turbine.javac.JavacTurbine.java

/** Write the class output from a successful compilation to the output jar. */
private static void emitClassJar(Path outputJar, ImmutableMap<String, OutputFileObject> files)
        throws IOException {
    try (OutputStream fos = Files.newOutputStream(outputJar);
            ZipOutputStream zipOut = new ZipOutputStream(new BufferedOutputStream(fos, ZIPFILE_BUFFER_SIZE))) {
        for (Map.Entry<String, OutputFileObject> entry : files.entrySet()) {
            if (entry.getValue().location != StandardLocation.CLASS_OUTPUT) {
                continue;
            }//from  ww w. java2 s  . c om
            String name = entry.getKey();
            byte[] bytes = entry.getValue().asBytes();
            if (bytes == null) {
                continue;
            }
            if (name.endsWith(".class")) {
                bytes = processBytecode(bytes);
            }
            ZipUtil.storeEntry(name, bytes, zipOut);
        }
    }
}

From source file:com.facebook.buck.python.PythonUtil.java

public static ImmutableMap<Path, SourcePath> toModuleMap(BuildTarget target, SourcePathResolver resolver,
        String parameter, Path baseModule, Iterable<SourceList> inputs) {

    ImmutableMap.Builder<Path, SourcePath> moduleNamesAndSourcePaths = ImmutableMap.builder();

    for (SourceList input : inputs) {
        ImmutableMap<String, SourcePath> namesAndSourcePaths;
        if (input.getUnnamedSources().isPresent()) {
            namesAndSourcePaths = resolver.getSourcePathNames(target, parameter,
                    input.getUnnamedSources().get());
        } else {//from  www  .  java  2  s  .c  o  m
            namesAndSourcePaths = input.getNamedSources().get();
        }
        for (ImmutableMap.Entry<String, SourcePath> entry : namesAndSourcePaths.entrySet()) {
            moduleNamesAndSourcePaths.put(baseModule.resolve(entry.getKey()), entry.getValue());
        }
    }

    return moduleNamesAndSourcePaths.build();
}

From source file:com.google.devtools.build.lib.skyframe.SkylarkImportLookupFunction.java

/**
 * Computes the set of {@link Label}s corresponding to a set of Skylark {@link LoadStatement}s.
 *
 * @param imports a collection of Skylark {@link LoadStatement}s
 * @param containingFileLabel the {@link Label} of the file containing the load statements
 * @return an {@link ImmutableMap} which maps a {@link String} used in the load statement to its
 *     corresponding {@Label}. Returns {@code null} if any Skyframe dependencies are unavailable.
 * @throws SkylarkImportFailedException if no package can be found that contains the loaded file
 *///from  ww w.  j  ava2s  .c om
@Nullable
static ImmutableMap<String, Label> findLabelsForLoadStatements(ImmutableCollection<SkylarkImport> imports,
        Label containingFileLabel, Environment env) throws SkylarkImportFailedException, InterruptedException {
    Preconditions.checkArgument(!containingFileLabel.getPackageIdentifier().getRepository().isDefault());
    Map<String, Label> outputMap = Maps.newHashMapWithExpectedSize(imports.size());

    // Filter relative vs. absolute paths.
    ImmutableSet.Builder<PathFragment> absoluteImportsToLookup = new ImmutableSet.Builder<>();
    // We maintain a multimap from path fragments to their correspond import strings, to cover the
    // (unlikely) case where two distinct import strings generate the same path fragment.
    ImmutableMultimap.Builder<PathFragment, String> pathToImports = new ImmutableMultimap.Builder<>();
    for (SkylarkImport imp : imports) {
        if (imp.hasAbsolutePath()) {
            absoluteImportsToLookup.add(imp.getAbsolutePath());
            pathToImports.put(imp.getAbsolutePath(), imp.getImportString());
        } else {
            outputMap.put(imp.getImportString(), imp.getLabel(containingFileLabel));
        }
    }

    // Look up labels for absolute paths.
    ImmutableMap<PathFragment, Label> absoluteLabels = labelsForAbsoluteImports(absoluteImportsToLookup.build(),
            env);
    if (absoluteLabels == null) {
        return null;
    }
    for (Entry<PathFragment, Label> entry : absoluteLabels.entrySet()) {
        PathFragment currPath = entry.getKey();
        Label currLabel = entry.getValue();
        for (String importString : pathToImports.build().get(currPath)) {
            outputMap.put(importString, currLabel);
        }
    }

    ImmutableMap<String, Label> immutableOutputMap = ImmutableMap.copyOf(outputMap);
    return immutableOutputMap;
}

From source file:com.facebook.buck.features.python.PythonUtil.java

static ImmutableMap<Path, SourcePath> toModuleMap(BuildTarget target, SourcePathResolver resolver,
        String parameter, Path baseModule, Iterable<SourceSortedSet> inputs) {

    ImmutableMap.Builder<Path, SourcePath> moduleNamesAndSourcePaths = ImmutableMap.builder();

    for (SourceSortedSet input : inputs) {
        ImmutableMap<String, SourcePath> namesAndSourcePaths;
        if (input.getUnnamedSources().isPresent()) {
            namesAndSourcePaths = resolver.getSourcePathNames(target, parameter,
                    input.getUnnamedSources().get());
        } else {/*w  ww .  j  a  va2  s .co  m*/
            namesAndSourcePaths = input.getNamedSources().get();
        }
        for (ImmutableMap.Entry<String, SourcePath> entry : namesAndSourcePaths.entrySet()) {
            moduleNamesAndSourcePaths.put(baseModule.resolve(entry.getKey()), entry.getValue());
        }
    }

    return moduleNamesAndSourcePaths.build();
}

From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r12.AndroidNdkCrosstoolsR12.java

private static ImmutableList<DefaultCpuToolchain> getDefaultCpuToolchains(StlImpl stlImpl) {
    // TODO(bazel-team): It would be better to auto-generate this somehow.

    ImmutableMap<String, String> defaultCpus = ImmutableMap.<String, String>builder()
            // arm
            .put("armeabi", "arm-linux-androideabi-4.9").put("armeabi-v7a", "arm-linux-androideabi-4.9-v7a")
            .put("arm64-v8a", "aarch64-linux-android-4.9")

            // mips
            .put("mips", "mipsel-linux-android-4.9").put("mips64", "mips64el-linux-android-4.9")

            // x86
            .put("x86", "x86-4.9").put("x86_64", "x86_64-4.9").build();

    ImmutableList.Builder<DefaultCpuToolchain> defaultCpuToolchains = ImmutableList.builder();
    for (Entry<String, String> defaultCpu : defaultCpus.entrySet()) {
        defaultCpuToolchains.add(DefaultCpuToolchain.newBuilder().setCpu(defaultCpu.getKey())
                .setToolchainIdentifier(defaultCpu.getValue() + "-" + stlImpl.getName()).build());
    }// w  w w. j  a va 2  s. c  o m
    return defaultCpuToolchains.build();
}

From source file:org.apache.rya.indexing.smarturi.SmartUriAdapter.java

/**
 * Serializes an {@link Entity} into a Smart {@link URI}.
 * @param entity the {@link Entity} to serialize into a Smart URI.
 * @return the Smart {@link URI}.// www  .j a  v a2 s . c  om
 * @throws SmartUriException
 */
public static URI serializeUriEntity(final Entity entity) throws SmartUriException {
    final Map<URI, Value> objectMap = new LinkedHashMap<>();

    // Adds the entity's types to the Smart URI
    final List<RyaURI> typeIds = entity.getExplicitTypeIds();
    final Map<RyaURI, String> ryaTypeMap = createTypeMap(typeIds);
    final URI ryaTypeMapUri = createTypeMapUri(typeIds);
    final RyaType valueRyaType = new RyaType(XMLSchema.ANYURI, ryaTypeMapUri.stringValue());
    final Value typeValue = RyaToRdfConversions.convertValue(valueRyaType);
    objectMap.put(RYA_TYPES_URI, typeValue);

    final RyaURI subject = entity.getSubject();
    final Map<RyaURI, ImmutableMap<RyaURI, Property>> typeMap = entity.getProperties();
    for (final Entry<RyaURI, ImmutableMap<RyaURI, Property>> typeEntry : typeMap.entrySet()) {
        final RyaURI type = typeEntry.getKey();
        String typeShortName = ryaTypeMap.get(type);
        typeShortName = typeShortName != null ? typeShortName + "." : "";
        final ImmutableMap<RyaURI, Property> typeProperties = typeEntry.getValue();
        for (final Entry<RyaURI, Property> properties : typeProperties.entrySet()) {
            final RyaURI key = properties.getKey();
            final Property property = properties.getValue();
            final String valueString = property.getValue().getData();
            final RyaType ryaType = property.getValue();

            //final RyaType ryaType = new RyaType(new URIImpl(key.getData()), valueString);

            final Value value = RyaToRdfConversions.convertValue(ryaType);

            String formattedKey = key.getData();
            if (StringUtils.isNotBlank(typeShortName)) {
                formattedKey = addTypePrefixToUri(formattedKey, typeShortName);
            }
            final URI uri = new URIImpl(formattedKey);
            objectMap.put(uri, value);
        }
    }

    return serializeUri(subject, objectMap);
}

From source file:com.google.devtools.build.lib.bazel.rules.android.ndkcrosstools.r13.AndroidNdkCrosstoolsR13.java

private static ImmutableList<DefaultCpuToolchain> getDefaultCpuToolchains(StlImpl stlImpl) {
    // TODO(bazel-team): It would be better to auto-generate this somehow.

    ImmutableMap<String, String> defaultCpus = ImmutableMap.<String, String>builder()
            // arm
            .put("armeabi", "arm-linux-androideabi-clang3.8")
            .put("armeabi-v7a", "arm-linux-androideabi-clang3.8-v7a")
            .put("arm64-v8a", "aarch64-linux-android-clang3.8")

            // mips
            .put("mips", "mipsel-linux-android-clang3.8").put("mips64", "mips64el-linux-android-clang3.8")

            // x86
            .put("x86", "x86-clang3.8").put("x86_64", "x86_64-clang3.8").build();

    ImmutableList.Builder<DefaultCpuToolchain> defaultCpuToolchains = ImmutableList.builder();
    for (Entry<String, String> defaultCpu : defaultCpus.entrySet()) {
        defaultCpuToolchains.add(DefaultCpuToolchain.newBuilder().setCpu(defaultCpu.getKey())
                .setToolchainIdentifier(defaultCpu.getValue() + "-" + stlImpl.getName()).build());
    }/*  w w w.  java  2s.c o  m*/
    return defaultCpuToolchains.build();
}

From source file:org.apache.spark.network.yarn.YarnShuffleServiceMetrics.java

private static void addSnapshotToMetricRecordBuilder(Snapshot snapshot, MetricsRecordBuilder builder,
        String name, String metricType) {

    ImmutableMap<String, Double> doubleValues = ImmutableMap.<String, Double>builder()
            .put("median", snapshot.getMedian()).put("mean", snapshot.getMean())
            .put("75th", snapshot.get75thPercentile()).put("95th", snapshot.get95thPercentile())
            .put("98th", snapshot.get98thPercentile()).put("99th", snapshot.get99thPercentile())
            .put("999th", snapshot.get999thPercentile()).build();

    ImmutableMap<String, Long> longValues = ImmutableMap.<String, Long>builder().put("min", snapshot.getMin())
            .put("max", snapshot.getMax()).build();

    for (Map.Entry<String, Double> entry : doubleValues.entrySet()) {
        builder.addGauge(new ShuffleServiceMetricsInfo(name + "_" + entry.getKey(),
                entry.getKey() + " of " + metricType + " " + name), entry.getValue() / rateFactor);
    }//from   w  ww . ja v  a 2  s .c o m

    for (Map.Entry<String, Long> entry : longValues.entrySet()) {
        builder.addGauge(new ShuffleServiceMetricsInfo(name + "_" + entry.getKey(),
                entry.getKey() + " of " + metricType + " " + name), entry.getValue() / rateFactor);
    }

}

From source file:com.github.rinde.dynurg.Generator.java

private static void generate(RandomGenerator rng, LocationGenerator lg) {
    final List<Long> urgencyLevels = Longs.asList(0, 5, 10, 15, 20, 25, 30, 35, 40, 45);

    final ImmutableMap.Builder<GeneratorSettings, ScenarioGenerator> generatorsMap = ImmutableMap.builder();

    for (final long urg : urgencyLevels) {
        System.out.print("create " + urg);
        final long urgency = urg * 60 * 1000L;
        // The office hours is the period in which new orders are accepted, it
        // is defined as [0,officeHoursLength).
        final long officeHoursLength;
        if (urgency < HALF_DIAG_TT) {
            officeHoursLength = SCENARIO_LENGTH - TWO_DIAG_TT - PICKUP_DURATION - DELIVERY_DURATION;
        } else {//ww  w .  j av a 2 s. c o m
            officeHoursLength = SCENARIO_LENGTH - urgency - ONE_AND_HALF_DIAG_TT - PICKUP_DURATION
                    - DELIVERY_DURATION;
        }

        final double numPeriods = officeHoursLength / (double) INTENSITY_PERIOD;

        final Map<String, String> props = newLinkedHashMap();
        props.put("expected_num_orders", Integer.toString(NUM_ORDERS));
        props.put("time_series", "sine Poisson ");
        props.put("time_series.period", Long.toString(INTENSITY_PERIOD));
        props.put("time_series.num_periods", Double.toString(numPeriods));
        props.put("pickup_duration", Long.toString(PICKUP_DURATION));
        props.put("delivery_duration", Long.toString(DELIVERY_DURATION));
        props.put("width_height", String.format("%1.1fx%1.1f", AREA_WIDTH, AREA_WIDTH));
        final GeneratorSettings sineSettings = new GeneratorSettings(TimeSeriesType.SINE, urg, SCENARIO_LENGTH,
                officeHoursLength, props);

        System.out.print(" non-homogenous Poisson");
        // NON-HOMOGENOUS
        final TimeSeriesGenerator sineTsg = TimeSeries.nonHomogenousPoisson(officeHoursLength,
                IntensityFunctions.sineIntensity().area(NUM_ORDERS / numPeriods).period(INTENSITY_PERIOD)
                        .height(StochasticSuppliers.uniformDouble(-.99, 3d))
                        .phaseShift(StochasticSuppliers.uniformDouble(0, INTENSITY_PERIOD))
                        .buildStochasticSupplier());

        System.out.print(" homogenous Poisson");
        // HOMOGENOUS
        props.put("time_series", "homogenous Poisson");
        props.put("time_series.intensity", Double.toString((double) NUM_ORDERS / (double) officeHoursLength));
        props.remove("time_series.period");
        props.remove("time_series.num_periods");
        final TimeSeriesGenerator homogTsg = TimeSeries.homogenousPoisson(officeHoursLength, NUM_ORDERS);
        final GeneratorSettings homogSettings = new GeneratorSettings(TimeSeriesType.HOMOGENOUS, urg,
                SCENARIO_LENGTH, officeHoursLength, props);

        System.out.print(" normal");
        // NORMAL
        props.put("time_series", "normal");
        props.remove("time_series.intensity");
        final TimeSeriesGenerator normalTsg = TimeSeries.normal(officeHoursLength, NUM_ORDERS, 2.4 * 60 * 1000);
        final GeneratorSettings normalSettings = new GeneratorSettings(TimeSeriesType.NORMAL, urg,
                SCENARIO_LENGTH, officeHoursLength, props);

        System.out.print(" uniform");
        // UNIFORM
        props.put("time_series", "uniform");
        final StochasticSupplier<Double> maxDeviation = StochasticSuppliers.normal().mean(1 * 60 * 1000)
                .std(1 * 60 * 1000).lowerBound(0).upperBound(15d * 60 * 1000).buildDouble();
        final TimeSeriesGenerator uniformTsg = TimeSeries.uniform(officeHoursLength, NUM_ORDERS, maxDeviation);
        final GeneratorSettings uniformSettings = new GeneratorSettings(TimeSeriesType.UNIFORM, urg,
                SCENARIO_LENGTH, officeHoursLength, props);
        System.out.println(".");

        generatorsMap.put(sineSettings, createGenerator(SCENARIO_LENGTH, urgency, sineTsg, lg));
        generatorsMap.put(homogSettings, createGenerator(SCENARIO_LENGTH, urgency, homogTsg, lg));
        generatorsMap.put(normalSettings, createGenerator(SCENARIO_LENGTH, urgency, normalTsg, lg));
        generatorsMap.put(uniformSettings, createGenerator(SCENARIO_LENGTH, urgency, uniformTsg, lg));
    }

    final ImmutableMap<GeneratorSettings, ScenarioGenerator> scenarioGenerators = generatorsMap.build();

    System.out.println("num generators: " + scenarioGenerators.size());
    for (final Entry<GeneratorSettings, ScenarioGenerator> entry : scenarioGenerators.entrySet()) {

        final GeneratorSettings generatorSettings = entry.getKey();
        System.out.println("URGENCY: " + generatorSettings.urgency + " " + generatorSettings.timeSeriesType);

        if (generatorSettings.timeSeriesType == TimeSeriesType.SINE) {
            createScenarios(rng, generatorSettings, entry.getValue(), .0, .46, 10);
        } else if (generatorSettings.timeSeriesType == TimeSeriesType.HOMOGENOUS) {
            createScenarios(rng, generatorSettings, entry.getValue(), .49, .56, 2);
        } else if (generatorSettings.timeSeriesType == TimeSeriesType.NORMAL) {
            createScenarios(rng, generatorSettings, entry.getValue(), .59, .66, 2);
        } else if (generatorSettings.timeSeriesType == TimeSeriesType.UNIFORM) {
            createScenarios(rng, generatorSettings, entry.getValue(), .69, 1, 7);
        } else {
            throw new IllegalArgumentException();
        }
    }
    System.out.println("DONE.");
}