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.acmutv.ontoqa.benchmark.basic.QuestionB01Test.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 w w .jav a 2 s . c om*/ @Test public void test_nlp_wired() throws Exception { final Grammar grammar = CommonGrammar.build_completeGrammar(); 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.assertEquals(QUERY_2, query.toString()); Assert.assertEquals(ANSWER, answer); }
From source file:forge.game.GameOutcome.java
/** * Gets the win spell effect./*from w w w . j av a 2 s. co m*/ * * @return the win spell effect */ public String getWinSpellEffect() { for (Pair<LobbyPlayer, PlayerStatistics> pv : playerRating) { PlayerOutcome po = pv.getValue().getOutcome(); if (po.hasWon()) { return po.altWinSourceName; } } return null; }
From source file:com.snaplogic.snaps.lunex.RequestProcessor.java
public String execute(RequestBuilder rBuilder) throws MalformedURLException, IOException { try {/*from w w w . ja va2 s .co m*/ URL api_url = new URL(rBuilder.getURL()); HttpURLConnection httpUrlConnection = (HttpURLConnection) api_url.openConnection(); httpUrlConnection.setRequestMethod(rBuilder.getMethod().toString()); httpUrlConnection.setDoInput(true); httpUrlConnection.setDoOutput(true); if (rBuilder.getSnapType() != LunexSnaps.Read) { rBuilder.getHeaders().add(Pair.of(CONTENT_LENGTH, rBuilder.getRequestBodyLenght())); } for (Pair<String, String> header : rBuilder.getHeaders()) { if (!StringUtils.isEmpty(header.getKey()) && !StringUtils.isEmpty(header.getValue())) { httpUrlConnection.setRequestProperty(header.getKey(), header.getValue()); } } log.debug(String.format(LUNEX_HTTP_INFO, rBuilder.getSnapType(), rBuilder.getURL(), httpUrlConnection.getRequestProperties().toString())); if (rBuilder.getSnapType() != LunexSnaps.Read) { String paramsJson = null; if (!StringUtils.isEmpty(paramsJson = rBuilder.getRequestBody())) { DataOutputStream cgiInput = new DataOutputStream(httpUrlConnection.getOutputStream()); log.debug(String.format(LUNEX_HTTP_REQ_INFO, paramsJson)); cgiInput.writeBytes(paramsJson); cgiInput.flush(); IOUtils.closeQuietly(cgiInput); } } List<String> input = null; StringBuilder response = new StringBuilder(); try (InputStream iStream = httpUrlConnection.getInputStream()) { input = IOUtils.readLines(iStream); } catch (IOException ioe) { log.warn(String.format(INPUT_STREAM_ERROR, ioe.getMessage())); try (InputStream eStream = httpUrlConnection.getErrorStream()) { if (eStream != null) { input = IOUtils.readLines(eStream); } else { response.append(String.format(INPUT_STREAM_ERROR, ioe.getMessage())); } } catch (IOException ioe1) { log.warn(String.format(INPUT_STREAM_ERROR, ioe1.getMessage())); } } statusCode = httpUrlConnection.getResponseCode(); log.debug(String.format(HTTP_STATUS, statusCode)); if (input != null && !input.isEmpty()) { for (String line : input) { response.append(line); } } return formatResponse(response, rBuilder); } catch (MalformedURLException me) { log.error(me.getMessage(), me); throw me; } catch (IOException ioe) { log.error(ioe.getMessage(), ioe); throw ioe; } catch (Exception ex) { log.error(ex.getMessage(), ex); throw ex; } }
From source file:com.evolveum.midpoint.prism.path.CanonicalItemPath.java
private String extractExplicitReplacements(String uri) { for (Pair<String, String> mapping : EXPLICIT_REPLACEMENTS) { if (uri.startsWith(mapping.getKey())) { return SHORTCUT_MARKER_START + mapping.getValue() + SHORTCUT_MARKER_END + uri.substring(mapping.getKey().length()); }/*from ww w. j av a 2 s .co m*/ } return uri; }
From source file:com.dangdang.config.service.zookeeper.ZookeeperConfigGroup.java
void reloadKey(final String nodePath) { try {/* w w w. j a v a2s . com*/ Pair<String, String> keyValue = loadKey(nodePath); if (keyValue != null) { super.put(keyValue.getKey(), keyValue.getValue()); } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:com.michellemay.URLLanguageDetectorTest.java
public void validateTestCases(URLLanguageDetector detector, List<Pair<String, String>> testCases) throws Exception { List<Pair<Pair<String, String>, Optional<Locale>>> failedTests = testCases.stream() .map((test) -> Pair.of(test, detector.detect(test.getKey()))).filter((testAndResult) -> { Pair<String, String> test = testAndResult.getKey(); Optional<Locale> detectedLanguage = testAndResult.getValue(); boolean localTestFailed = (detectedLanguage.isPresent() != !test.getValue().isEmpty()); if (!localTestFailed && detectedLanguage.isPresent()) { localTestFailed = !detectedLanguage.get().equals(LocaleUtils.toLocale(test.getValue())); }/*from w ww.j av a2s . com*/ return localTestFailed; }).collect(Collectors.toList()); failedTests .forEach((test) -> System.out.println("FAILED: " + test.getKey() + ", FOUND: " + test.getValue())); assertTrue(failedTests.isEmpty()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForOneDay() { int numberOfDays = 1; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusDays(numberOfDays); Pair<String, Integer> dayPair = PeriodUtils.period(start, end); assertEquals(DAY_LABEL, dayPair.getKey()); assertEquals(numberOfDays, (int) dayPair.getValue()); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForDays() { int numberOfDays = 3; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusDays(numberOfDays); Pair<String, Integer> dayPair = PeriodUtils.period(start, end); assertEquals(DAYS_LABEL, dayPair.getKey()); assertEquals(numberOfDays, (int) dayPair.getValue()); }
From source file:com.acmutv.ontoqa.benchmark.basic.QuestionB03Test.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. *///from ww w . j av a 2 s . c o m @Test public void test_nlp_wired() throws Exception { final Grammar grammar = CommonGrammar.build_completeGrammar(); 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_2.equals(query.toString()) || QUERY_2_bis.equals(query.toString())); Assert.assertEquals(ANSWER, answer); }
From source file:com.trenako.utility.PeriodUtilsTests.java
@Test public void shouldCalculatePeriodForOneWeek() { int numberOfWeeks = 1; DateTime start = new DateTime(2010, 1, 1, 10, 30); DateTime end = start.plusWeeks(numberOfWeeks); Pair<String, Integer> weekPair = PeriodUtils.period(start, end); assertEquals(WEEK_LABEL, weekPair.getKey()); assertEquals(numberOfWeeks, (int) weekPair.getValue()); }