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

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

Introduction

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

Prototype

V get(Object key);

Source Link

Document

Returns the value to which the specified key is mapped, or null if this map contains no mapping for the key.

Usage

From source file:com.snaplogic.snaps.lunex.BaseService.java

private void setSuggestionBuilder(final SuggestionBuilder suggestionBuilder, PropertyValues propertyValues,
        final String TABLE_PROP_NAME, final String VALUE_PROP_NAME,
        ImmutableMap<String, ImmutableSet<String>> PARAM_LIST) {
    suggestionBuilder.node(TABLE_PROP_NAME).over(VALUE_PROP_NAME)
            .suggestions(PARAM_LIST.get(propertyValues.get(RESOURCE_PROP)).toArray(new String[0]));
}

From source file:io.druid.indexing.overlord.setup.FillCapacityWithAffinityWorkerSelectStrategy.java

@Override
public Optional<ImmutableZkWorker> findWorkerForTask(final RemoteTaskRunnerConfig config,
        final ImmutableMap<String, ImmutableZkWorker> zkWorkers, final Task task) {
    // don't run other datasources on affinity workers; we only want our configured datasources to run on them
    ImmutableMap.Builder<String, ImmutableZkWorker> builder = new ImmutableMap.Builder<>();
    for (String workerHost : zkWorkers.keySet()) {
        if (!affinityWorkerHosts.contains(workerHost)) {
            builder.put(workerHost, zkWorkers.get(workerHost));
        }/*w  w w .jav  a2 s  . co  m*/
    }
    ImmutableMap<String, ImmutableZkWorker> eligibleWorkers = builder.build();

    List<String> workerHosts = affinityConfig.getAffinity().get(task.getDataSource());
    if (workerHosts == null) {
        return super.findWorkerForTask(config, eligibleWorkers, task);
    }

    ImmutableMap.Builder<String, ImmutableZkWorker> affinityBuilder = new ImmutableMap.Builder<>();
    for (String workerHost : workerHosts) {
        ImmutableZkWorker zkWorker = zkWorkers.get(workerHost);
        if (zkWorker != null) {
            affinityBuilder.put(workerHost, zkWorker);
        }
    }
    ImmutableMap<String, ImmutableZkWorker> affinityWorkers = affinityBuilder.build();

    if (!affinityWorkers.isEmpty()) {
        Optional<ImmutableZkWorker> retVal = super.findWorkerForTask(config, affinityWorkers, task);
        if (retVal.isPresent()) {
            return retVal;
        }
    }

    return super.findWorkerForTask(config, eligibleWorkers, task);
}

From source file:com.srotya.flume.kinesis.source.KinesisSource.java

@Override
protected void doConfigure(Context ctx) throws FlumeException {
    ImmutableMap<String, String> props = ctx.getSubProperties(Constants.SETTINGS);
    if (!props.containsKey(Constants.ACCESS_KEY) || !props.containsKey(Constants.ACCESS_SECRET)) {
        Throwables.propagate(//from   w  ww  . jav a2  s.  c  om
                new InvalidArgumentException("Must provide AWS credentials i.e. accessKey and accessSecret"));
    }
    awsCredentials = new BasicAWSCredentials(props.get(Constants.ACCESS_KEY),
            props.get(Constants.ACCESS_SECRET));
    clientConfig = new ClientConfiguration();
    if (props.containsKey(Constants.PROXY_HOST)) {
        clientConfig.setProxyHost(props.get(Constants.PROXY_HOST));
        clientConfig.setProxyPort(Integer.parseInt(props.getOrDefault(Constants.PROXY_PORT, "80")));
        clientConfig.setProtocol(Protocol.valueOf(props.getOrDefault(Constants.PROTOCOL, "HTTPS")));
    }
    if (!props.containsKey(Constants.STREAM_NAME)) {
        Throwables.propagate(new InvalidArgumentException("Must provide Kinesis stream name"));
    }
    streamName = props.get(Constants.STREAM_NAME);
    putSize = Integer.parseInt(props.getOrDefault(Constants.PUT_SIZE, "100"));
    if (putSize > 500) {
        Throwables.propagate(
                new InvalidArgumentException("AWS Kinesis doesn't allow more than 500 put requests"));
    }
    endpoint = props.getOrDefault(Constants.ENDPOINT, Constants.DEFAULT_ENDPOINT);
    String serializerClass = props.getOrDefault(Constants.SERIALIZER, GsonSerializer.class.getName());
    try {
        serializer = (KinesisSerializer) Class.forName(serializerClass).newInstance();
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        Throwables.propagate(e);
    }
    serializer.configure(props);
    shardId = Integer.parseInt(props.getOrDefault(SHARD_INDEX, "0"));
    shardIteratorType = props.getOrDefault(ITERATOR_TYPE, DEFAULT_ITERATOR_TYPE);
}

