Java Code Examples for com.google.common.collect.ImmutableBiMap#copyOf()
The following examples show how to use
com.google.common.collect.ImmutableBiMap#copyOf() .
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: AggregationQuery.java From immutables with Apache License 2.0 | 7 votes |
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(); }
Example 2
Source File: FDBReverseDirectoryCacheTest.java From fdb-record-layer with Apache License 2.0 | 6 votes |
@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); }
Example 3
Source File: GqlInputConverter.java From rejoiner with Apache License 2.0 | 6 votes |
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)); }
Example 4
Source File: AccessibilityHierarchyAndroid.java From Accessibility-Test-Framework-for-Android with Apache License 2.0 | 6 votes |
/** * 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); }
Example 5
Source File: AutoValueOrOneOfProcessor.java From auto with Apache License 2.0 | 6 votes |
/** 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); }
Example 6
Source File: UniqueCachedNaming.java From immutables with Apache License 2.0 | 6 votes |
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); }
Example 7
Source File: AbstractBug301935Test.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
@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")); }
Example 8
Source File: BlazeIdeInterfaceState.java From intellij with Apache License 2.0 | 5 votes |
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)); }
Example 9
Source File: JmxProxyImpl.java From cassandra-reaper with Apache License 2.0 | 5 votes |
@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); } }
Example 10
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 5 votes |
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); }
Example 11
Source File: UndirectedNodeConnections.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
static <N, E> UndirectedNodeConnections<N, E> ofImmutable(Map<E, N> incidentEdges) { return new UndirectedNodeConnections<N, E>(ImmutableBiMap.copyOf(incidentEdges)); }
Example 12
Source File: GeneralRegressionModelEvaluator.java From jpmml-evaluator with GNU Affero General Public License v3.0 | 4 votes |
@Override public BiMap<FieldName, Predictor> load(GeneralRegressionModel generalRegressionModel){ return ImmutableBiMap.copyOf(parsePredictorRegistry(generalRegressionModel.getCovariateList())); }
Example 13
Source File: DirectedNodeConnections.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
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)); }
Example 14
Source File: DirectedNodeConnections.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
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)); }
Example 15
Source File: RuleNames.java From xtext-core with Eclipse Public License 2.0 | 4 votes |
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); }
Example 16
Source File: DirectedNodeConnections.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
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)); }
Example 17
Source File: HashBiMapState.java From Rails with GNU General Public License v2.0 | 4 votes |
/** * creates an immutable copy of the biMap * @return immutable version of the biMap */ @Override public ImmutableBiMap<K,V> view() { return ImmutableBiMap.copyOf(map); }
Example 18
Source File: DirectedNodeConnections.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
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)); }
Example 19
Source File: UndirectedNodeConnections.java From codebuff with BSD 2-Clause "Simplified" License | 4 votes |
static <N, E> UndirectedNodeConnections<N, E> ofImmutable(Map<E, N> incidentEdges) { return new UndirectedNodeConnections<N, E>(ImmutableBiMap.copyOf(incidentEdges)); }
Example 20
Source File: ObfuscatedStateMapper.java From ForgeHax with MIT License | 4 votes |
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())); }