Java Code Examples for com.google.common.collect.BiMap#put()
The following examples show how to use
com.google.common.collect.BiMap#put() .
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: EnumValueXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testEnumValueFunction() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(EnumValueXPathFunctionTest.class, "/yang-xpath-functions-test/enum-value-function/foo.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode("major")); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("foo-prefix", FOO_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToSeverityLeafNode("major")); final Function enumValueFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "enum-value"); final int enumValueResult = (int) enumValueFunction.call(normalizedNodeContext, ImmutableList.of()); assertEquals(5, enumValueResult); }
Example 2
Source File: ProtoRegistry.java From rejoiner with Apache License 2.0 | 6 votes |
/** Applies the supplied modifications to the GraphQLTypes. */ private static BiMap<String, GraphQLType> modifyTypes( BiMap<String, GraphQLType> mapping, ImmutableListMultimap<String, TypeModification> modifications) { BiMap<String, GraphQLType> result = HashBiMap.create(mapping.size()); for (String key : mapping.keySet()) { if (mapping.get(key) instanceof GraphQLObjectType) { GraphQLObjectType val = (GraphQLObjectType) mapping.get(key); if (modifications.containsKey(key)) { for (TypeModification modification : modifications.get(key)) { val = modification.apply(val); } } result.put(key, val); } else { result.put(key, mapping.get(key)); } } return result; }
Example 3
Source File: ExportAdmins.java From usergrid with Apache License 2.0 | 6 votes |
private void addOrganizationsToTask(AdminUserWriteTask task) throws Exception { task.orgNamesByUuid = managementService.getOrganizationsForAdminUser( task.adminUser.getUuid() ); List<Org> orgs = userToOrgsMap.get( task.adminUser.getUuid() ); if ( orgs != null && task.orgNamesByUuid.size() < orgs.size() ) { // list of orgs from getOrganizationsForAdminUser() is less than expected, use userToOrgsMap BiMap<UUID, String> bimap = HashBiMap.create(); for (Org org : orgs) { bimap.put( org.orgId, org.orgName ); } task.orgNamesByUuid = bimap; } }
Example 4
Source File: ParticipatingClients.java From qpid-broker-j with Apache License 2.0 | 6 votes |
private BiMap<String, String> mapConfiguredToRegisteredClientNames(List<String> configuredClientNamesForTest, ClientRegistry clientRegistry) { BiMap<String, String> configuredToRegisteredNameMap = HashBiMap.create(); TreeSet<String> registeredClients = new TreeSet<String>(clientRegistry.getClients()); for (String configuredClientName : configuredClientNamesForTest) { String allocatedClientName = registeredClients.pollFirst(); if (allocatedClientName == null) { throw new IllegalArgumentException("Too few clients in registry " + clientRegistry + " configured clients " + configuredClientNamesForTest); } configuredToRegisteredNameMap.put(configuredClientName, allocatedClientName); } return configuredToRegisteredNameMap; }
Example 5
Source File: DerivedFromXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testInvalidNormalizedNodeValueType() throws Exception { final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(DerivedFromXPathFunctionTest.class, "/yang-xpath-functions-test/derived-from-function/foo.yang", "/yang-xpath-functions-test/derived-from-function/bar.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode("should be QName")); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("bar-prefix", BAR_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToIdrefLeafNode()); final Function derivedFromFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "derived-from"); assertFalse(getDerivedFromResult(derivedFromFunction, normalizedNodeContext, "foo-prefix:id-a3")); }
Example 6
Source File: ToXdr.java From monsoon with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Lookup the index for the argument, or if it isn't present, create one. */ private int simpleGroupPath_index(dictionary_delta dict_delta, SimpleGroupPath group) { final BiMap<SimpleGroupPath, Integer> dict = from_.getGroupDict().inverse(); final Integer resolved = dict.get(group); if (resolved != null) return resolved; final int allocated = allocate_index_(dict); dict.put(group, allocated); // Create new pdd for serialization. path_dictionary_delta gdd = new path_dictionary_delta(); gdd.id = allocated; gdd.value = new_path_(group.getPath()); // Append new entry to array. dict_delta.gdd = Stream.concat(Arrays.stream(dict_delta.gdd), Stream.of(gdd)) .toArray(path_dictionary_delta[]::new); LOG.log(Level.FINE, "dict_delta.gdd: {0} items (added {1})", new Object[]{dict_delta.gdd.length, group}); return allocated; }
Example 7
Source File: ToXdr.java From monsoon with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** Lookup the index for the argument, or if it isn't present, create one. */ private int metricName_index(dictionary_delta dict_delta, MetricName metric) { final BiMap<MetricName, Integer> dict = from_.getMetricDict().inverse(); final Integer resolved = dict.get(metric); if (resolved != null) return resolved; final int allocated = allocate_index_(dict); dict.put(metric, allocated); // Create new pdd for serialization. path_dictionary_delta mdd = new path_dictionary_delta(); mdd.id = allocated; mdd.value = new_path_(metric.getPath()); // Append new entry to array. dict_delta.mdd = Stream.concat(Arrays.stream(dict_delta.mdd), Stream.of(mdd)) .toArray(path_dictionary_delta[]::new); LOG.log(Level.FINE, "dict_delta.mdd: {0} items (added {1})", new Object[]{dict_delta.mdd.length, metric}); return allocated; }
Example 8
Source File: BitIsSetXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 6 votes |
@Test public void testInvalidTypeOfCorrespondingSchemaNode() throws Exception { final Set<String> setOfBits = ImmutableSet.of("UP", "PROMISCUOUS"); final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class, "/yang-xpath-functions-test/bit-is-set-function/foo-invalid.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode(setOfBits)); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("foo-prefix", FOO_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToFlagsLeafNode(setOfBits)); final Function bitIsSetFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "bit-is-set"); boolean bitIsSetResult = (boolean) bitIsSetFunction.call(normalizedNodeContext, ImmutableList.of("UP")); assertFalse(bitIsSetResult); }
Example 9
Source File: ServerTableSizeReaderTest.java From incubator-pinot with Apache License 2.0 | 6 votes |
@Test public void testServerSizeReader() { ServerTableSizeReader reader = new ServerTableSizeReader(executor, httpConnectionManager); BiMap<String, String> endpoints = HashBiMap.create(); for (int i = 0; i < 2; i++) { endpoints.put(serverList.get(i), endpointList.get(i)); } endpoints.put(serverList.get(5), endpointList.get(5)); Map<String, List<SegmentSizeInfo>> serverSizes = reader.getSegmentSizeInfoFromServers(endpoints, "foo", timeoutMsec); Assert.assertEquals(serverSizes.size(), 3); Assert.assertTrue(serverSizes.containsKey(serverList.get(0))); Assert.assertTrue(serverSizes.containsKey(serverList.get(1))); Assert.assertTrue(serverSizes.containsKey(serverList.get(5))); Assert.assertEquals(serverSizes.get(serverList.get(0)), tableInfo1.segments); Assert.assertEquals(serverSizes.get(serverList.get(1)), tableInfo2.segments); Assert.assertEquals(serverSizes.get(serverList.get(5)), tableInfo3.segments); }
Example 10
Source File: PinotHelixResourceManager.java From incubator-pinot with Apache License 2.0 | 6 votes |
/** * Provides admin endpoints for the provided data instances * @param instances instances for which to read endpoints * @return returns map of instances to their admin endpoints. * The return value is a biMap because admin instances are typically used for * http requests. So, on response, we need mapping from the endpoint to the * server instances. With BiMap, both mappings are easily available */ public BiMap<String, String> getDataInstanceAdminEndpoints(Set<String> instances) throws InvalidConfigException { BiMap<String, String> endpointToInstance = HashBiMap.create(instances.size()); for (String instance : instances) { String instanceAdminEndpoint; try { instanceAdminEndpoint = _instanceAdminEndpointCache.get(instance); } catch (ExecutionException e) { String errorMessage = String .format("ExecutionException when getting instance admin endpoint for instance: %s. Error message: %s", instance, e.getMessage()); LOGGER.error(errorMessage, e); throw new InvalidConfigException(errorMessage); } endpointToInstance.put(instance, instanceAdminEndpoint); } return endpointToInstance; }
Example 11
Source File: ManagementServiceImpl.java From usergrid with Apache License 2.0 | 5 votes |
private BiMap<UUID, String> buildOrgBiMap( List<OrganizationInfo> orgs ) { BiMap<UUID, String> organizations = HashBiMap.create(); for ( OrganizationInfo orgInfo : orgs ) { organizations.put( orgInfo.getUuid(), orgInfo.getName() ); } return organizations; }
Example 12
Source File: ZWaveBasicDevicesType.java From arcusplatform with Apache License 2.0 | 5 votes |
private static BiMap<String, Byte> createGenericNamesBiMap() { BiMap<String, Byte> bimap = HashBiMap.create(); bimap.put("AV Control Point", AV_CONTROL_POINT); bimap.put("Display", DISPLAY); bimap.put("Entry Control", ENTRY_CONTROL); bimap.put("Generic Controller", GENERIC_CONTROLLER); bimap.put("Meter", METER); bimap.put("Meter Pulse", METER_PULSE); bimap.put("Non-Interoperable", NON_INTEROPERABLE); bimap.put("Generic Repeater Slave", GENERIC_REPEATER_SLAVE); bimap.put("Security Panel", SECURITY_PANEL); bimap.put("Semi-Interoperable", SEMI_INTEROPERABLE); bimap.put("Sensor Alarm", SENSOR_ALARM); bimap.put("Binary Sensor", SENSOR_BINARY); bimap.put("Sensor Multilevel", SENSOR_MULTILEVEL); bimap.put("Static Controller", GENERIC_STATIC_CONTROLLER); bimap.put("Binary Switch", SWITCH_BINARY); bimap.put("Multilevel Switch", SWITCH_MULTILEVEL); bimap.put("Remote Switch", SWITCH_REMOTE); bimap.put("Toggle Switch", SWITCH_TOGGLE); bimap.put("Thermostat", THERMOSTAT); bimap.put("Ventilation", VENTILATION); bimap.put("Window Covering", WINDOW_COVERING); bimap.put("ZIP Node", ZIP_NODE); bimap.put("Wall Controller", WALL_CONTROLLER); bimap.put("Network Extender", NETWORK_EXTENDER); bimap.put("Appliance", APPLIANCE); bimap.put("Sensor Notification", SENSOR_NOTIFICATION); return bimap; }
Example 13
Source File: TypeDependenceGraph.java From binnavi with Apache License 2.0 | 5 votes |
private static Node createTypeNode(final BaseType baseType, final Graph graph, final BiMap<BaseType, Node> map) { final Node node = map.get(baseType); if (node == null) { final Node newNode = graph.createNode(); map.put(baseType, newNode); return newNode; } else { return node; } }
Example 14
Source File: BitIsSetXPathFunctionTest.java From yangtools with Eclipse Public License 1.0 | 5 votes |
@Test public void testBitIsSetFunction() throws Exception { final Set<String> setOfBits = ImmutableSet.of("UP", "PROMISCUOUS"); final SchemaContext schemaContext = YangParserTestUtils.parseYangResources(BitIsSetXPathFunctionTest.class, "/yang-xpath-functions-test/bit-is-set-function/foo.yang"); assertNotNull(schemaContext); final XPathSchemaContext jaxenSchemaContext = SCHEMA_CONTEXT_FACTORY.createContext(schemaContext); final XPathDocument jaxenDocument = jaxenSchemaContext.createDocument(buildMyContainerNode(setOfBits)); final BiMap<String, QNameModule> converterBiMap = HashBiMap.create(); converterBiMap.put("foo-prefix", FOO_MODULE); final NormalizedNodeContextSupport normalizedNodeContextSupport = NormalizedNodeContextSupport.create( (JaxenDocument) jaxenDocument, Maps.asConverter(converterBiMap)); final NormalizedNodeContext normalizedNodeContext = normalizedNodeContextSupport.createContext( buildPathToFlagsLeafNode(setOfBits)); final Function bitIsSetFunction = normalizedNodeContextSupport.getFunctionContext() .getFunction(null, null, "bit-is-set"); boolean bitIsSetResult = (boolean) bitIsSetFunction.call(normalizedNodeContext, ImmutableList.of("UP")); assertTrue(bitIsSetResult); bitIsSetResult = (boolean) bitIsSetFunction.call(normalizedNodeContext, ImmutableList.of("PROMISCUOUS")); assertTrue(bitIsSetResult); bitIsSetResult = (boolean) bitIsSetFunction.call(normalizedNodeContext, ImmutableList.of("DISABLED")); assertFalse(bitIsSetResult); }
Example 15
Source File: KeywordHelper.java From xtext-core with Eclipse Public License 2.0 | 5 votes |
private BiMap<CharSequence, String> createKeywordMap(Grammar grammar) { List<ParserRule> parserRules = GrammarUtil.allParserRules(grammar); List<EnumRule> enumRules = GrammarUtil.allEnumRules(grammar); Iterator<EObject> iter = Iterators.concat( EcoreUtil.<EObject>getAllContents(parserRules), EcoreUtil.<EObject>getAllContents(enumRules)); Iterator<Keyword> filtered = Iterators.filter(iter, Keyword.class); Iterator<String> transformed = Iterators.transform(filtered, new Function<Keyword, String>() { @Override public String apply(Keyword from) { return from.getValue(); } }); TreeSet<String> treeSet = Sets.newTreeSet(new Comparator<String>() { @Override public int compare(String o1, String o2) { if (o1.length() == o2.length()) return o1.compareTo(o2); return Integer.valueOf(o1.length()).compareTo(Integer.valueOf(o2.length())); } }); Iterators.addAll(treeSet, transformed); BiMap<CharSequence, String> result = HashBiMap.create(); for(String s: treeSet) { CharSequence key = createKey(s); String readableName = toAntlrTokenIdentifier(s); if (result.containsValue(readableName)) { int i = 1; String next = readableName + "_" + i; while(result.containsValue(next)) { i++; next = readableName + "_" + i; } readableName = next; } result.put(key, readableName); } return result; }
Example 16
Source File: LockedTenant.java From vespa with Apache License 2.0 | 5 votes |
public Cloud withDeveloperKey(PublicKey key, Principal principal) { BiMap<PublicKey, Principal> keys = HashBiMap.create(developerKeys); if (keys.containsKey(key)) throw new IllegalArgumentException("Key " + KeyUtils.toPem(key) + " is already owned by " + keys.get(key)); keys.put(key, principal); return new Cloud(name, billingInfo, keys); }
Example 17
Source File: EncDec.java From monsoon with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static <T> int getOrCreate(BiMap<Integer, T> dict, T v, BiConsumer<Integer, T> onCreate) { { final Integer idx = dict.inverse().get(v); if (idx != null) return idx; } final int newIdx = allocateNext(dict); onCreate.accept(newIdx, v); dict.put(newIdx, v); return newIdx; }
Example 18
Source File: GuavaBiMapUnitTest.java From tutorials with MIT License | 5 votes |
@Test public void whenQueryByValue_returnsKey() { final BiMap<String, String> capitalCountryBiMap = HashBiMap.create(); capitalCountryBiMap.put("New Delhi", "India"); capitalCountryBiMap.put("Washingon, D.C.", "USA"); capitalCountryBiMap.put("Moscow", "Russia"); final String countryCapitalName = capitalCountryBiMap.inverse().get("India"); assertEquals("New Delhi", countryCapitalName); }
Example 19
Source File: VariantSimilarity.java From dataflow-java with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws IOException, GeneralSecurityException { // Register the options so that they show up via --help PipelineOptionsFactory.register(Options.class); Options options = PipelineOptionsFactory.fromArgs(args) .withValidation().as(Options.class); // Option validation is not yet automatic, we make an explicit call here. Options.Methods.validateOptions(options); // Set up the prototype request and auth. StreamVariantsRequest prototype = CallSetNamesOptions.Methods.getRequestPrototype(options); OfflineAuth auth = GenomicsOptions.Methods.getGenomicsAuth(options); // Make a bimap of the callsets so that the indices the pipeline is passing around are small. List<String> callSetNames = (0 < prototype.getCallSetIdsCount()) ? Lists.newArrayList(CallSetNamesOptions.Methods.getCallSetNames(options)) : GenomicsUtils.getCallSetsNames(options.getVariantSetId(), auth); Collections.sort(callSetNames); // Ensure a stable sort order for reproducible results. BiMap<String, Integer> dataIndices = HashBiMap.create(); for(String callSetName : callSetNames) { dataIndices.put(callSetName, dataIndices.size()); } Pipeline p = Pipeline.create(options); p.begin(); PCollection<StreamVariantsRequest> requests; if(null != options.getSitesFilepath()) { // Compute PCA on a list of sites. requests = p.apply("ReadSites", TextIO.read().from(options.getSitesFilepath())) .apply(new SitesToShards.SitesToStreamVariantsShardsTransform(prototype)); } else { // Compute PCA over genomic regions. List<StreamVariantsRequest> shardRequests = options.isAllReferences() ? ShardUtils.getVariantRequests(prototype, ShardUtils.SexChromosomeFilter.EXCLUDE_XY, options.getBasesPerShard(), auth) : ShardUtils.getVariantRequests(prototype, options.getBasesPerShard(), options.getReferences()); requests = p.apply(Create.of(shardRequests)); } requests.apply(new VariantStreamer(auth, ShardBoundary.Requirement.STRICT, VARIANT_FIELDS)) .apply(ParDo.of(new ExtractSimilarCallsets())) .apply(new OutputPCoAFile(dataIndices, options.getOutput())); PipelineResult result = p.run(); if(options.getWait()) { result.waitUntilFinish(); } }
Example 20
Source File: JaxenTest.java From yangtools with Eclipse Public License 1.0 | 4 votes |
private Converter<String, QNameModule> createPrefixes() { BiMap<String, QNameModule> currentConverter = HashBiMap.create(); currentConverter.put("test2", moduleQName); return Maps.asConverter(currentConverter); }