From source file:org.apache.calcite.sql.test.SqlTestFactory.java

protected SqlTestFactory(ImmutableMap<String, Object> options, MockCatalogReaderFactory catalogReaderFactory,
        ValidatorFactory validatorFactory) {
    this.options = options;
    this.catalogReaderFactory = catalogReaderFactory;
    this.validatorFactory = validatorFactory;
    this.operatorTable = Suppliers
            .memoize(() -> createOperatorTable((SqlOperatorTable) options.get("operatorTable")));
    this.typeFactory = Suppliers.memoize(() -> createTypeFactory((SqlConformance) options.get("conformance")));
    Boolean caseSensitive = (Boolean) options.get("caseSensitive");
    this.catalogReader = Suppliers
            .memoize(() -> catalogReaderFactory.create(typeFactory.get(), caseSensitive).init());
    this.parserConfig = Suppliers.memoize(() -> createParserConfig(options));
}

From source file:com.facebook.buck.js.ReactNativeBundle.java

@Override
public ImmutableList<SourcePath> getInputsAfterBuildingLocally() throws IOException {
    ImmutableList.Builder<SourcePath> inputs = ImmutableList.builder();

    // Use the generated depfile to determinate which sources ended up being used.
    ImmutableMap<Path, SourcePath> pathToSourceMap = Maps.uniqueIndex(srcs, getResolver()::getAbsolutePath);
    Path depFile = getPathToDepFile(getBuildTarget(), getProjectFilesystem());
    for (String line : getProjectFilesystem().readLines(depFile)) {
        Path path = getProjectFilesystem().getPath(line);
        SourcePath sourcePath = pathToSourceMap.get(path);
        if (sourcePath == null) {
            throw new IOException(
                    String.format("%s: entry path '%s' transitively uses source file not preset in `srcs`: %s",
                            getBuildTarget(), entryPath, path));
        }// w w w.  j  a v  a2 s.  com
        inputs.add(sourcePath);
    }

    return inputs.build();
}

From source file:com.facebook.buck.android.dalvik.DalvikAwareZipSplitter.java

