List of usage examples for org.apache.commons.lang3.tuple Pair getValue
@Override
public R getValue()
Gets the value from this pair.
This method implements the Map.Entry interface returning the right element as the value.
From source file:com.astamuse.asta4d.util.i18n.MappedParamI18nMessageHelper.java
@SuppressWarnings("rawtypes") private Map<String, Object> pairToMap(Pair[] params) { Map<String, Object> map = new HashMap<>(); for (Pair pair : params) { map.put(pair.getKey().toString(), pair.getValue()); }/*w w w.j a v a 2s. com*/ return map; }
From source file:emily.games.game2048.Grid.java
public void addRandomTwo() { Pair<Integer, Integer> pos = getRandomFreePosition(); board[pos.getKey()][pos.getValue()] = 2; }
From source file:lineage2.gameserver.network.clientpackets.ConfirmDlg.java
/** * Method runImpl.//from w w w. j ava2s . c om */ @Override protected void runImpl() { Player activeChar = getClient().getActiveChar(); if (activeChar == null) { return; } Pair<Integer, OnAnswerListener> entry = activeChar.getAskListener(true); if ((entry == null) || (entry.getKey() != _requestId)) { return; } OnAnswerListener listener = entry.getValue(); if (_answer == 1) { listener.sayYes(); } else { listener.sayNo(); } }
From source file:com.acmutv.ontoqa.benchmark.advanced.QuestionA01Test.java
/** * Tests the question-answering with parsing. * @throws QuestionException when the question is malformed. * @throws OntoqaFatalException when the question cannot be processed due to some fatal errors. */// w ww . j a v a 2 s.c o m @Test public void test_nlp() throws Exception { final Grammar grammar = Common.getGrammar(); final Ontology ontology = Common.getOntology(); final Pair<Query, Answer> result = CoreController.process(QUESTION, grammar, ontology); final Query query = result.getKey(); final Answer answer = result.getValue(); LOGGER.info("Query: {}", query); LOGGER.info("Answer: {}", answer); Assert.assertTrue(QUERY.equals(query.toString()) || QUERY_bis.equals(query.toString())); Assert.assertEquals(ANSWER, answer); }
From source file:ch.uzh.phys.ecn.oboma.agents.model.Agent.java
public int getPreferredTimeOfStay(String pNodeId) { for (Pair<String, Integer> item : this.mRoute) { if (item.getKey().equals(pNodeId)) { return item.getValue(); }//from ww w .j a v a 2s . c o m } return 1; }
From source file:com.vmware.photon.controller.common.xenon.ServiceHostUtils.java
public static void waitForNodeGroupConvergence(ServiceHost localHost, Collection<Pair<String, Integer>> remoteHostIpAndPortPairs, String nodeGroupPath, int maxRetries, int retryInterval) throws Throwable { checkArgument(localHost != null, "localHost cannot be null"); checkArgument(remoteHostIpAndPortPairs != null, "remoteHostIpAndPortPairs cannot be null"); checkArgument(!Strings.isNullOrEmpty(nodeGroupPath), "nodeGroupPath cannot be null or empty"); checkArgument(maxRetries > 0, "maxRetries must be > 0"); for (Pair<String, Integer> remoteHostIpAndPortPair : remoteHostIpAndPortPairs) { int checkRetries = maxRetries; int checksToConvergence = REQUIRED_STABLE_STATE_COUNT; while (checkRetries > 0 && checksToConvergence > 0) { // update retry count and sleep checkRetries--;//from www .j a v a 2 s . co m Thread.sleep(retryInterval * checksToConvergence); // check the host response NodeGroupService.NodeGroupState response = getNodeGroupState(localHost, remoteHostIpAndPortPair.getKey(), remoteHostIpAndPortPair.getValue(), nodeGroupPath); if (response.nodes.size() < remoteHostIpAndPortPairs.size()) { continue; } // check host status checksToConvergence--; for (NodeState nodeState : response.nodes.values()) { if (nodeState.status != NodeState.NodeStatus.AVAILABLE) { checksToConvergence = REQUIRED_STABLE_STATE_COUNT; break; // Note that we are not breaking from the above while loop where checksToConvergence is done // This is because the nodes might switch between AVAILABLE and SYNCHRONIZING as the other nodes join } } } if (checkRetries == 0) { throw new TimeoutException("nodes did not converge"); } } }
From source file:io.confluent.kafka.connect.source.io.processing.csv.SchemaConfigTest.java
@Test public void schema() { SpoolDirectoryConfig config = new SpoolDirectoryConfig(Data.settings(Files.createTempDir())); final SchemaConfig input = Data.schemaConfig(); final Schema expectedValueSchema = SchemaBuilder.struct().name("io.confluent.kafka.connect.source.MockData") .field("id", Schema.INT32_SCHEMA).field("first_name", Schema.STRING_SCHEMA) .field("last_name", Schema.STRING_SCHEMA).field("email", Schema.STRING_SCHEMA) .field("gender", Schema.STRING_SCHEMA).field("ip_address", Schema.STRING_SCHEMA) .field("last_login", Timestamp.builder().optional()) .field("account_balance", Decimal.builder(10).optional()).field("country", Schema.STRING_SCHEMA) .field("favorite_color", Schema.OPTIONAL_STRING_SCHEMA).build(); final Schema expectedKeySchema = SchemaBuilder.struct() .name("io.confluent.kafka.connect.source.MockDataKey").field("id", Schema.INT32_SCHEMA).build(); final Pair<SchemaConfig.ParserConfig, SchemaConfig.ParserConfig> actual = input.parserConfigs(config); System.out.println(actual.getKey()); System.out.println(actual.getValue()); assertSchema(expectedKeySchema, actual.getKey().structSchema); assertSchema(expectedValueSchema, actual.getValue().structSchema); }
From source file:io.confluent.kafka.connect.source.io.processing.csv.SchemaConfigTest.java
@Test public void schemaNoKeys() { SpoolDirectoryConfig config = new SpoolDirectoryConfig(Data.settings(Files.createTempDir())); final SchemaConfig input = Data.schemaConfig(); input.keys.clear();/*from www .ja va 2s. c om*/ final Schema expectedValueSchema = SchemaBuilder.struct().name("io.confluent.kafka.connect.source.MockData") .field("id", Schema.INT32_SCHEMA).field("first_name", Schema.STRING_SCHEMA) .field("last_name", Schema.STRING_SCHEMA).field("email", Schema.STRING_SCHEMA) .field("gender", Schema.STRING_SCHEMA).field("ip_address", Schema.STRING_SCHEMA) .field("last_login", Timestamp.builder().optional()) .field("account_balance", Decimal.builder(10).optional()).field("country", Schema.STRING_SCHEMA) .field("favorite_color", Schema.OPTIONAL_STRING_SCHEMA).build(); final Schema expectedKeySchema = null; final Pair<SchemaConfig.ParserConfig, SchemaConfig.ParserConfig> actual = input.parserConfigs(config); System.out.println(actual.getKey()); System.out.println(actual.getValue()); Assert.assertNull(actual.getKey().structSchema); assertSchema(expectedValueSchema, actual.getValue().structSchema); }
From source file:com.microsoft.tooling.msservices.serviceexplorer.azure.storage.StorageModule.java
@Override protected void refreshItems() throws AzureCmdException { List<Pair<String, String>> failedSubscriptions = new ArrayList<>(); try {/*from w ww. j a v a 2 s . c o m*/ AzureManager azureManager = AuthMethodManager.getInstance().getAzureManager(); // not signed in if (azureManager == null) { return; } SubscriptionManager subscriptionManager = azureManager.getSubscriptionManager(); Set<String> sidList = subscriptionManager.getAccountSidList(); for (String sid : sidList) { try { Azure azure = azureManager.getAzure(sid); List<com.microsoft.azure.management.storage.StorageAccount> storageAccounts = azure .storageAccounts().list(); for (StorageAccount sm : storageAccounts) { addChildNode(new StorageNode(this, sid, sm)); } } catch (Exception ex) { failedSubscriptions.add(new ImmutablePair<>(sid, ex.getMessage())); continue; } } } catch (Exception ex) { DefaultLoader.getUIHelper() .logError("An error occurred when trying to load Storage Accounts\n\n" + ex.getMessage(), ex); } // public List<ArmStorageAccount> execute(@NotNull Azure azure) throws Throwable { // List<ArmStorageAccount> storageAccounts = new ArrayList<>(); // for (StorageAccount storageAccount : azure.storageAccounts().list()){ // ArmStorageAccount sa = new ArmStorageAccount(storageAccount.name(), subscriptionId, storageAccount); // // sa.setProtocol("https"); // sa.setType(storageAccount.sku().name().toString()); // sa.setLocation(Strings.nullToEmpty(storageAccount.regionName())); // List<StorageAccountKey> keys = storageAccount.keys(); // if (!(keys == null || keys.isEmpty())) { // sa.setPrimaryKey(keys.get(0).value()); // if (keys.size() > 1) { // sa.setSecondaryKey(keys.get(1).value()); // } // } // sa.setResourceGroupName(storageAccount.resourceGroupName()); // storageAccounts.add(sa); // } // return storageAccounts; // } //TODO // load External Accounts for (ClientStorageAccount clientStorageAccount : ExternalStorageHelper.getList(getProject())) { ClientStorageAccount storageAccount = StorageClientSDKManager.getManager() .getStorageAccount(clientStorageAccount.getConnectionString()); // addChildNode(new ExternalStorageNode(this, storageAccount)); } if (!failedSubscriptions.isEmpty()) { StringBuilder errorMessage = new StringBuilder( "An error occurred when trying to load Storage Accounts for the subscriptions:\n\n"); for (Pair error : failedSubscriptions) { errorMessage.append(error.getKey()).append(": ").append(error.getValue()).append("\n"); } DefaultLoader.getUIHelper().logError( "An error occurred when trying to load Storage Accounts\n\n" + errorMessage.toString(), null); } }
From source file:com.nesscomputing.jackson.datatype.CommonsLang3SerializerTest.java
@Test public void testTrumpetPairCompatibility() throws IOException { Pair<String, Boolean> pair = mapper.readValue("{\"car\":\"foo\",\"cdr\":true}", new TypeReference<Pair<String, Boolean>>() { });//from w w w . j a v a2 s .co m assertEquals("foo", pair.getKey()); assertEquals(true, pair.getValue()); }