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:org.caleydo.view.bicluster.sorting.BandSortingStrategy.java

@Override
public List<IntFloat> apply(List<IntFloat> list) {
    List<Collection<Integer>> nonEmptyDimBands = new ArrayList<>();
    for (Edge edge : cluster.getOverlappingEdges(dim)) {
        nonEmptyDimBands.add(edge.getOverlapIndices(dim));
    }/*from  w  w  w. j  a  v  a 2 s. c om*/
    if (nonEmptyDimBands.isEmpty()) // early abort no bands nothing todo
        return list;

    BandSorting dimConflicts = new BandSorting(nonEmptyDimBands);

    Set<IntFloat> finalDimSorting = new LinkedHashSet<IntFloat>();

    ImmutableMap<Integer, IntFloat> byIndex = Maps.uniqueIndex(list, IntFloat.TO_INDEX);
    for (Integer i : dimConflicts) {
        finalDimSorting.add(byIndex.get(i));
    }
    // fill up rest
    finalDimSorting.addAll(list);
    return new ArrayList<>(finalDimSorting);
}

From source file:mod.rankshank.arbitraria.client.item.spraybottle.ModelSprayBottleFluid.java

@Override
public IModel retexture(ImmutableMap<String, String> data) {
    return new ModelSprayBottleFluid(
            data.containsKey("bottle") ? new ResourceLocation(data.get("bottle")) : this.bottle,
            data.containsKey("filler") ? new ResourceLocation(data.get("filler")) : this.filler, this.fluid);
}

From source file:com.facebook.buck.util.trace.ChromeTraceParser.java

/**
 * Parses a Chrome trace and stops parsing once all of the specified matchers have been satisfied.
 * This method parses only one Chrome trace event at a time, which avoids loading the entire trace
 * into memory./*from w ww .  j  a  va  2 s  . c  o  m*/
 *
 * @param pathToTrace is a relative path [to the ProjectFilesystem] to a Chrome trace in the "JSON
 *     Array Format."
 * @param chromeTraceEventMatchers set of matchers this invocation of {@code parse()} is trying to
 *     satisfy. Once a matcher finds a match, it will not consider any other events in the trace.
 * @return a {@code Map} where every matcher that found a match will have an entry whose key is
 *     the matcher and whose value is the one returned by {@link ChromeTraceEventMatcher#test(Map,
 *     String)} without the {@link Optional} wrapper.
 */
public Map<ChromeTraceEventMatcher<?>, Object> parse(Path pathToTrace,
        Set<ChromeTraceEventMatcher<?>> chromeTraceEventMatchers) throws IOException {
    Set<ChromeTraceEventMatcher<?>> unmatchedMatchers = new HashSet<>(chromeTraceEventMatchers);
    Preconditions.checkArgument(!unmatchedMatchers.isEmpty(), "Must specify at least one matcher");
    Map<ChromeTraceEventMatcher<?>, Object> results = new HashMap<>();

    try (InputStream input = projectFilesystem.newFileInputStream(pathToTrace);
            MappingIterator<ImmutableMap<String, Object>> it = ObjectMappers.READER
                    .forType(new TypeReference<ImmutableMap<String, Object>>() {
                    }).readValues(input)) {
        featureSearch: while (it.hasNext()) {
            // Verify and extract the name property before invoking any of the matchers.
            ImmutableMap<String, Object> event = it.next();
            Object nameEl = event.get("name");
            if (!(nameEl instanceof String)) {
                continue;
            }
            String name = (String) nameEl;

            // Prefer Iterator to Iterable+foreach so we can use remove().
            for (Iterator<ChromeTraceEventMatcher<?>> iter = unmatchedMatchers.iterator(); iter.hasNext();) {
                ChromeTraceEventMatcher<?> chromeTraceEventMatcher = iter.next();
                Optional<?> result = chromeTraceEventMatcher.test(event, name);
                if (result.isPresent()) {
                    iter.remove();
                    results.put(chromeTraceEventMatcher, result.get());

                    if (unmatchedMatchers.isEmpty()) {
                        break featureSearch;
                    }
                }
            }
        }
    }

    // We could throw if !unmatchedMatchers.isEmpty(), but that might be overbearing.
    return results;
}

