List of usage examples for com.google.common.collect Multimap put
boolean put(@Nullable K key, @Nullable V value);
From source file:com.android.tools.idea.editors.theme.attributes.AttributesGrouper.java
@NotNull private static List<TableLabel> generateLabelsForType(@NotNull final List<EditedStyleItem> source, @NotNull final List<EditedStyleItem> sink) { // ArrayListMultimap is used to ensure the elements stay sorted final Multimap<Group, EditedStyleItem> classes = ArrayListMultimap.create(); for (final EditedStyleItem item : source) { final String name = item.getName(); classes.put(Group.getGroupFromName(name), item); }//from w w w . j av a 2 s. c o m final List<TableLabel> labels = new ArrayList<TableLabel>(); int offset = 0; for (Group group : Group.values()) { Collection<EditedStyleItem> elements = classes.get(group); boolean addHeader = !elements.isEmpty(); if (addHeader && group == Group.OTHER) { // Adding "Everything else" label only in case when there are at least one other label, // because having "Everything else" as the only label present looks quite silly addHeader = offset != 0; } if (addHeader) { labels.add(new TableLabel(group.name, offset)); } sink.addAll(elements); offset += elements.size(); } return labels; }
From source file:com.android.tools.idea.apk.viewer.dex.DexParser.java
@NotNull private static Multimap<String, MethodReference> getMethodsByClassName(@NotNull DexBackedDexFile dexFile) { Multimap<String, MethodReference> methodsByClass = ArrayListMultimap.create(); for (int i = 0, m = dexFile.getMethodCount(); i < m; i++) { MethodReference methodRef = new DexBackedMethodReference(dexFile, i); methodsByClass.put(methodRef.getDefiningClass(), methodRef); }/* www . j a v a 2 s .c om*/ return methodsByClass; }
From source file:org.sosy_lab.cpachecker.cpa.bam.BAMARGUtils.java
private static void gatherReachedSets(BAMCPA cpa, Block block, ReachedSet reachedSet, Multimap<Block, ReachedSet> blockToReachedSet) { if (blockToReachedSet.containsEntry(block, reachedSet)) { return; //avoid looping in recursive block calls }//w w w . j a v a2 s . com blockToReachedSet.put(block, reachedSet); ARGState firstElement = (ARGState) reachedSet.getFirstState(); Deque<ARGState> worklist = new LinkedList<>(); Set<ARGState> processed = new HashSet<>(); worklist.add(firstElement); while (worklist.size() != 0) { ARGState currentElement = worklist.removeLast(); assert reachedSet.contains(currentElement); if (processed.contains(currentElement)) { continue; } processed.add(currentElement); for (ARGState child : currentElement.getChildren()) { CFAEdge edge = currentElement.getEdgeToChild(child); if (edge == null) { //this is a summary edge Pair<Block, ReachedSet> pair = cpa.getTransferRelation().getCachedReachedSet(currentElement, reachedSet.getPrecision(currentElement)); gatherReachedSets(cpa, pair.getFirst(), pair.getSecond(), blockToReachedSet); } if (!worklist.contains(child)) { if (reachedSet.contains(child)) { worklist.add(child); } } } } }
From source file:com.rackspacecloud.blueflood.io.astyanax.AstyanaxWriter.java
private static Multimap<Locator, IMetric> asMultimap(Collection<IMetric> metrics) { Multimap<Locator, IMetric> map = LinkedListMultimap.create(); for (IMetric metric : metrics) map.put(metric.getLocator(), metric); return map;/*from ww w . j ava 2 s . c o m*/ }
From source file:com.android.tools.idea.navigator.nodes.NdkModuleNode.java
@NotNull public static Collection<AbstractTreeNode> getNativeSourceNodes(@NotNull Project project, @NotNull NdkModuleModel ndkModuleModel, @NotNull ViewSettings viewSettings) { NativeAndroidProject nativeAndroidProject = ndkModuleModel.getAndroidProject(); Collection<String> sourceFileExtensions = nativeAndroidProject.getFileExtensions().keySet(); NdkModuleModel.NdkVariant variant = ndkModuleModel.getSelectedVariant(); Multimap<String, NativeArtifact> nativeLibraries = HashMultimap.create(); for (NativeArtifact artifact : variant.getArtifacts()) { String artifactOutputFileName = artifact.getOutputFile().getName(); nativeLibraries.put(artifactOutputFileName, artifact); }/*from www .j a v a2s. co m*/ if (nativeLibraries.keySet().size() == 1) { return getSourceDirectoryNodes(project, nativeLibraries.values(), viewSettings, sourceFileExtensions); } List<AbstractTreeNode> children = Lists.newArrayList(); for (String name : nativeLibraries.keySet()) { String nativeLibraryType = ""; String nativeLibraryName = trimEnd(name, ".so"); if (nativeLibraryName.length() < name.length()) { nativeLibraryType = "Shared Library"; } else { nativeLibraryName = trimEnd(name, ".a"); if (nativeLibraryName.length() < name.length()) { nativeLibraryType = "Static Library"; } } nativeLibraryName = trimStart(nativeLibraryName, "lib"); children.add(new NativeAndroidLibraryNode(project, nativeLibraryName, nativeLibraryType, nativeLibraries.get(name), viewSettings, sourceFileExtensions)); } return children; }
From source file:org.eclipse.sirius.diagram.sequence.business.internal.ordering.RefreshOrderingHelper.java
private static void add(SingleEventEnd see, Multimap<EObject, SingleEventEnd> endToEventEnds) { if (see != null && see.getSemanticEnd() != null) { endToEventEnds.put(see.getSemanticEnd(), see); }/*w ww . ja va2 s . c om*/ }
From source file:org.lanternpowered.server.profile.LanternProfileProperty.java
/** * Creates a multimap with {@link LanternProfileProperty}s from the specified {@link JsonArray}. * * @param jsonArray The json array//from w ww . j a va 2 s .c o m * @return The multimap */ public static Multimap<String, ProfileProperty> createPropertiesMapFromJson(JsonArray jsonArray) { final Multimap<String, ProfileProperty> properties = LinkedHashMultimap.create(); for (int i = 0; i < jsonArray.size(); i++) { final ProfileProperty profileProperty = createFromJson(jsonArray.get(i).getAsJsonObject()); properties.put(profileProperty.getName(), profileProperty); } return properties; }
From source file:grakn.core.graql.reasoner.plan.GraqlTraversalPlanner.java
/** * * @param atoms list of current atoms of interest * @param queryPattern corresponding pattern * @return an optimally ordered list of provided atoms *//* w w w .j av a 2 s . c o m*/ private static ImmutableList<Atom> planFromTraversal(List<Atom> atoms, Conjunction<?> queryPattern, TransactionOLTP tx) { Multimap<VarProperty, Atom> propertyMap = HashMultimap.create(); atoms.stream().filter(atom -> !(atom instanceof OntologicalAtom)) .forEach(atom -> atom.getVarProperties().forEach(property -> propertyMap.put(property, atom))); Set<VarProperty> properties = propertyMap.keySet(); GraqlTraversal graqlTraversal = TraversalPlanner.createTraversal(queryPattern, tx); ImmutableList<Fragment> fragments = Iterables.getOnlyElement(graqlTraversal.fragments()); List<Atom> atomList = new ArrayList<>(); atoms.stream().filter(atom -> atom instanceof OntologicalAtom).forEach(atomList::add); fragments.stream().map(Fragment::varProperty).filter(Objects::nonNull).filter(properties::contains) .distinct().flatMap(property -> propertyMap.get(property).stream()).distinct() .forEach(atomList::add); //add any unlinked items (disconnected and indexed for instance) propertyMap.values().stream().filter(at -> !atomList.contains(at)).forEach(atomList::add); return ImmutableList.copyOf(atomList); }
From source file:com.torodb.torod.db.postgresql.query.processors.InProcessor.java
public static List<ProcessedQueryCriteria> process(InQueryCriteria criteria, QueryCriteriaVisitor<List<ProcessedQueryCriteria>, Void> visitor) { if (!Utils.isTypeKnownInStructure(criteria.getAttributeReference())) { return Collections.singletonList(new ProcessedQueryCriteria(null, criteria)); } else {/*www.j av a2s . c o m*/ Multimap<BasicType, Value<?>> byTypeValues = MultimapBuilder.enumKeys(BasicType.class).hashSetValues() .build(); for (Value<?> value : criteria.getValue()) { byTypeValues.put(value.getType(), value); } List<ProcessedQueryCriteria> result; if (byTypeValues.isEmpty()) { result = Collections.emptyList(); } else { result = Lists.newArrayList(); ProcessedQueryCriteria typeQuery; typeQuery = getNumericQuery(criteria, byTypeValues); if (typeQuery != null) { result.add(typeQuery); } typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.STRING); if (typeQuery != null) { result.add(typeQuery); } typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.ARRAY); if (typeQuery != null) { result.add(typeQuery); } typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.BOOLEAN); if (typeQuery != null) { result.add(typeQuery); } typeQuery = getProcessedQuery(criteria, byTypeValues, BasicType.NULL); if (typeQuery != null) { result.add(typeQuery); } } return result; } }
From source file:eu.esdihumboldt.cst.functions.core.join.JoinUtil.java
/** * Build the join table and joined properties maps based on the given join * parameter// ww w . ja va 2s . c om * * @param joinParameter The join parameter * @return A {@link JoinDefinition} containing the join table and joined * properties maps */ public static JoinDefinition getJoinDefinition(JoinParameter joinParameter) { JoinDefinition result = new JoinDefinition(joinParameter.getTypes().size()); for (JoinCondition condition : joinParameter.getConditions()) { int baseTypeIndex = joinParameter.getTypes() .indexOf(AlignmentUtil.getTypeEntity(condition.baseProperty)); int joinTypeIndex = joinParameter.getTypes() .indexOf(AlignmentUtil.getTypeEntity(condition.joinProperty)); Multimap<Integer, JoinCondition> typeTable = result.joinTable.get(joinTypeIndex); if (typeTable == null) { typeTable = ArrayListMultimap.create(2, 2); result.joinTable.put(joinTypeIndex, typeTable); } typeTable.put(baseTypeIndex, condition); // update highest type if necessary if (result.directParent[joinTypeIndex] < baseTypeIndex) { result.directParent[joinTypeIndex] = baseTypeIndex; } result.properties.put(condition.joinProperty.getType(), condition.joinProperty); result.baseProperties.put(condition.baseProperty.getType(), condition.baseProperty); } return result; }