下面列出了com.google.common.collect.Multimaps#unmodifiableMultimap ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@BeforeClass
public static void beforeClass() {
Multimap<String,String> multimap = LinkedListMultimap.create();
multimap.clear();
multimap.put("MAKE_COLOR", "MAKE");
multimap.put("MAKE_COLOR", "COLOR");
multimap.put("COLOR_WHEELS", "COLOR");
multimap.put("COLOR_WHEELS", "WHEELS");
multimap.put("TEAM_NAME_POINTS", "TEAM");
multimap.put("TEAM_NAME_POINTS", "NAME");
multimap.put("TEAM_NAME_POINTS", "POINTS");
multimap.put("TEAM_POINTS", "TEAM");
multimap.put("TEAM_POINTS", "POINTS");
compositeToFieldMap = Multimaps.unmodifiableMultimap(multimap);
Map<String,String> sepMap = new HashMap<>();
sepMap.put("MAKE_COLOR", ",");
sepMap.put("COLOR_WHEELS", ",");
sepMap.put("TEAM_NAME_POINTS", ",");
sepMap.put("TEAM_POINTS", ",");
compositeFieldSeparators = Collections.unmodifiableMap(sepMap);
}
@JsonCreator
public TimelyUser(@JsonProperty(value = "dn", required = true) SubjectIssuerDNPair dn,
@JsonProperty(value = "userType", required = true) UserType userType,
@JsonProperty("auths") Collection<String> auths, @JsonProperty("roles") Collection<String> roles,
@JsonProperty("roleToAuthMapping") Multimap<String, String> roleToAuthMapping,
@JsonProperty(value = "creationTime", defaultValue = "-1L") long creationTime,
@JsonProperty(value = "expirationTime", defaultValue = "-1L") long expirationTime) {
this.name = dn.toString();
this.commonName = DnUtils.getCommonName(dn.subjectDN());
this.dn = dn;
this.userType = userType;
this.auths = auths == null ? Collections.emptyList() : new LinkedHashSet<>(auths);
this.unmodifiableAuths = Collections.unmodifiableCollection(this.auths);
this.roles = roles == null ? Collections.emptyList() : new LinkedHashSet<>(roles);
this.unmodifiableRoles = Collections.unmodifiableCollection(this.roles);
this.roleToAuthMapping = roleToAuthMapping == null ? LinkedHashMultimap.create()
: Multimaps.unmodifiableMultimap(LinkedHashMultimap.create(roleToAuthMapping));
this.creationTime = creationTime;
this.expirationTime = expirationTime;
}
public Multimap<SendToTableOperatorSpec, StreamTableJoinOperatorSpec> getSendToTableOpSpecToStreamTableJoinOpSpecs() {
Multimap<SendToTableOperatorSpec, StreamTableJoinOperatorSpec> sendToTableOpSpecToStreamTableJoinOpSpecs =
HashMultimap.create();
// Map every SendToTableOperatorSpec to all StreamTableJoinOperatorSpecs referencing the same table.
for (String tableId : tableToSendToTableOpSpecs.keySet()) {
Collection<SendToTableOperatorSpec> sendToTableOpSpecs = tableToSendToTableOpSpecs.get(tableId);
Collection<StreamTableJoinOperatorSpec> streamTableJoinOpSpecs =
tableToStreamTableJoinOpSpecs.get(tableId);
for (SendToTableOperatorSpec sendToTableOpSpec : sendToTableOpSpecs) {
sendToTableOpSpecToStreamTableJoinOpSpecs.putAll(sendToTableOpSpec, streamTableJoinOpSpecs);
}
}
return Multimaps.unmodifiableMultimap(sendToTableOpSpecToStreamTableJoinOpSpecs);
}
/**
* Generates the header cache.
*/
private synchronized void generateHeaderCache() {
if (headerCache != null) {
// already generated cache
return;
}
// generate the multimap
Multimap<String, String> headers = HashMultimap.create();
if (base.headers != null) {
for (Header header : base.headers) {
headers.putAll(header.name, header.value);
}
}
headerCache = Multimaps.unmodifiableMultimap(headers);
}
/**
* Builds a map of module dependencies.
*
* <p>If module "a" contains {@code <uses-split name="b"/>} manifest entry, then the map contains
* entry ("a", "b").
*
* <p>All modules implicitly depend on the "base" module. Hence the map contains also dependency
* ("base", "base").
*/
public static Multimap<String, String> buildAdjacencyMap(ImmutableList<BundleModule> modules) {
Multimap<String, String> moduleDependenciesMap = ArrayListMultimap.create();
for (BundleModule module : modules) {
String moduleName = module.getName().getName();
AndroidManifest manifest = module.getAndroidManifest();
checkArgument(
!moduleDependenciesMap.containsKey(moduleName),
"Module named '%s' was passed in multiple times.",
moduleName);
moduleDependenciesMap.putAll(moduleName, manifest.getUsesSplits());
// Check that module does not declare explicit dependency on the "base" module
// (whose split ID actually is empty instead of "base" anyway).
if (moduleDependenciesMap.containsEntry(moduleName, BASE_MODULE_NAME.getName())) {
throw InvalidBundleException.builder()
.withUserMessage(
"Module '%s' declares dependency on the '%s' module, which is implicit.",
moduleName, BASE_MODULE_NAME)
.build();
}
// Add implicit dependency on the base. Also ensures that every module has a key in the map.
moduleDependenciesMap.put(moduleName, BASE_MODULE_NAME.getName());
}
return Multimaps.unmodifiableMultimap(moduleDependenciesMap);
}
protected HttpRequestImpl(HttpRequest.Builder builder) {
this.uri = checkNotNull(builder.uri, "uri");
this.method = checkNotNull(builder.method, "method");
this.body = builder.body;
this.headers = Multimaps.unmodifiableMultimap(ArrayListMultimap.create(checkNotNull(builder.headers, "headers")));
this.credentials = builder.credentials;
this.config = builder.config;
}
public HttpRequestImpl(HttpRequestImpl httpRequest) {
this.uri = checkNotNull(httpRequest.uri, "uri");
this.method = checkNotNull(httpRequest.method, "method");
this.body = httpRequest.body;
this.headers = Multimaps.unmodifiableMultimap(ArrayListMultimap.create(checkNotNull(httpRequest.headers, "headers")));
this.credentials = httpRequest.credentials;
this.config = httpRequest.config;
}
/**
* @return immutable Multimap
*/
@Override
public Multimap map(Object sourceEnumerable, EnumerableFunction mapFunction, OwnerContext owner) {
Validate.argumentIsNotNull(mapFunction);
Multimap sourceMultimap = toNotNullMultimap(sourceEnumerable);
Multimap targetMultimap = ArrayListMultimap.create();
MapEnumerationOwnerContext enumeratorContext = new MapEnumerationOwnerContext(owner, true);
MapType.mapEntrySet(sourceMultimap.entries(), mapFunction, enumeratorContext, (k,v) -> targetMultimap.put(k,v));
return Multimaps.unmodifiableMultimap(targetMultimap);
}
/**
* Get containers used for this DAG
*
* @return Multimap<Container, TaskAttemptInfo> task attempt details at every container
*/
public final Multimap<Container, TaskAttemptInfo> getContainersToTaskAttemptMapping() {
List<VertexInfo> VertexInfoList = getVertices();
Multimap<Container, TaskAttemptInfo> containerMapping = LinkedHashMultimap.create();
for (VertexInfo vertexInfo : VertexInfoList) {
containerMapping.putAll(vertexInfo.getContainersMapping());
}
return Multimaps.unmodifiableMultimap(containerMapping);
}
/**
* Get the set of containers on which the task attempts ran for this task
*
* @return Multimap<Container, TaskAttemptInfo> task attempt details at container level
*/
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);
}
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);
}
/**
* Return the validation issues as an unmodifiable map.
*/
public Multimap<URI, LSPIssue> getValidationIssues() {
return Multimaps.unmodifiableMultimap(validationIssues);
}
/** Must first call {@link #blame}. */
public Multimap<PackageChunk, ResourceEntry> getPackageToBlamedResources() {
return Multimaps.unmodifiableMultimap(packageToBlame);
}
/** Must first call {@link #blame}. */
public Multimap<TypeChunk.Entry, ResourceEntry> getTypeEntryToBlamedResources() {
return Multimaps.unmodifiableMultimap(typeEntryToBlame);
}
public Multimap<V, K> inverse()
{
return Multimaps.unmodifiableMultimap(reverseMap);
}
/**
* @return an unmodifiable inverse view that will stay in sync
*/
public Multimap<V, K> inverse() {
return Multimaps.unmodifiableMultimap(mapInv);
}
public Multimap<Container, TaskAttemptInfo> getContainerMapping() {
return Multimaps.unmodifiableMultimap(containerMapping);
}