From source file:com.facebook.buck.skylark.parser.context.ParseContext.java

/** Records the parsed {@code rawRule}. */
public void recordRule(ImmutableMap<String, Object> rawRule, FuncallExpression ast) throws EvalException {
    String name = Objects.requireNonNull((String) rawRule.get("name"), "Every target must have a name.");
    if (rawRules.containsKey(name)) {
        throw new EvalException(ast.getLocation(),
                String.format("Cannot register rule %s with content %s again.", name, rawRule));
    }/*from  www .ja v a2s . co  m*/
    rawRules.put(name, rawRule);
}

From source file:com.facebook.buck.parser.ParserConfig.java

/**
 * A (possibly empty) sequence of paths to files that should be included by default when
 * evaluating a build file./*  www. j a v  a  2s. c  om*/
 */
public Iterable<String> getDefaultIncludes() {
    ImmutableMap<String, String> entries = delegate.getEntriesForSection(BUILDFILE_SECTION_NAME);
    String includes = Strings.nullToEmpty(entries.get("includes"));
    return Splitter.on(' ').trimResults().omitEmptyStrings().split(includes);
}

From source file:com.liveramp.megadesk.recipes.aggregator.InterProcessKeyedAggregator.java

@Override
public AGGREGATE read(KEY key) throws Exception {
    ImmutableMap<KEY, AGGREGATE> remote = innerAggregator.read();
    if (remote == null) {
        return null;
    } else {//from   w w  w .j a  v a 2 s. c o m
        return remote.get(key);
    }
}

From source file:com.intel.hibench.stormbench.trident.functions.Parser.java

@Override
public void execute(TridentTuple tuple, TridentCollector collector) {
    ImmutableMap<String, String> kv = (ImmutableMap<String, String>) tuple.getValue(0);
    String key = kv.keySet().iterator().next();
    Long startTime = Long.parseLong(key);
    UserVisit uv = UserVisitParser.parse(kv.get(key));
    collector.emit(new Values(uv.getIp(), startTime));
}

From source file:com.facebook.buck.util.Config.java

public Optional<String> getValue(String sectionName, String propertyName) {
    ImmutableMap<String, String> properties = get(sectionName);
    return Optional.fromNullable(properties.get(propertyName));
}

From source file:com.google.jimfs.AclAttributeProvider.java

@Override
public AclFileAttributeView view(FileLookup lookup, ImmutableMap<String, FileAttributeView> inheritedViews) {
    return new View(lookup, (FileOwnerAttributeView) inheritedViews.get("owner"));
}

From source file:com.facebook.buck.features.apple.project.WorkspaceAndProjectGenerator.java

/**
 * Transform a map from scheme name to `TargetNode` to scheme name to the associated `PBXProject`.
 *
 * @param schemeToTargetNodes Map to transform.
 * @return Map of scheme name to associated `PXBProject`s.
 *///from ww w . j  a  va  2 s .  c o  m
private static ImmutableSetMultimap<String, PBXTarget> mapFromSchemeToPBXProject(
        ImmutableSetMultimap<String, ? extends TargetNode<?>> schemeToTargetNodes,
        ImmutableMap<BuildTarget, PBXTarget> buildTargetToPBXTarget) {
    ImmutableSetMultimap<String, PBXTarget> schemeToPBXProject = ImmutableSetMultimap
            .copyOf(schemeToTargetNodes.entries().stream()
                    .map(stringTargetNodeEntry -> Maps.immutableEntry(stringTargetNodeEntry.getKey(),
                            buildTargetToPBXTarget.get(stringTargetNodeEntry.getValue().getBuildTarget())))
                    .filter(stringPBXTargetEntry -> {
                        return stringPBXTargetEntry.getValue() != null;
                    }).collect(Collectors.toList()));
    return schemeToPBXProject;
}