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.jeffreybosboom.lyne.Effector.java

public void playPuzzle() {
    BufferedImage image = robot.createScreenCapture(lyneRect);
    Pair<Puzzle, ImmutableMap<Node, Region.Point>> parseImage = parseImage(image);
    System.out.println(parseImage.first);
    Set<List<Node>> solutionPaths = Solver.solve(parseImage.first);
    ImmutableMap<Node, Region.Point> pointMap = parseImage.second;
    for (List<Node> path : solutionPaths) {
        System.out.println(path.stream().map(n -> String.format("%s (%d, %d)", n, n.row(), n.col()))
                .collect(Collectors.joining(", ")));
        mouseMove(pointMap.get(path.get(0)));
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        for (int i = 1; i < path.size(); ++i)
            mouseMove(pointMap.get(path.get(i)));
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    }//from  w ww. ja v  a2 s  .c  o m
}

From source file:com.radeonsys.data.querystore.support.properties.PropertiesQueryStore.java

/**
 * Copies queries from the specified properties object into this query
 * store// w w w .j  a  va  2 s.  c o m
 * 
 * @param props   reference to an instance of {@link Properties} which
 *             contains query definitions to copy
 * 
 * @throws IllegalArgumentException
 *          if the specified properties is {@code null}
 */
private final void copyQueriesToStore(Properties props) {
    Preconditions.checkArgument(props != null, "A valid set of properties must be specified.");

    if (props.isEmpty())
        return;

    ImmutableMap<String, String> propMap = Maps.fromProperties(props);

    for (String queryName : propMap.keySet())
        addQuery(queryName, propMap.get(queryName).trim());

    if (logger.isTraceEnabled())
        logger.trace(String.format("Copied %d queries into query store", props.size()));
}

From source file:org.grycap.gpf4med.ext.GraphConnectorManager.java

public @Nullable GraphConnector getConnector(final String path) {
    checkArgument(StringUtils.isNotBlank(path), "Uninitialized or invalid path");
    final ImmutableMap<String, GraphConnector> connectors = listConnectors();
    return (connectors != null ? connectors.get(path) : null);
}

From source file:name.martingeisse.stackd.server.section.SectionToClientShipper.java

/**
 * Fetches all jobs from the job queue and handles them.
 *///from   w w  w. ja v  a2s.co  m
public void handleJobs() {

    // Fetch pending jobs, returning if there is nothing to do. This happens quite often because
    // the job handling task gets scheduled for every added job, but the task handles *all*
    // pending jobs, so the remaining task executions only find an empty job queue.
    if (jobQueue.isEmpty()) {
        return;
    }
    ArrayList<ShippingJob> jobs = new ArrayList<SectionToClientShipper.ShippingJob>();
    jobQueue.drainTo(jobs);
    if (jobs.isEmpty()) {
        return;
    }

    // collect section data IDs
    Set<SectionDataId> sectionDataIds = new HashSet<>();
    for (ShippingJob job : jobs) {
        sectionDataIds.add(job.sectionDataId);
    }

    // fetch the objects from the cache
    ImmutableMap<SectionDataId, SectionDataCacheEntry> cacheEntries = workingSet.getAll(sectionDataIds);

    // complete the jobs by sending data to the clients
    for (ShippingJob job : jobs) {
        sendResult(cacheEntries.get(job.sectionDataId), job.session);
    }

}

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

@Override
public Collection<File> execute() throws IOException {
    ClasspathTraverser classpathTraverser = new DefaultClasspathTraverser();

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

    final ImmutableMap.Builder<String, FileLike> entriesBuilder = ImmutableMap.builder();

    // Iterate over all of the inFiles and add all entries that match the requiredInPrimaryZip
    // predicate.
    classpathTraverser.traverse(new ClasspathTraversal(inFiles, filesystem) {
        @Override
        public void visit(FileLike entry) throws IOException {
            String relativePath = entry.getRelativePath();
            if (requiredInPrimaryZip.apply(relativePath)) {
                primaryOut.putEntry(entry);
            } else if (wantedInPrimaryZip.contains(relativePath)) {
                entriesBuilder.put(relativePath, new BufferedFileLike(entry));
            }
        }
    });

    // 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);
        }
    }

    // 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 {
            if (primaryOut.containsEntry(entry)) {
                return;
            }

            // 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 {
                secondaryDexWriter.getOutputToWriteTo(entry).putEntry(entry);
            }
        }
    });

    primaryOut.close();
    secondaryDexWriter.close();
    return secondaryDexWriter.getFiles();
}

