List of usage examples for org.apache.commons.lang3.tuple Pair of
public static <L, R> Pair<L, R> of(final L left, final R right)
Obtains an immutable pair of from two objects inferring the generic types.
This factory allows the pair to be created using inference to obtain the generic types.
From source file:de.codecentric.batch.metrics.BatchMetricsImpl.java
@Override public void submit(String metricName, double value) { if (TransactionSynchronizationManager.isSynchronizationActive()) { initializeMetricContainerAndRegisterTransactionSynchronizationIfNecessary(); metricContainer.get().metrics.add(Pair.of(metricName, value)); } else {// w w w .j a va 2 s. c o m set(metricName, value); } }
From source file:com.vmware.photon.controller.common.dcp.ServiceHostUtils.java
public static void waitForNodeGroupConvergence(ServiceHost[] hosts, String nodeGroupPath, int maxRetries, int retryInterval) throws Throwable { checkArgument(hosts != null, "hosts cannot be null"); checkArgument(hosts.length > 0, "hosts cannot be empty"); checkArgument(!Strings.isNullOrEmpty(nodeGroupPath), "nodeGroupPath cannot be null or empty"); checkArgument(maxRetries > 0, "maxRetries must be > 0"); if (hosts.length == 1) { // nothing to synchronize if we only have one host return;/*ww w . ja v a 2s . c om*/ } List<Pair<String, Integer>> remoteHostIpAndPortPairs = new ArrayList<>(); for (ServiceHost host : hosts) { remoteHostIpAndPortPairs.add(Pair.of(host.getState().bindAddress, host.getPort())); } waitForNodeGroupConvergence(hosts[0], remoteHostIpAndPortPairs, nodeGroupPath, maxRetries, retryInterval); }
From source file:com.github.steveash.jg2p.align.FilterWalkerDecorator.java
@Override public void backward(Word x, Word y, final Visitor visitor) { delegate.backward(x, y, new Visitor() { @Override/*w w w . jav a 2 s. com*/ public void visit(int xxBefore, int xxAfter, String xGram, int yyBefore, int yyAfter, String yGram) { if (isAllowed(xGram, yGram)) { visitor.visit(xxBefore, xxAfter, xGram, yyBefore, yyAfter, yGram); } else { blocked.add(Pair.of(xGram, yGram)); } } }); }
From source file:edu.umd.umiacs.clip.tools.scor.WordVectorUtils.java
public static void enStem(String input, String output) { Set<String> allWords = new HashSet<>(); List<String> lines = new ArrayList<>(); lines(input).map(line -> line.split(" ")).filter(fields -> fields.length > 2) .map(fields -> Pair.of(fields[0].equals("</s>") ? fields[0] : LuceneUtils.enStem(fields[0]), Stream.of(fields).skip(1).collect(joining(" ")))) .filter(pair -> !pair.getLeft().isEmpty() && !pair.getLeft().contains(" ") && !allWords.contains(pair.getLeft())) .peek(pair -> allWords.add(pair.getLeft())).map(pair -> pair.getLeft() + " " + pair.getRight()) .forEach(lines::add);//from w w w . j a v a 2 s . c o m lines.add(0, lines.size() + " " + (lines.get(0).split(" ").length - 1)); write(output, lines, REMOVE_OLD_FILE); }
From source file:io.cloudslang.lang.runtime.steps.ActionSteps.java
public void doAction(@Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv, @Param(ExecutionParametersConsts.NON_SERIALIZABLE_EXECUTION_DATA) Map<String, Object> nonSerializableExecutionData, @Param(ScoreLangConstants.ACTION_TYPE) ActionType actionType, @Param(ScoreLangConstants.ACTION_CLASS_KEY) String className, @Param(ScoreLangConstants.ACTION_METHOD_KEY) String methodName, @Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices, @Param(ScoreLangConstants.PYTHON_SCRIPT_KEY) String python_script, @Param(ScoreLangConstants.NEXT_STEP_ID_KEY) Long nextStepId) { Map<String, Serializable> returnValue = new HashMap<>(); Map<String, Serializable> callArguments = runEnv.removeCallArguments(); Map<String, SerializableSessionObject> serializableSessionData = runEnv.getSerializableDataMap(); fireEvent(executionRuntimeServices, runEnv, ScoreLangConstants.EVENT_ACTION_START, "Preparing to run action " + actionType, Pair.of(LanguageEventData.CALL_ARGUMENTS, (Serializable) callArguments)); try {//from ww w. j a v a 2 s . com switch (actionType) { case JAVA: returnValue = runJavaAction(serializableSessionData, callArguments, nonSerializableExecutionData, className, methodName); break; case PYTHON: returnValue = prepareAndRunPythonAction(callArguments, python_script); break; default: break; } } catch (RuntimeException ex) { fireEvent(executionRuntimeServices, runEnv, ScoreLangConstants.EVENT_ACTION_ERROR, ex.getMessage(), Pair.of(LanguageEventData.EXCEPTION, ex.getMessage())); logger.error(ex); throw (ex); } //todo: hook ReturnValues returnValues = new ReturnValues(returnValue, null); runEnv.putReturnValues(returnValues); fireEvent(executionRuntimeServices, runEnv, ScoreLangConstants.EVENT_ACTION_END, "Action performed", Pair.of(LanguageEventData.RETURN_VALUES, (Serializable) returnValue)); runEnv.putNextStepPosition(nextStepId); }
From source file:co.rsk.peg.BridgeSerializationUtils.java
public static SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> deserializePairMap(byte[] data, NetworkParameters networkParameters) { SortedMap<Sha3Hash, Pair<BtcTransaction, Long>> map = new TreeMap<>(); if (data == null || data.length == 0) return map; RLPList rlpList = (RLPList) RLP.decode2(data).get(0); int ntxs = rlpList.size() / 3; for (int k = 0; k < ntxs; k++) { Sha3Hash hash = new Sha3Hash(rlpList.get(k * 3).getRLPData()); BtcTransaction tx = new BtcTransaction(networkParameters, rlpList.get(k * 3 + 1).getRLPData()); byte[] lkeyBytes = rlpList.get(k * 3 + 2).getRLPData(); Long lkey = lkeyBytes == null ? 0 : (new BigInteger(1, lkeyBytes)).longValue(); map.put(hash, Pair.of(tx, lkey)); }// w ww . j a va 2s . c om return map; }
From source file:io.cloudslang.lang.runtime.steps.AsyncLoopSteps.java
public void addBranches( @Param(ScoreLangConstants.ASYNC_LOOP_STATEMENT_KEY) AsyncLoopStatement asyncLoopStatement, @Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv, @Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices, @Param(ScoreLangConstants.NODE_NAME_KEY) String nodeName, @Param(ExecutionParametersConsts.RUNNING_EXECUTION_PLAN_ID) Long RUNNING_EXECUTION_PLAN_ID, @Param(ScoreLangConstants.NEXT_STEP_ID_KEY) Long nextStepId, @Param(ScoreLangConstants.BRANCH_BEGIN_STEP_ID_KEY) Long branchBeginStep, @Param(ScoreLangConstants.REF_ID) String refId) { try {//from ww w . ja v a2 s .c om Context flowContext = runEnv.getStack().popContext(); List<Serializable> splitData = asyncLoopBinding.bindAsyncLoopList(asyncLoopStatement, flowContext, nodeName); fireEvent(executionRuntimeServices, ScoreLangConstants.EVENT_ASYNC_LOOP_EXPRESSION_END, "async loop expression bound", runEnv.getExecutionPath().getCurrentPathPeekForward(), Pair.of(LanguageEventData.BOUND_ASYNC_LOOP_EXPRESSION, (Serializable) splitData), Pair.of(LanguageEventData.levelName.TASK_NAME.name(), nodeName)); runEnv.putNextStepPosition(nextStepId); for (Serializable splitItem : splitData) { RunEnvironment branchRuntimeEnvironment = (RunEnvironment) SerializationUtils.clone(runEnv); Context branchContext = (Context) SerializationUtils.clone(flowContext); branchContext.putVariable(asyncLoopStatement.getVarName(), splitItem); updateCallArgumentsAndPushContextToStack(branchRuntimeEnvironment, branchContext, new HashMap<String, Serializable>()); createBranch(branchRuntimeEnvironment, executionRuntimeServices, RUNNING_EXECUTION_PLAN_ID, refId, nextStepId, branchBeginStep); fireEvent(executionRuntimeServices, ScoreLangConstants.EVENT_BRANCH_START, "async loop branch created", runEnv.getExecutionPath().getCurrentPathPeekForward(), Pair.of(ScoreLangConstants.REF_ID, refId), Pair.of(RuntimeConstants.SPLIT_ITEM_KEY, splitItem), Pair.of(LanguageEventData.levelName.TASK_NAME.name(), nodeName)); } updateCallArgumentsAndPushContextToStack(runEnv, flowContext, new HashMap<String, Serializable>()); // forward after the branches are created because begin task method also calls forward runEnv.getExecutionPath().forward(); } catch (RuntimeException e) { logger.error("There was an error running the add branches execution step of: \'" + nodeName + "\'. Error is: " + e.getMessage()); throw new RuntimeException("Error running: " + nodeName + ": " + e.getMessage(), e); } }
From source file:edu.wpi.checksims.algorithm.AlgorithmRunnerTest.java
@Test public void TestRunAlgorithmTwoPairs() { Set<Pair<Submission, Submission>> submissions = setFromElements(Pair.of(a, b), Pair.of(a, c)); Collection<AlgorithmResults> results = AlgorithmRunner.runAlgorithm(submissions, detectNothing); AlgorithmUtils.checkResultsContainsPairs(results, submissions); }
From source file:cherry.goods.telno.SoumuExcelParserTest.java
@Test public void testParse6() throws Exception { Map<String, Pair<String, String>> map; try (InputStream in = getClass().getResourceAsStream("soumu/000124075.xls")) { map = parser.parse(in);/*w w w .j a v a2 s . co m*/ } assertEquals(3000, map.size()); assertEquals(Pair.of("06", "4000"), map.get("064000")); assertEquals(Pair.of("06", "7999"), map.get("067999")); }
From source file:com.yahoo.bullet.storm.StormUtilsTest.java
private void assertContains(Map<Pair<String, String>, List<Fields>> groupings, String component, String stream, Fields... fields) {//from ww w. ja v a2 s . co m List<Fields> actuals = groupings.get(Pair.of(component, stream)); Assert.assertNotNull(actuals); List<Fields> expecteds = Arrays.asList(fields); Assert.assertEquals(actuals.size(), expecteds.size()); for (int i = 0; i < actuals.size(); ++i) { Assert.assertEquals(actuals.get(i).toList(), expecteds.get(i).toList()); } }