下面列出了com.google.common.collect.ImmutableBiMap#copyOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Test
public void testResolveDoesPut() throws Exception {
FDBReverseDirectoryCache reverseDirectoryCache = fdb.getReverseDirectoryCache();
final Map<String, Long> forwardMapping = new HashMap<>();
try (FDBRecordContext context = openContext()) {
final Random random = new Random();
for (int i = 0; i < 5; i++) {
final String directoryKey = "dir_" + Math.abs(random.nextLong());
forwardMapping.put(directoryKey, globalScope.resolve(context.getTimer(), directoryKey).get());
}
}
reverseDirectoryCache.clearStats();
BiMap<String, Long> mapping = ImmutableBiMap.copyOf(forwardMapping);
for (Map.Entry<Long, String> reverseDirectoryEntry : mapping.inverse().entrySet()) {
String reverseDirectoryValue = reverseDirectoryCache.get(globalScope.wrap(reverseDirectoryEntry.getKey())).join()
.orElseThrow(() -> new AssertionError("RD cache get should not be empty"));
assertEquals(reverseDirectoryValue, reverseDirectoryEntry.getValue());
}
final String stats = " (persistent hit=" + reverseDirectoryCache.getPersistentCacheHitCount()
+ ", persistent miss=" + reverseDirectoryCache.getPersistentCacheMissCount() + ")";
assertEquals(mapping.size(), reverseDirectoryCache.getPersistentCacheHitCount(), "persistent hit count " + stats);
assertEquals(0L, reverseDirectoryCache.getPersistentCacheMissCount(), "persistent miss count " + stats);
}
public GqlInputConverter build() {
HashBiMap<String, Descriptor> mapping = HashBiMap.create();
HashBiMap<String, EnumDescriptor> enumMapping = HashBiMap.create(getEnumMap(enumDescriptors));
LinkedList<Descriptor> loop = new LinkedList<>(descriptors);
Set<FileDescriptor> fileDescriptorSet = ProtoRegistry.extractDependencies(fileDescriptors);
for (FileDescriptor fileDescriptor : fileDescriptorSet) {
loop.addAll(fileDescriptor.getMessageTypes());
enumMapping.putAll(getEnumMap(fileDescriptor.getEnumTypes()));
}
while (!loop.isEmpty()) {
Descriptor descriptor = loop.pop();
if (!mapping.containsKey(descriptor.getFullName())) {
mapping.put(getReferenceName(descriptor), descriptor);
loop.addAll(descriptor.getNestedTypes());
enumMapping.putAll(getEnumMap(descriptor.getEnumTypes()));
}
}
return new GqlInputConverter(
ImmutableBiMap.copyOf(mapping), ImmutableBiMap.copyOf(enumMapping));
}
private static <T> BiMap<T, String> buildBiMap(Iterable<T> values) {
@SuppressWarnings("unchecked")
Suggester<T> suggester = (Suggester<T>) PREFIX_SUGGESTER;
final BiMap<T, String> map = HashBiMap.create();
for (T value: values) {
if (!map.containsKey(value)) {
String name;
for (int i = 0; ; i++) {
name = suggester.suggest(value, i, map.size());
if (!map.containsValue(name)) {
map.put(value, name);
break; // name found, break the loop
}
}
}
}
return ImmutableBiMap.copyOf(map);
}
/** Returns a bi-map between property names and the corresponding abstract property methods. */
final ImmutableBiMap<String, ExecutableElement> propertyNameToMethodMap(
Set<ExecutableElement> propertyMethods) {
Map<String, ExecutableElement> map = new LinkedHashMap<>();
Set<String> reportedDups = new HashSet<>();
boolean allPrefixed = gettersAllPrefixed(propertyMethods);
for (ExecutableElement method : propertyMethods) {
String methodName = method.getSimpleName().toString();
String name = allPrefixed ? nameWithoutPrefix(methodName) : methodName;
ExecutableElement old = map.put(name, method);
if (old != null) {
List<ExecutableElement> contexts = new ArrayList<>(Arrays.asList(method));
if (reportedDups.add(name)) {
contexts.add(old);
}
// Report the error for both of the methods. If this is a third or further occurrence,
// reportedDups prevents us from reporting more than one error for the same method.
for (ExecutableElement context : contexts) {
errorReporter.reportError(
context, "More than one @%s property called %s", simpleAnnotationName, name);
}
}
}
return ImmutableBiMap.copyOf(map);
}
/**
* Populate bimap to contain all unique view element class names of a given {@link
* windowHierarchyElements}.
*/
public ViewElementClassNamesAndroid(
List<WindowHierarchyElementAndroid> windowHierarchyElements) {
Map<String, Integer> classIdMap = new HashMap<>();
for (WindowHierarchyElementAndroid window : windowHierarchyElements) {
for (ViewHierarchyElementAndroid view : window.getAllViews()) {
Set<String> classReferenceSet = getSuperclassSet(view);
for (String className : classReferenceSet) {
Integer classNameId = classIdMap.get(className);
if (classNameId == null) {
classNameId = classIdMap.size();
classIdMap.put(className, classNameId);
}
view.addIdToSuperclassViewList(classNameId);
}
}
}
this.uniqueViewElementsClassNames = ImmutableBiMap.copyOf(classIdMap);
}
AggregationQuery(Query query, PathNaming pathNaming) {
this.query = maybeRewriteDistinctToGroupBy(query);
this.pathNaming = Objects.requireNonNull(pathNaming, "naming");
BiMap<Expression, String> biMap = HashBiMap.create();
List<Path> paths = Stream.concat(query.projections().stream(), Stream.concat(query.groupBy().stream(), query.collations().stream().map(Collation::expression)))
.map(AggregationQuery::extractPath).collect(Collectors.toList());
@SuppressWarnings("unchecked")
ExpressionNaming naming = ExpressionNaming.from(UniqueCachedNaming.of(paths.iterator()));
paths.forEach(p -> biMap.put(p, naming.name(p)));
this.projectionNaming = ExpressionNaming.from(UniqueCachedNaming.of(query.projections()));
this.naming = ImmutableBiMap.copyOf(biMap);
this.codecRegistry = MongoClientSettings.getDefaultCodecRegistry();
}
public static BlazeIdeInterfaceState fromProto(ProjectData.BlazeIdeInterfaceState proto) {
ImmutableMap<String, TargetKey> targets =
ProtoWrapper.map(
proto.getFileToTargetMap(), ArtifactState::migrateOldKeyFormat, TargetKey::fromProto);
ImmutableMap.Builder<String, ArtifactState> artifacts = ImmutableMap.builder();
for (LocalFileOrOutputArtifact output : proto.getIdeInfoFilesList()) {
ArtifactState state = ArtifactStateProtoConverter.fromProto(output);
if (state == null) {
continue;
}
artifacts.put(state.getKey(), state);
}
return new BlazeIdeInterfaceState(artifacts.build(), ImmutableBiMap.copyOf(targets));
}
private static BiMap<String, GraphQLType> getMap(
List<FileDescriptor> fileDescriptors,
List<Descriptor> descriptors,
List<EnumDescriptor> enumDescriptors,
GraphQLInterfaceType nodeInterface,
SchemaOptions schemaOptions) {
HashBiMap<String, GraphQLType> mapping =
HashBiMap.create(getEnumMap(enumDescriptors, schemaOptions));
LinkedList<Descriptor> loop = new LinkedList<>(descriptors);
Set<FileDescriptor> fileDescriptorSet = extractDependencies(fileDescriptors);
for (FileDescriptor fileDescriptor : fileDescriptorSet) {
loop.addAll(fileDescriptor.getMessageTypes());
mapping.putAll(getEnumMap(fileDescriptor.getEnumTypes(), schemaOptions));
}
while (!loop.isEmpty()) {
Descriptor descriptor = loop.pop();
if (!mapping.containsKey(descriptor.getFullName())) {
mapping.put(
ProtoToGql.getReferenceName(descriptor),
ProtoToGql.convert(descriptor, nodeInterface, schemaOptions));
GqlInputConverter inputConverter =
GqlInputConverter.newBuilder().add(descriptor.getFile()).build();
mapping.put(
GqlInputConverter.getReferenceName(descriptor),
inputConverter.getInputType(descriptor, schemaOptions));
loop.addAll(descriptor.getNestedTypes());
mapping.putAll(getEnumMap(descriptor.getEnumTypes(), schemaOptions));
}
}
return ImmutableBiMap.copyOf(mapping);
}
@NotNull
@Override
public String getLocalEndpoint() throws ReaperException {
String cassandraVersion = getCassandraVersion();
if (versionCompare(cassandraVersion, "2.1.10") >= 0) {
return ssProxy.getHostIdToEndpoint().get(ssProxy.getLocalHostId());
} else {
// pre-2.1.10 compatibility
BiMap<String, String> hostIdBiMap = ImmutableBiMap.copyOf(ssProxy.getHostIdMap());
String localHostId = ssProxy.getLocalHostId();
return hostIdBiMap.inverse().get(localHostId);
}
}
@Test public void testGetTokenDefMap_02() {
ITokenDefProvider tokenDefProvider = get(ITokenDefProvider.class);
ImmutableBiMap<Integer, String> tokens = ImmutableBiMap.copyOf(tokenDefProvider.getTokenDefMap());
ImmutableBiMap<String,Integer> inverseTokens = tokens.inverse();
assertTrue("'\n'", inverseTokens.containsKey("'\n'"));
assertTrue("'\r'", inverseTokens.containsKey("'\r'"));
assertTrue("RULE_ID", inverseTokens.containsKey("RULE_ID"));
assertTrue("RULE_ANY_OTHER", inverseTokens.containsKey("RULE_ANY_OTHER"));
assertTrue("RULE_WS", inverseTokens.containsKey("RULE_WS"));
}
protected ObfuscatedStateMapper() {
LOGGER.info("Using build mapping \"" + ForgeHaxProperties.getMcpMappingUrl() + "\"");
MCPMappingLoader mcpMappingLoader = null;
try {
mcpMappingLoader = new MCPMappingLoader(ForgeHaxProperties.getMcpMappingUrl());
} catch (Exception e) {
LOGGER.error(e.getMessage());
ASMStackLogger.printStackTrace(e);
}
LOGGER.info("Mapping data successfully initialize");
Objects.requireNonNull(mcpMappingLoader, "MCPMappingLoader failed to lookup obfuscation data");
if (isObfuscated()) {
LOGGER.info("initializing ObfuscatedStateMapper WITH obfuscation");
} else {
LOGGER.info("initializing ObfuscatedStateMapper WITHOUT obfuscation");
}
this.mcClasses =
ImmutableBiMap.copyOf(
FastReflectionForge.Fields.FMLDeobfuscatingRemapper_classNameBiMap.get(
FMLDeobfuscatingRemapper.INSTANCE));
this.mcpMethodData =
buildMcpTypeData(
mcpMappingLoader.getCsvMethodData(),
mcpMappingLoader.getSrgFileData().class2MethodDataSet,
getConvertedMap(
FastReflectionForge.Fields.FMLDeobfuscatingRemapper_rawMethodMaps.get(
FMLDeobfuscatingRemapper.INSTANCE),
str -> str.split("\\(")[0]),
((csvData, data) -> csvData.getMcpName() + data.getSrgDescriptor()));
this.mcpFieldData =
buildMcpTypeData(
mcpMappingLoader.getCsvFieldData(),
mcpMappingLoader.getSrgFileData().class2FieldDataSet,
getConvertedMap(
FastReflectionForge.Fields.FMLDeobfuscatingRemapper_rawFieldMaps.get(
FMLDeobfuscatingRemapper.INSTANCE),
str -> str.split(":")[0]),
((csvData, data) -> csvData.getMcpName()));
}
/**
* creates an immutable copy of the biMap
* @return immutable version of the biMap
*/
@Override
public ImmutableBiMap<K,V> view() {
return ImmutableBiMap.copyOf(map);
}
public RuleNames(Grammar grammar, boolean installAdapter) {
this.contextGrammar = grammar;
Adapter adapter = new Adapter(this);
if (installAdapter) {
installAdapterIfMissing(adapter, grammar);
}
List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
ImmutableListMultimap.Builder<String, AbstractRule> simpleNameToRulesBuilder = ImmutableListMultimap.builder();
ImmutableMap.Builder<String, AbstractRule> qualifiedNameToRuleBuilder = ImmutableMap.builder();
ImmutableBiMap.Builder<String, AbstractRule> uniqueNameToRuleBuilder = ImmutableBiMap.builder();
ImmutableBiMap.Builder<String, AbstractRule> antlrNameToRuleBuilder = ImmutableBiMap.builder();
Map<String, AbstractRule> names = Maps.newHashMap();
Set<String> usedAntlrNames = Sets.newHashSet();
Set<String> usedUniqueNames = Sets.newHashSet();
for(AbstractRule rule: allRules) {
String name = rule.getName();
simpleNameToRulesBuilder.put(name, rule);
String qualifiedName = getQualifiedName(rule);
qualifiedNameToRuleBuilder.put(qualifiedName, rule);
String uniqueName = name;
String antlrRuleName;
if (names.containsKey(name)) {
name = qualifiedName;
uniqueName = getInheritedUniqueName(rule, usedUniqueNames);
antlrRuleName = getInheritedAntlrRuleName(rule, usedAntlrNames);
} else {
antlrRuleName = getDefaultAntlrRuleName(rule);
}
names.put(name, rule);
if (!usedUniqueNames.add(uniqueName)) {
throw new IllegalStateException(uniqueName);
}
uniqueNameToRuleBuilder.put(uniqueName, rule);
if (!usedAntlrNames.add(antlrRuleName)) {
throw new IllegalStateException(antlrRuleName);
}
antlrNameToRuleBuilder.put(antlrRuleName, rule);
if (installAdapter) {
installAdapterIfMissing(adapter, rule);
}
}
simpleNameToRules = simpleNameToRulesBuilder.build();
qualifiedNameToRule = qualifiedNameToRuleBuilder.build();
nameToRule = ImmutableBiMap.copyOf(names);
uniqueNameToRule = uniqueNameToRuleBuilder.build();
antlrNameToRule = antlrNameToRuleBuilder.build();
this.allRules = ImmutableList.copyOf(allRules);
}
static <N, E> DirectedNodeConnections<N, E> ofImmutable(Map<E, N> inEdges, Map<E, N> outEdges) {
return new DirectedNodeConnections<N, E>(ImmutableBiMap.copyOf(inEdges), ImmutableBiMap.copyOf(outEdges));
}
static <N, E> UndirectedNodeConnections<N, E> ofImmutable(Map<E, N> incidentEdges) {
return new UndirectedNodeConnections<N, E>(ImmutableBiMap.copyOf(incidentEdges));
}
@Override
public BiMap<FieldName, Predictor> load(GeneralRegressionModel generalRegressionModel){
return ImmutableBiMap.copyOf(parsePredictorRegistry(generalRegressionModel.getCovariateList()));
}
static <N, E> DirectedNodeConnections<N, E> ofImmutable(Map<E, N> inEdges, Map<E, N> outEdges) {
return new DirectedNodeConnections<N, E>(ImmutableBiMap.copyOf(inEdges), ImmutableBiMap.copyOf(outEdges));
}
static <N, E> DirectedNodeConnections<N, E> ofImmutable(Map<E, N> inEdges, Map<E, N> outEdges) {
return new DirectedNodeConnections<N, E>(ImmutableBiMap.copyOf(inEdges), ImmutableBiMap.copyOf(outEdges));
}
static <N, E> DirectedNodeConnections<N, E> ofImmutable(Map<E, N> inEdges, Map<E, N> outEdges) {
return new DirectedNodeConnections<N, E>(
ImmutableBiMap.copyOf(inEdges), ImmutableBiMap.copyOf(outEdges));
}
static <N, E> UndirectedNodeConnections<N, E> ofImmutable(Map<E, N> incidentEdges) {
return new UndirectedNodeConnections<N, E>(ImmutableBiMap.copyOf(incidentEdges));
}