List of usage examples for com.google.common.collect ImmutableMap get
V get(Object key);
From source file:com.facebook.buck.cxx.AbstractElfRewriteDynStrSectionStep.java
/** @return a processor for the `.dynamic` section. */ private SectionUsingDynamicStrings getDynamicProcessor(Elf elf) throws IOException { return new SectionUsingDynamicStrings() { // Load the dynamic section. private final ElfSection dynamicSection = elf.getMandatorySectionByName(getPath(), DYNAMIC) .getSection();// w w w . ja v a 2 s . co m private final ElfDynamicSection dynamic = ElfDynamicSection.parse(elf.header.ei_class, dynamicSection.body); @Override public ImmutableList<Long> getStringReferences() { return RichStream.from(dynamic.entries) .filter(e -> e.d_tag.getType() == ElfDynamicSection.DTag.Type.STRING).map(e -> e.d_un) .toImmutableList(); } @Override public void processNewStringReferences(long newSize, ImmutableMap<Long, Long> newStringIndices) { ElfDynamicSection newDynamic = new ElfDynamicSection(RichStream.from(dynamic.entries).map(e -> { if (e.d_tag == ElfDynamicSection.DTag.DT_STRSZ) { return new ElfDynamicSection.Entry(e.d_tag, newSize); } else if (e.d_tag.getType() == ElfDynamicSection.DTag.Type.STRING) { return new ElfDynamicSection.Entry(e.d_tag, Objects.requireNonNull(newStringIndices.get(e.d_un))); } else { return e; } }).toImmutableList()); dynamicSection.body.rewind(); newDynamic.write(elf.header.ei_class, dynamicSection.body); } }; }
From source file:com.isotrol.impe3.pms.core.obj.ConfigurationObject.java
/** * Constructor.//from w w w . jav a 2 s. c o m * @param definition Definition. * @param entity Configuration entity. */ private ConfigurationObject(ConfigurationDefinition<?> definition, ConfigurationEntity entity) { super(entity.getId()); ImmutableMap.Builder<String, Object> values = null; ImmutableMap.Builder<UUID, FileObject> files = null; ImmutableSet.Builder<UUID> usedContentTypes = null; ImmutableSet.Builder<UUID> usedCategories = null; ImmutableSet.Builder<String> extra = null; ImmutableSet.Builder<String> errors = null; final ImmutableMap<String, Item> parameters = definition.getParameters(); for (Entry<String, ConfigurationValue> ecv : entity.getValues().entrySet()) { final String name = ecv.getKey(); final Item item = parameters.get(name); if (item == null) { extra = add(extra, name); continue; } final Class<?> type = item.getType(); Object value = null; final ConfigurationValue cv = ecv.getValue(); if (item.isEnum()) { try { value = item.fromString(cv.getStringValue()); } catch (IllegalArgumentException iae) { if (errors == null) { errors = ImmutableSet.builder(); } errors.add(name); } } else if (String.class == type) { value = cv.getStringValue(); } else if (Integer.class == type) { value = cv.getIntegerValue(); } else if (Boolean.class == type) { value = cv.getBooleanValue(); } else if (FileId.class == type) { final FileEntity fe = cv.getFileValue(); if (fe != null) { final UUID id = fe.getId(); final FileId fid = FileId.of(id, fe.getName()); value = fid; files = put(files, id, new FileObject(fid, item)); } } else if (Category.class == type) { final CategoryEntity ce = cv.getCategoryValue(); if (ce != null) { final UUID id = ce.getId(); value = id; usedCategories = add(usedCategories, id); } } else if (ContentType.class == type) { final ContentTypeEntity ce = cv.getContentTypeValue(); if (ce != null) { final UUID id = ce.getId(); value = id; usedContentTypes = add(usedContentTypes, id); } } if (value != null) { values = put(values, name, value); } } this.definition = definition; this.values = build(values); this.files = build(files); this.usedContentTypes = build(usedContentTypes); this.usedCategories = build(usedCategories); Set<String> missing = Sets.difference(definition.getMBPParameters().keySet(), this.values.keySet()); if (errors == null) { this.errors = ImmutableSet.copyOf(missing); } else { this.errors = errors.addAll(missing).build(); } this.extra = build(extra); }
From source file:com.google.devtools.build.android.ParsedAndroidDataSubject.java
private <T extends DataValue> void compareDataValues(Iterable<Entry<DataKey, T>> actual, Iterable<Entry<DataKey, T>> expected, List<String> out, String valueType) { List<String> errors = new ArrayList<>(); ImmutableMap<DataKey, T> actualMap = ImmutableMap.copyOf(actual); ImmutableMap<DataKey, T> expectedMap = ImmutableMap.copyOf(expected); for (DataKey key : Sets.union(actualMap.keySet(), expectedMap.keySet())) { if (!(actualMap.containsKey(key) && expectedMap.containsKey(key))) { if (!actualMap.containsKey(key)) { errors.add(error("\tExpected %s.", key.toPrettyString())); }/*from w w w . j a va 2 s . co m*/ if (!expectedMap.containsKey(key)) { errors.add(error("\tHad unexpected %s.", key.toPrettyString())); } } else { T actualValue = actualMap.get(key); T expectedValue = expectedMap.get(key); if (!actualValue.equals(expectedValue)) { errors.add(error("\t%s is not equal", key.toPrettyString())); if (!actualValue.source().equals(expectedValue.source())) { if (!actualValue.source().getPath().equals(expectedValue.source().getPath())) { errors.add(error("\t\t%-10s: %s", "Expected path", expectedValue.source().getPath())); errors.add(error("\t\t%-10s: %s", "Actual path", actualValue.source().getPath())); } if (!actualValue.source().overrides().equals(expectedValue.source().overrides())) { errors.add(error("\t\t%-10s: %s", "Expected overrides", expectedValue.source())); errors.add(error("\t\t%-10s: %s", "Actual overrides", actualValue.source())); } } if (!actualValue.getClass().equals(expectedValue.getClass())) { errors.add(error("\t\t%-10s: %s", "Expected class", expectedValue.getClass())); errors.add(error("\t\t%-10s: %s", "Actual class", actualValue.getClass())); } else if (actualValue instanceof DataResourceXml) { errors.add(error("\t\t%-10s: %s", "Expected xml", expectedValue)); errors.add(error("\t\t%-10s: %s", "Actual xml", actualValue)); } } } } if (errors.isEmpty()) { return; } out.add(valueType); out.add(Joiner.on("\n").join(errors)); }
From source file:se.sics.caracaldb.global.DefaultPolicy.java
private long guessAddedSize(LUTWorkingBuffer lut, Integer[] member, ImmutableMap<Address, Stats.Report> stats) { // Use the average of the average node size of all live members to guess the size for this group ArrayList<Long> avgSizes = new ArrayList<Long>(member.length); for (Integer id : member) { Address addr = lut.getHost(id);/*from w w w .jav a 2 s .c o m*/ Stats.Report rep = stats.get(addr); if (rep != null) { avgSizes.add(rep.averageSize); } } long sum = 0; for (Long l : avgSizes) { sum += l; } return Stats.floorDiv(sum, avgSizes.size()); }
From source file:se.sics.caracaldb.global.DefaultPolicy.java
private void addMoreCandidates(LUTWorkingBuffer lut, TreeMultimap<Long, Integer> candidates, ImmutableMap<Address, Stats.Report> stats) { if (candidates.values().size() >= stats.size()) { return; // Already everyone a candidate...nothing to do }/*from w ww .j ava 2 s . c o m*/ int index = 0; for (Address addr : lut.hosts()) { if (!candidates.containsValue(index)) { Stats.Report rep = stats.get(addr); if (rep != null) { long curSize = rep.averageSize * rep.numberOfVNodes; candidates.put(curSize, index); } } index++; } }
From source file:com.isotrol.impe3.pms.core.obj.PortalConfigurationObject.java
/** * Constructor.//from w w w . jav a 2 s .c o m * @param definition Definition. * @param entity Configuration entity. */ private PortalConfigurationObject(PortalConfigurationDefinition<?> definition, ConfigurationEntity entity) { super(entity.getId()); ImmutableMap.Builder<String, Object> values = null; ImmutableMap.Builder<UUID, PortalFileObject> files = null; ImmutableSet.Builder<UUID> usedContentTypes = null; ImmutableSet.Builder<UUID> usedCategories = null; ImmutableSet.Builder<String> extra = null; ImmutableSet.Builder<String> errors = null; final ImmutableMap<String, Item> parameters = definition.getParameters(); for (Entry<String, ConfigurationValue> ecv : entity.getValues().entrySet()) { final String name = ecv.getKey(); final Item item = parameters.get(name); if (item == null) { extra = add(extra, name); continue; } final Class<?> type = item.getType(); Object value = null; final ConfigurationValue cv = ecv.getValue(); if (item.isEnum()) { try { value = item.fromString(cv.getStringValue()); } catch (IllegalArgumentException iae) { if (errors == null) { errors = ImmutableSet.builder(); } errors.add(name); } } else if (String.class == type) { value = cv.getStringValue(); } else if (Integer.class == type) { value = cv.getIntegerValue(); } else if (Boolean.class == type) { value = cv.getBooleanValue(); } else if (FileId.class == type) { final FileEntity fe = cv.getFileValue(); if (fe != null) { final UUID id = fe.getId(); final FileId fid = FileId.of(id, fe.getName()); value = fid; files = put(files, id, new PortalFileObject(fid, item)); } } else if (Category.class == type) { final CategoryEntity ce = cv.getCategoryValue(); if (ce != null) { final UUID id = ce.getId(); value = id; usedCategories = add(usedCategories, id); } } else if (ContentType.class == type) { final ContentTypeEntity ce = cv.getContentTypeValue(); if (ce != null) { final UUID id = ce.getId(); value = id; usedContentTypes = add(usedContentTypes, id); } } if (value != null) { values = put(values, name, value); } } this.definition = definition; this.values = build(values); this.files = build(files); this.usedContentTypes = build(usedContentTypes); this.usedCategories = build(usedCategories); Set<String> missing = Sets.difference(definition.getMBPParameters().keySet(), this.values.keySet()); if (errors == null) { this.errors = ImmutableSet.copyOf(missing); } else { this.errors = errors.addAll(missing).build(); } this.extra = build(extra); }
From source file:com.android.builder.shrinker.Shrinker.java
private void decrementCounter(T member, DependencyType dependencyType, ShrinkType shrinkType, @Nullable ImmutableMap<ShrinkType, Set<T>> modifiedClasses) { if (mGraph.decrementAndCheck(member, dependencyType, shrinkType)) { if (modifiedClasses != null) { modifiedClasses.get(shrinkType).add(mGraph.getClassForMember(member)); }/* w w w.ja v a 2 s. c o m*/ for (Dependency<T> dependency : mGraph.getDependencies(member)) { decrementCounter(dependency.target, dependency.type, shrinkType, modifiedClasses); } } }
From source file:com.clearclouds.driver.monitor.jvm.DeadlockAnalyzer.java
private Set<LinkedHashSet<ThreadInfo>> calculateCycleDeadlockChains( ImmutableMap<Long, ThreadInfo> threadInfoMap, Set<LinkedHashSet<ThreadInfo>> cycles) { ThreadInfo allThreads[] = threadBean.getThreadInfo(threadBean.getAllThreadIds()); Set<LinkedHashSet<ThreadInfo>> deadlockChain = new HashSet<>(); Set<Long> knownDeadlockedThreads = threadInfoMap.keySet(); for (ThreadInfo threadInfo : allThreads) { Thread.State state = threadInfo.getThreadState(); if (state == Thread.State.BLOCKED && !knownDeadlockedThreads.contains(threadInfo.getThreadId())) { for (LinkedHashSet cycle : cycles) { if (cycle.contains(threadInfoMap.get(Long.valueOf(threadInfo.getLockOwnerId())))) { LinkedHashSet<ThreadInfo> chain = new LinkedHashSet<>(); for (ThreadInfo node = threadInfo; !chain.contains(node); node = threadInfoMap .get(Long.valueOf(node.getLockOwnerId()))) chain.add(node); deadlockChain.add(chain); }// ww w . ja v a 2 s.c o m } } } return deadlockChain; }
From source file:com.google.idea.blaze.cpp.BlazeResolveConfigurationTemporaryBase.java
private void collectHeaderRoots(ImmutableMap<File, VirtualFile> virtualFileCache, ImmutableList.Builder<HeadersSearchRoot> roots, ImmutableCollection<ExecutionRootPath> paths, boolean isUserHeader) { for (ExecutionRootPath executionRootPath : paths) { ImmutableList<File> possibleDirectories = workspacePathResolver .resolveToIncludeDirectories(executionRootPath); for (File f : possibleDirectories) { VirtualFile vf = virtualFileCache.get(f); if (vf != null) { roots.add(new IncludedHeadersRoot(project, vf, false /* recursive */, isUserHeader)); }/*w w w.ja va 2 s . c o m*/ } } }
From source file:de.faustedition.genesis.lines.VerseStatisticsResource.java
@Get("json") public Representation chartData() { final List<Map<String, Object>> chartData = Lists.newLinkedList(); final ImmutableMap<String, MaterialUnit> documentIndex = Maps.uniqueIndex(verseStatistics.keySet(), new Function<MaterialUnit, String>() { @Override/*from w w w . j a v a2s . c om*/ public String apply(@Nullable MaterialUnit input) { return input.toString() + " [" + input.node.getId() + "]"; } }); for (String documentDesc : Ordering.natural().immutableSortedCopy(documentIndex.keySet())) { final List<Map<String, Object>> intervals = Lists.newLinkedList(); for (VerseInterval interval : Ordering.from(VerseManager.INTERVAL_COMPARATOR) .immutableSortedCopy(verseStatistics.get(documentIndex.get(documentDesc)))) { intervals.add(new ModelMap().addAttribute("start", Math.max(from, interval.getStart())) .addAttribute("end", Math.min(to, interval.getEnd()))); } chartData.add(new ModelMap().addAttribute("sigil", documentDesc.substring(0, documentDesc.indexOf('['))) /*.addAttribute("transcript", documentIndex.get(documentDesc).node.getId())*/ .addAttribute("source", ((Document) documentIndex.get(documentDesc)).getSource().toString()) .addAttribute("intervals", intervals)); } return jsonRepresentationFactory.map(chartData, false); }