@Override
public ImmutableMultimap<APKModule, Path> execute() throws IOException {
    ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();
    Set<String> secondaryTail = new HashSet<String>();

    // Start out by writing the primary zip and recording which entries were added to it.
    primaryOut = newZipOutput(outPrimary);
    secondaryDexWriter.reset();//from w ww . j  av a2 s  .c o  m

    ImmutableMap.Builder<String, FileLike> entriesBuilder = ImmutableMap.builder();
    List<String> additionalDexStoreEntries = new ArrayList<>();

    // Iterate over all of the inFiles and add all entries that match the requiredInPrimaryZip
    // predicate.
    LOG.verbose("Traversing classpath for primary zip");

    classpathTraverser.traverse(new ClasspathTraversal(inFiles, filesystem) {
        @Override
        public void visit(FileLike entry) throws IOException {
            LOG.verbose("Visiting " + entry.getRelativePath());

            String relativePath = entry.getRelativePath();
            if (!relativePath.endsWith(".class")) {
                // We don't need resources in dex jars, so just drop them.
                return;
            }
            String classPath = relativePath.replaceAll("\\.class$", "");

            Objects.requireNonNull(primaryOut);
            Objects.requireNonNull(classPathToDexStore);

            if (requiredInPrimaryZip.test(relativePath)) {
                primaryOut.putEntry(entry);
            } else if (wantedInPrimaryZip.contains(relativePath)
                    || (secondaryHeadSet != null && secondaryHeadSet.contains(relativePath))) {
                entriesBuilder.put(relativePath, new BufferedFileLike(entry));
            } else if (secondaryTailSet != null && secondaryTailSet.contains(relativePath)) {
                entriesBuilder.put(relativePath, new BufferedFileLike(entry));
                secondaryTail.add(relativePath);
            } else {
                ImmutableCollection<APKModule> containingModule = classPathToDexStore.get(classPath);
                if (!containingModule.isEmpty()) {
                    if (containingModule.size() > 1) {
                        throw new IllegalStateException(
                                String.format("classpath %s is contained in multiple dex stores: %s", classPath,
                                        classPathToDexStore.get(classPath).asList().toString()));
                    }
                    APKModule dexStore = containingModule.iterator().next();
                    if (!dexStore.equals(rootModule)) {
                        MySecondaryDexHelper dexHelper = additionalDexWriters.get(dexStore);
                        Objects.requireNonNull(dexHelper);
                        dexHelper.getOutputToWriteTo(entry).putEntry(entry);
                        additionalDexStoreEntries.add(relativePath);
                    }
                }
            }
        }
    });

    // Put as many of the items wanted in the primary dex as we can into the primary dex.
    ImmutableMap<String, FileLike> entries = entriesBuilder.build();
    for (String wanted : wantedInPrimaryZip) {
        FileLike entry = entries.get(wanted);
        if ((entry != null) && !primaryOut.containsEntry(entry) && primaryOut.canPutEntry(entry)) {
            primaryOut.putEntry(entry);
        }
    }

    if (secondaryHeadSet != null) {
        for (String head : secondaryHeadSet) {
            FileLike headEntry = entries.get(head);
            if ((headEntry != null) && !primaryOut.containsEntry(headEntry)) {
                secondaryDexWriter.getOutputToWriteTo(headEntry).putEntry(headEntry);
            }
        }
    }

    LOG.verbose("Traversing classpath for secondary zip");

    // Now that all of the required entries have been added to the primary zip, fill the rest of
    // the zip up with the remaining entries.
    classpathTraverser.traverse(new ClasspathTraversal(inFiles, filesystem) {
        @Override
        public void visit(FileLike entry) throws IOException {
            Objects.requireNonNull(primaryOut);
            String relativePath = entry.getRelativePath();

            // skip if it is the primary dex, is part of a modular dex store, or is not a class file
            if (primaryOut.containsEntry(entry) || additionalDexStoreEntries.contains(relativePath)) {
                return;
            }

            LOG.verbose("Visiting " + entry.getRelativePath());

            // Even if we have started writing a secondary dex, we still check if there is any
            // leftover
            // room in the primary dex for the current entry in the traversal.
            if (dexSplitStrategy == DexSplitStrategy.MAXIMIZE_PRIMARY_DEX_SIZE
                    && primaryOut.canPutEntry(entry)) {
                primaryOut.putEntry(entry);
            } else {
                if (secondaryHeadSet != null && secondaryHeadSet.contains(relativePath)) {
                    return;
                }
                if (secondaryTail.contains(relativePath)) {
                    return;
                }
                secondaryDexWriter.getOutputToWriteTo(entry).putEntry(entry);
            }
        }
    });
    if (secondaryTailSet != null) {
        for (String tail : secondaryTailSet) {
            FileLike tailEntry = entries.get(tail);
            if ((tailEntry != null) && !primaryOut.containsEntry(tailEntry) && secondaryTail.contains(tail)) {
                secondaryDexWriter.getOutputToWriteTo(tailEntry).putEntry(tailEntry);
            }
        }
    }
    primaryOut.close();
    secondaryDexWriter.close();

    ImmutableMultimap.Builder<APKModule, Path> outputFilesBuilder = ImmutableMultimap.builder();
    APKModule secondaryDexStore = rootModule;
    outputFilesBuilder.putAll(secondaryDexStore, secondaryDexWriter.getFiles());
    for (Map.Entry<APKModule, MySecondaryDexHelper> entry : additionalDexWriters.entrySet()) {
        if (!entry.getKey().equals(secondaryDexStore)) {
            entry.getValue().close();
            outputFilesBuilder.putAll(entry.getKey(), entry.getValue().getFiles());
        }
    }
    return outputFilesBuilder.build();
}

From source file:com.facebook.buck.distributed.build_slave.DelegateAndGraphsInitializer.java

