Java Code Examples for com.google.common.collect.LinkedHashMultimap#create()
The following examples show how to use
com.google.common.collect.LinkedHashMultimap#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConservativeAspectResolver.java From bazel with Apache License 2.0 | 6 votes |
@Override public ImmutableMultimap<Attribute, Label> computeAspectDependencies( Target target, DependencyFilter dependencyFilter) { if (!(target instanceof Rule)) { return ImmutableMultimap.of(); } Rule rule = (Rule) target; if (!rule.hasAspects()) { return ImmutableMultimap.of(); } Multimap<Attribute, Label> result = LinkedHashMultimap.create(); for (Attribute attribute : rule.getAttributes()) { for (Aspect aspect : attribute.getAspects(rule)) { AspectDefinition.addAllAttributesOfAspect( rule, result, aspect, dependencyFilter); } } return ImmutableMultimap.copyOf(result); }
Example 2
Source File: MatchRuleUtilsTest.java From flashback with BSD 2-Clause "Simplified" License | 6 votes |
@Test public void testMethodUriBodyWithAnyBoundaryMatchForDifferentUri() throws Exception { Multimap<String, String> headers = LinkedHashMultimap.create(); headers.put("key1", "value1"); headers.put("Content-Type", "multipart/form-data; boundary=wxyz1234abcd5e"); RecordedHttpBody body = new RecordedStringHttpBody("------wxyz1234abcd5e\nContent-Disposition: form-data; name=\"org\" \ngoogle\n------wxyz1234abcd5e"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest("POST", new URI("http://www.linkedin.com/"), headers, body); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest("POST", new URI("http://www.google.com/"), headers, body); MatchRule matchRule = MatchRuleUtils.matchMethodUriBodyWithAnyBoundary(); Assert.assertFalse(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); Assert.assertTrue(matchRule.getMatchFailureDescriptionForRequests(recordedHttpRequest1, recordedHttpRequest2).contains("URI Mismatch")); }
Example 3
Source File: Support.java From immutables with Apache License 2.0 | 6 votes |
private Document mergeConjunctions(List<Document> conjunctions) { final Multimap<String, Document> merged = LinkedHashMultimap.create(); for (Document doc : conjunctions) { Preconditions.checkState(doc.keySet().size() == 1, "Invalid constraint %s", doc); final String key = doc.keySet().iterator().next(); merged.put(key, doc); } final Document result = new Document(); for (Map.Entry<String, Collection<Document>> entry : merged.asMap().entrySet()) { Preconditions.checkState(!entry.getValue().isEmpty(), "empty constraint: %s", entry); if (entry.getValue().size() == 1) { result.putAll(entry.getValue().iterator().next()); } else { result.putAll(new Document(QueryOperators.AND, entry.getValue())); } } return result; }
Example 4
Source File: ExpandCompositeTerms.java From datawave with Apache License 2.0 | 6 votes |
/** * Using the leaf nodes and anded nodes passed in, attempts to create composites from those nodes. The generated composites are required to contain at least * one of the leaf nodes. * * @param leafNodes * A multimap of leaf child nodes, keyed by field name, from the parent node * @param andedNodes * A multimap of anded nodes, keyed by field name, passed down from our ancestors * @param usedLeafNodes * A multimap of used leaf child nodes, keyed by field name, used to create the returned composites * @param usedAndedNodes * A multimap of used anded nodes, keyed by field name, used to create the returned composites * @return A list of composites which can be created from the given leaf and anded nodes */ private List<Composite> findComposites(Multimap<String,JexlNode> leafNodes, Multimap<String,JexlNode> andedNodes, Multimap<String,JexlNode> usedLeafNodes, Multimap<String,JexlNode> usedAndedNodes) { // determine what composites can be made with these fields Multimap<String,String> filteredCompositeToFieldMap = getFilteredCompositeToFieldMap(leafNodes.keySet(), andedNodes.keySet()); // TODO: Update this to use some kind of cardinality-based heuristic to sort the composites // order the composite to field map in order of preference filteredCompositeToFieldMap = orderByCollectionSize(filteredCompositeToFieldMap); // for each of the required fields, if is is an overloaded composite field, // we may need to create or tweak the leaf node's range, so we add a self-mapping Multimap<String,String> overloadedCompositeMap = LinkedHashMultimap.create(); for (String requiredField : leafNodes.keySet()) if (CompositeIngest.isOverloadedCompositeField(config.getCompositeToFieldMap(), requiredField)) overloadedCompositeMap.put(requiredField, requiredField); // Add overloaded composite entries to the set of entries List<Entry<String,Collection<String>>> compositeFieldMapList = new ArrayList<>(filteredCompositeToFieldMap.asMap().entrySet()); compositeFieldMapList.addAll(overloadedCompositeMap.asMap().entrySet()); return findComposites(compositeFieldMapList, leafNodes, andedNodes, usedLeafNodes, usedAndedNodes); }
Example 5
Source File: ResourceSymbols.java From bazel with Apache License 2.0 | 6 votes |
/** * Loads the SymbolTables from a list of SymbolFileProviders. * * @param dependencies The full set of library symbols to load. * @param executor The executor use during loading. * @param packageToExclude A string package to elide if it exists in the providers. * @return A list of loading {@link ResourceSymbols} instances. * @throws ExecutionException * @throws InterruptedException when there is an error loading the symbols. */ public static Multimap<String, ListenableFuture<ResourceSymbols>> loadFrom( Iterable<? extends SymbolFileProvider> dependencies, ListeningExecutorService executor, @Nullable String packageToExclude) throws InterruptedException, ExecutionException { Map<SymbolFileProvider, ListenableFuture<String>> providerToPackage = new LinkedHashMap<>(); for (SymbolFileProvider dependency : dependencies) { providerToPackage.put( dependency, executor.submit(new PackageParsingTask(dependency.getManifest()))); } Multimap<String, ListenableFuture<ResourceSymbols>> packageToTable = LinkedHashMultimap.create(); for (Map.Entry<SymbolFileProvider, ListenableFuture<String>> entry : providerToPackage.entrySet()) { File symbolFile = entry.getKey().getSymbolFile(); if (!Objects.equals(entry.getValue().get(), packageToExclude)) { packageToTable.put(entry.getValue().get(), load(symbolFile.toPath(), executor)); } } return packageToTable; }
Example 6
Source File: JethroDataSqlDialect.java From Quicksql with MIT License | 6 votes |
private JethroInfo makeInfo(Connection jethroConnection) { try (Statement jethroStatement = jethroConnection.createStatement(); ResultSet functionsTupleSet = jethroStatement.executeQuery("show functions extended")) { final Multimap<String, JethroSupportedFunction> supportedFunctions = LinkedHashMultimap.create(); while (functionsTupleSet.next()) { String functionName = functionsTupleSet.getString(1); String operandsType = functionsTupleSet.getString(3); supportedFunctions.put(functionName, new JethroSupportedFunction(functionName, operandsType)); } return new JethroInfo(supportedFunctions); } catch (Exception e) { final String msg = "Jethro server failed to execute 'show functions extended'"; LOGGER.error(msg, e); throw new RuntimeException(msg + "; make sure your Jethro server is up to date", e); } }
Example 7
Source File: ZipEntrySourceCollectionBuilder.java From buck with Apache License 2.0 | 5 votes |
public ZipEntrySourceCollectionBuilder( ImmutableSet<Pattern> entriesToExclude, OnDuplicateEntry onDuplicateEntryAction) { this.excludedEntriesMatcher = new PatternsMatcher(entriesToExclude); this.onDuplicateEntryAction = onDuplicateEntryAction; this.onDuplicateEntryHandler = createDuplicateEntryHandler(); this.entryNameToEntry = LinkedHashMultimap.create(); }
Example 8
Source File: AbstractAllContainersState.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
protected void initialize() { try { writeLock.lock(); uriToHandle = Collections.synchronizedMap(Maps.<URI, String>newHashMap()); handleToVisibleHandles = ArrayListMultimap.create(); handleToContent = LinkedHashMultimap.create(); emptyHandles = Collections.synchronizedSet(Sets.<String>newHashSet()); } finally { writeLock.unlock(); } }
Example 9
Source File: VertexInfo.java From tez with Apache License 2.0 | 5 votes |
public final Multimap<Container, TaskAttemptInfo> getContainersMapping() { Multimap<Container, TaskAttemptInfo> containerMapping = LinkedHashMultimap.create(); for (TaskAttemptInfo attemptInfo : getTaskAttempts()) { containerMapping.put(attemptInfo.getContainer(), attemptInfo); } return Multimaps.unmodifiableMultimap(containerMapping); }
Example 10
Source File: AliasConfig.java From buck with Apache License 2.0 | 5 votes |
/** * In a {@link BuckConfig}, an alias can either refer to a fully-qualified build target, or an * alias defined earlier in the {@code alias} section. The mapping produced by this method * reflects the result of resolving all aliases as values in the {@code alias} section. */ private ImmutableSetMultimap<String, UnconfiguredBuildTarget> createAliasToBuildTargetMap( ImmutableMap<String, String> rawAliasMap) { // We use a LinkedHashMap rather than an ImmutableMap.Builder because we want both (1) order to // be preserved, and (2) the ability to inspect the Map while building it up. SetMultimap<String, UnconfiguredBuildTarget> aliasToBuildTarget = LinkedHashMultimap.create(); for (Map.Entry<String, String> aliasEntry : rawAliasMap.entrySet()) { String alias = aliasEntry.getKey(); validateAliasName(alias); // Determine whether the mapping is to a build target or to an alias. List<String> values = Splitter.on(' ').splitToList(aliasEntry.getValue()); for (String value : values) { Set<UnconfiguredBuildTarget> buildTargets; if (isValidAliasName(value)) { buildTargets = aliasToBuildTarget.get(value); if (buildTargets.isEmpty()) { throw new HumanReadableException("No alias for: %s.", value); } } else if (value.isEmpty()) { continue; } else { // Here we parse the alias values with a BuildTargetParser to be strict. We could be // looser and just grab everything between "//" and ":" and assume it's a valid base path. buildTargets = ImmutableSet.of( getDelegate().getUnconfiguredBuildTargetForFullyQualifiedTarget(value)); } aliasToBuildTarget.putAll(alias, buildTargets); } } return ImmutableSetMultimap.copyOf(aliasToBuildTarget); }
Example 11
Source File: StructureContentExtractorTest.java From baleen with Apache License 2.0 | 5 votes |
@Override protected Extraction extract(InputStream stream, String source) throws ExtractionException { Multimap<String, String> metadata = LinkedHashMultimap.create(); metadata.put("test", "true"); return new DefaultExtraction( "<html><head><meta name=\"test\" content=\"true\" /></head><body><h1>Title</h1>\n<p>Example</p></body></html>", metadata); }
Example 12
Source File: RecordedHttpMessageTest.java From flashback with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testGetContentType() throws URISyntaxException { Multimap<String, String> headers = LinkedHashMultimap.create(); headers.put(HttpHeaders.CONTENT_TYPE, "text/html"); RecordedHttpRequest recordedHttpRequest = new RecordedHttpRequest("GET", new URI("google.com"), headers, null); Assert.assertEquals(recordedHttpRequest.getContentType(), "text/html"); }
Example 13
Source File: MatchBodyWithAnyBoundaryTest.java From flashback with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testBodyMatchForMultipartDataWithDifferentBoundary() { RecordedHttpBody stringHttpBody1 = new RecordedStringHttpBody("------wxyz1234abcd5e\nContent-Disposition: form-data; name=\"org\" \nMMM\n------wxyz1234abcd5e"); RecordedHttpBody stringHttpBody2 = new RecordedStringHttpBody("------abcd5678wxyz4v\nContent-Disposition: form-data; name=\"org\" \nMMM\n------abcd5678wxyz4v"); Multimap<String, String> headers1 = LinkedHashMultimap.create(); headers1.put(HttpHeaders.CONTENT_TYPE, "multipart/form-data; boundary=wxyz1234abcd5e"); Multimap<String, String> headers2 = LinkedHashMultimap.create(); headers2.put(HttpHeaders.CONTENT_TYPE, "multipart/form-data; boundary=abcd5678wxyz4v"); RecordedHttpRequest recordedHttpRequest1 = new RecordedHttpRequest(null, null, headers1, stringHttpBody1); RecordedHttpRequest recordedHttpRequest2 = new RecordedHttpRequest(null, null, headers2, stringHttpBody2); MatchRule matchRule = new MatchBodyWithAnyBoundary(); Assert.assertTrue(matchRule.test(recordedHttpRequest1, recordedHttpRequest2)); }
Example 14
Source File: Environment.java From sqlitemagic with Apache License 2.0 | 4 votes |
public ImmutableSet<VariableElement> getLocalAndInheritedColumnFields(TypeElement type) { SetMultimap<String, VariableElement> fieldMap = LinkedHashMultimap.create(); getLocalAndInheritedColumnFields(getPackage(type), type, fieldMap); return ImmutableSet.copyOf(fieldMap.values()); }
Example 15
Source File: BalancingNodePlacementStrategyTest.java From brooklyn-server with Apache License 2.0 | 4 votes |
@Test public void testAddsBalancedWhenEmpty() throws Exception { LinkedHashMultimap<Location, Entity> currentMembers = LinkedHashMultimap.<Location,Entity>create(); List<Location> result = placementStrategy.locationsForAdditions(currentMembers, ImmutableList.of(loc1, loc2), 4); Asserts.assertEqualsIgnoringOrder(result, ImmutableList.of(loc1, loc1, loc2, loc2)); }
Example 16
Source File: BundleUpgradeParser.java From brooklyn-server with Apache License 2.0 | 4 votes |
@VisibleForTesting static Multimap<VersionedName,VersionRangedName> parseVersionRangedNameEqualsVersionedNameList(String input, boolean singleVersionIsOsgiRange, List<String> wildcardNames, List<String> wildcardVersions, Function<VersionRangedName,VersionedName> defaultTargetFunction) { LinkedHashMultimap<VersionedName,VersionRangedName> result = LinkedHashMultimap.create(); if (input == null) return result; List<String> vals = QuotedStringTokenizer.builder() .delimiterChars(",") .includeQuotes(false) .includeDelimiters(false) .buildList(input); for (String entry : vals) { entry = entry.trim(); String key, val; String[] keVals = entry.split("="); if (keVals.length>2) { throw new IllegalArgumentException("Max one = permitted in entry (\""+entry+"\"). If defining a range on an entry you must quote the entry."); } else if (keVals.length==2) { key = keVals[0]; val = keVals[1]; } else { key = keVals[0]; val = null; } List<String> sourceNames, sourceVersions; if (key.startsWith("*")) { if (wildcardNames==null) { throw new IllegalArgumentException("Wildcard cannot be inferred"); } if ("*".equals(key)) { if (wildcardVersions==null) { throw new IllegalArgumentException("Version for wildcard cannot be inferred"); } sourceVersions = wildcardVersions; } else if (key.startsWith("*:")) { sourceVersions = MutableList.of(key.substring(2)); } else { throw new IllegalArgumentException("Wildcard entry key must be of the form \"*\" or \"*:range\""); } sourceNames = MutableList.copyOf(wildcardNames); } else { String[] parts = key.split(":"); if (parts.length==1) { if (wildcardVersions==null) { throw new IllegalArgumentException("Version for "+key+" cannot be inferred"); } sourceNames = MutableList.of(key); sourceVersions = wildcardVersions; } else if (parts.length==2) { sourceNames = MutableList.of(parts[0]); sourceVersions = MutableList.of(parts[1]); } else { throw new IllegalArgumentException("Entry '"+entry+"' should be of form 'name[:versionRange][=name[:version]]'"); } } for (String item: sourceNames) { for (String v: sourceVersions) { VersionRangedName source = parseVersionRangedName(item, v, false); VersionedName target; if (val!=null) { target = VersionedName.fromString(val); } else if (defaultTargetFunction!=null) { target = defaultTargetFunction.apply(source); } else { throw new IllegalArgumentException("Wildcard entry key must be of the form \"*\" or \"*:range\""); } result.put(target, source); } } } return result; }
Example 17
Source File: DecomposeTable.java From quantumdb with Apache License 2.0 | 4 votes |
DecomposeTable(String tableName) { checkArgument(!Strings.isNullOrEmpty(tableName), "You must specify a 'tableName'."); this.tableName = tableName; this.decompositions = LinkedHashMultimap.create(); }
Example 18
Source File: ReferenceValidatorImpl.java From cm_ext with Apache License 2.0 | 4 votes |
public ReferenceCollector() { references = LinkedHashMultimap.create(); }
Example 19
Source File: AbstractRib.java From batfish with Apache License 2.0 | 4 votes |
protected AbstractRib(boolean withBackupRoutes) { _allRoutes = ImmutableSet.of(); _backupRoutes = withBackupRoutes ? LinkedHashMultimap.create() : null; _tree = new RibTree<>(this); }
Example 20
Source File: ExpandCompositeTerms.java From datawave with Apache License 2.0 | 3 votes |
/** * This function is to order collections by size, this is useful so building composites can skip shorter composites ex. if KEY1_KEY2_KEY3 existed we would * not want to create KEY1_KEY2 or KEY1_KEY3 so could be skipped. * * @param mm * Multimap to sort by size of the {@code collection<v>} * @param <K> * Key type for mm, not relevant to sort * @param <V> * Value type for mm, not relevant to sort * @return Sorted linked hash multimap to keep order */ private <K,V> LinkedHashMultimap<K,V> orderByCollectionSize(Multimap<K,V> mm) { List<Entry<K,Collection<V>>> orderedCompositeToFieldMap = new ArrayList<>(mm.asMap().entrySet()); Collections.sort(orderedCompositeToFieldMap, (o1, o2) -> Integer.compare(o2.getValue().size(), o1.getValue().size())); LinkedHashMultimap<K,V> orderedMm = LinkedHashMultimap.create(); for (Map.Entry<K,Collection<V>> foundEntry : orderedCompositeToFieldMap) { orderedMm.putAll(foundEntry.getKey(), foundEntry.getValue()); } return orderedMm; }