com.google.common.collect.LinkedHashMultimap#create ( )源码实例Demo

下面列出了com.google.common.collect.LinkedHashMultimap#create ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: bazel   文件: ConservativeAspectResolver.java
@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);
}
 
源代码2 项目: Quicksql   文件: JethroDataSqlDialect.java
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);
  }
}
 
源代码3 项目: bazel   文件: ResourceSymbols.java
/**
 * 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;
}
 
源代码4 项目: datawave   文件: ExpandCompositeTerms.java
/**
 * 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);
}
 
源代码5 项目: immutables   文件: Support.java
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;
}
 
源代码6 项目: flashback   文件: MatchRuleUtilsTest.java
@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"));
}
 
源代码7 项目: baleen   文件: StructureContentExtractorTest.java
@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);
}
 
源代码8 项目: buck   文件: AliasConfig.java
/**
 * 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);
}
 
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();
	}
}
 
源代码10 项目: buck   文件: ZipEntrySourceCollectionBuilder.java
public ZipEntrySourceCollectionBuilder(
    ImmutableSet<Pattern> entriesToExclude, OnDuplicateEntry onDuplicateEntryAction) {
  this.excludedEntriesMatcher = new PatternsMatcher(entriesToExclude);
  this.onDuplicateEntryAction = onDuplicateEntryAction;
  this.onDuplicateEntryHandler = createDuplicateEntryHandler();
  this.entryNameToEntry = LinkedHashMultimap.create();
}
 
源代码11 项目: tez   文件: VertexInfo.java
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);
}
 
源代码12 项目: flashback   文件: RecordedHttpMessageTest.java
@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");
}
 
源代码13 项目: flashback   文件: MatchBodyWithAnyBoundaryTest.java
@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));
}
 
源代码14 项目: sqlitemagic   文件: Environment.java
public ImmutableSet<VariableElement> getLocalAndInheritedColumnFields(TypeElement type) {
  SetMultimap<String, VariableElement> fieldMap = LinkedHashMultimap.create();
  getLocalAndInheritedColumnFields(getPackage(type), type, fieldMap);
  return ImmutableSet.copyOf(fieldMap.values());
}
 
@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));
}
 
源代码16 项目: brooklyn-server   文件: BundleUpgradeParser.java
@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;
}
 
源代码17 项目: quantumdb   文件: DecomposeTable.java
DecomposeTable(String tableName) {
	checkArgument(!Strings.isNullOrEmpty(tableName), "You must specify a 'tableName'.");

	this.tableName = tableName;
	this.decompositions = LinkedHashMultimap.create();
}
 
源代码18 项目: cm_ext   文件: ReferenceValidatorImpl.java
public ReferenceCollector() {
  references = LinkedHashMultimap.create();
}
 
源代码19 项目: batfish   文件: AbstractRib.java
protected AbstractRib(boolean withBackupRoutes) {
  _allRoutes = ImmutableSet.of();
  _backupRoutes = withBackupRoutes ? LinkedHashMultimap.create() : null;
  _tree = new RibTree<>(this);
}
 
源代码20 项目: datawave   文件: ExpandCompositeTerms.java
/**
 * 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;
}