From source file:com.google.caliper.runner.config.CaliperConfig.java

/**
 * Returns the default set of instruments to use if the user doesn't specify which instruments to
 * use on the command line./*from w  w w .  j av  a  2  s.c om*/
 */
public ImmutableSet<String> getDefaultInstruments() {
    // TODO(cgdecker): could/should this "defaults" be generalized?
    // e.g. if there's a command line option "--foo", "defaults.foo" is the default value of "foo"
    // if the user doesn't pass that option. This is already the case here since "--instrument" is
    // the long-form commmand line option, but I'm not trying to generalize now since there's no
    // apparent need to.
    ImmutableMap<String, String> defaults = subgroupMap(properties, "defaults");
    if (!defaults.isEmpty()) {
        String instruments = defaults.get("instrument");
        if (instruments != null) {
            return ImmutableSet.copyOf(Splitter.on(',').split(instruments));
        }
    }

    throw new InvalidConfigurationException(
            "Could not find default set of instruments to use (defaults.instrument in config file)");
}

From source file:org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsResponse.java

/**
 * Returns the mappings of a specific field.
 *
 * @param field field name as specified in the {@link GetFieldMappingsRequest}
 * @return FieldMappingMetaData for the requested field or null if not found.
 *//*w w  w. j av a2 s  . c  o  m*/
public FieldMappingMetaData fieldMappings(String index, String type, String field) {
    ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>> indexMapping = mappings.get(index);
    if (indexMapping == null) {
        return null;
    }
    ImmutableMap<String, FieldMappingMetaData> typeMapping = indexMapping.get(type);
    if (typeMapping == null) {
        return null;
    }
    return typeMapping.get(field);
}

From source file:com.pinterest.pinlater.PinLaterQueueConfig.java

@VisibleForTesting
double getDequeueRate(String queueName) {
    MorePreconditions.checkNotBlank(queueName);
    ImmutableMap<String, QueueRateLimiter.IFace> queueRateLimitMap = queueRateLimitMapRef.get();
    if (queueRateLimitMap != null && queueRateLimitMap.containsKey(queueName)) {
        return queueRateLimitMap.get(queueName).getRate();
    } else {/*from   w w  w . j a  v a  2 s.  com*/
        // No rate limit specified for this queue.
        return Double.MAX_VALUE;
    }
}

From source file:com.pinterest.pinlater.PinLaterQueueConfig.java

/**
 * Determines whether a dequeue request should be allowed.
 *
 * @param queueName  name of the queue.//w w  w  . j  a v  a  2  s .co  m
 * @param numJobs    number of jobs intended to be dequeued.
 * @return whether to allow the request.
 */
public boolean allowDequeue(String queueName, int numJobs) {
    MorePreconditions.checkNotBlank(queueName);
    Preconditions.checkArgument(numJobs > 0);
    ImmutableMap<String, QueueRateLimiter.IFace> queueRateLimitMap = queueRateLimitMapRef.get();
    if (queueRateLimitMap != null && queueRateLimitMap.containsKey(queueName)) {
        return queueRateLimitMap.get(queueName).allowDequeue(numJobs);
    } else {
        // No rate limit specified for this queue, so always allow.
        return true;
    }
}

From source file:org.apache.flume.plugins.KafkaSource.java

@Override
public void configure(Context context) {
    this.context = context;
    ImmutableMap<String, String> props = context.getParameters();

    // base: consumer.sources.s
    this.parameters = new Properties();
    for (String key : props.keySet()) {
        String value = props.get(key);
        this.parameters.put(key, value);
    }//from  www  .j  a  v  a 2s . c om

    //source monitoring count
    if (sourceCounter == null) {
        sourceCounter = new SourceCounter(getName());
    }
}