private TargetGraph createTargetGraph() throws InterruptedException {
    args.getTimingStatsTracker().startTimer(SlaveEvents.TARGET_GRAPH_DESERIALIZATION_TIME);
    try {// w  w w.  j av a 2  s .  c o  m
        TargetGraph targetGraph = null;
        DistBuildTargetGraphCodec codec = createGraphCodec();
        ImmutableMap<Integer, Cell> cells = args.getState().getCells();
        TargetGraphAndBuildTargets targetGraphAndBuildTargets = Objects
                .requireNonNull(codec.createTargetGraph(args.getState().getRemoteState().getTargetGraph(),
                        key -> Objects.requireNonNull(cells.get(key))));

        try {
            if (args.getState().getRemoteRootCellConfig().getView(BuildBuckConfig.class).getBuildVersions()) {
                targetGraph = args.getVersionedTargetGraphCache()
                        .toVersionedTargetGraph(args.getBuckEventBus(),
                                args.getState().getRemoteRootCellConfig(),
                                new DefaultTypeCoercerFactory(
                                        PathTypeCoercer.PathExistenceVerificationMode.DO_NOT_VERIFY),
                                new ParsingUnconfiguredBuildTargetFactory(), targetGraphAndBuildTargets)
                        .getTargetGraph();
            } else {
                targetGraph = targetGraphAndBuildTargets.getTargetGraph();
            }
        } catch (VersionException e) {
            throw new RuntimeException(e);
        }

        return targetGraph;
    } finally {
        args.getTimingStatsTracker().stopTimer(SlaveEvents.TARGET_GRAPH_DESERIALIZATION_TIME);
    }
}

From source file:io.druid.indexing.overlord.setup.EqualDistributionWithAffinityWorkerSelectStrategy.java

@Override
public Optional<ImmutableWorkerInfo> findWorkerForTask(final WorkerTaskRunnerConfig config,
        final ImmutableMap<String, ImmutableWorkerInfo> zkWorkers, final Task task) {
    // don't run other datasources on affinity workers; we only want our configured datasources to run on them
    ImmutableMap.Builder<String, ImmutableWorkerInfo> builder = new ImmutableMap.Builder<>();
    for (String workerHost : zkWorkers.keySet()) {
        if (!affinityWorkerHosts.contains(workerHost)) {
            builder.put(workerHost, zkWorkers.get(workerHost));
        }//from w  ww .  j  a v  a2  s.c  o m
    }
    ImmutableMap<String, ImmutableWorkerInfo> eligibleWorkers = builder.build();

    List<String> workerHosts = affinityConfig.getAffinity().get(task.getDataSource());
    if (workerHosts == null) {
        return super.findWorkerForTask(config, eligibleWorkers, task);
    }

    ImmutableMap.Builder<String, ImmutableWorkerInfo> affinityBuilder = new ImmutableMap.Builder<>();
    for (String workerHost : workerHosts) {
        ImmutableWorkerInfo zkWorker = zkWorkers.get(workerHost);
        if (zkWorker != null) {
            affinityBuilder.put(workerHost, zkWorker);
        }
    }
    ImmutableMap<String, ImmutableWorkerInfo> affinityWorkers = affinityBuilder.build();

    if (!affinityWorkers.isEmpty()) {
        Optional<ImmutableWorkerInfo> retVal = super.findWorkerForTask(config, affinityWorkers, task);
        if (retVal.isPresent()) {
            return retVal;
        }
    }

    return super.findWorkerForTask(config, eligibleWorkers, task);
}

From source file:no.ssb.vtl.model.Order.java

Order(DataStructure structure, ImmutableMap<Component, Direction> orders) {
    this.delegate = ImmutableMap.copyOf(orders);
    this.structure = checkNotNull(structure);

    ArrayList<Integer> indices = Lists.newArrayList();
    ArrayList<Direction> directions = Lists.newArrayList();
    for (Component component : orders.keySet()) {
        indices.add(structure.indexOf(component));
        directions.add(orders.get(component));
    }//from   www.  j a v a  2 s.c o m

    this.indices = Ints.toArray(indices);
    this.directions = directions.toArray(new Direction[] {});

}

From source file:com.android.build.gradle.shrinker.FullRunShrinker.java

/**
 * Sets the roots (i.e. entry points) of the graph and marks all nodes reachable from them.
 *///from w  ww.  j a v  a 2  s .  c om
private void setCounters(@NonNull ImmutableMap<CounterSet, KeepRules> allKeepRules) {
    final CounterSet counterSet = CounterSet.SHRINK;
    final KeepRules keepRules = allKeepRules.get(counterSet);

    for (final T klass : mGraph.getAllProgramClasses()) {
        mExecutor.execute(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                mGraph.addRoots(keepRules.getSymbolsToKeep(klass, mGraph), counterSet);
                return null;
            }
        });
    }
    waitForAllTasks();

    setCounters(counterSet);
}