List of usage examples for org.apache.commons.lang3.tuple Pair getRight
public abstract R getRight();
Gets the right element from this pair.
When treated as a key-value pair, this is the value.
From source file:com.astamuse.asta4d.web.form.field.impl.AbstractRadioAndCheckboxRenderer.java
protected Renderer retrieveAndCreateValueMap(final String editTargetSelector, final String displayTargetSelector) { Renderer render = Renderer.create(); if (PrepareRenderingDataUtil.retrieveStoredDataFromContextBySelector(editTargetSelector) == null) { final List<Pair<String, String>> inputList = new LinkedList<>(); final List<OptionValuePair> optionList = new LinkedList<>(); render.add(editTargetSelector, new ElementSetter() { @Override/*from ww w . j av a2s . co m*/ public void set(Element elem) { inputList.add(Pair.of(elem.id(), elem.attr("value"))); } }); render.add(":root", new Renderable() { @Override public Renderer render() { Renderer render = Renderer.create(); for (Pair<String, String> input : inputList) { String id = input.getLeft(); final String value = input.getRight(); if (StringUtils.isEmpty(id)) { if (allowNonIdItems()) { optionList.add(new OptionValuePair(value, value)); } else { String msg = "The target item[%s] must have id specified."; throw new IllegalArgumentException(String.format(msg, editTargetSelector)); } } else { render.add(SelectorUtil.attr("for", id), Renderer.create("label", new ElementSetter() { @Override public void set(Element elem) { optionList.add(new OptionValuePair(value, elem.text())); } })); render.add(":root", new Renderable() { @Override public Renderer render() { PrepareRenderingDataUtil.storeDataToContextBySelector(editTargetSelector, displayTargetSelector, new OptionValueMap(optionList)); return Renderer.create(); } }); } } // end for loop return render; } }); } return render; }
From source file:com.act.lcms.db.model.PregrowthWell.java
public List<PregrowthWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<String, String> plateAttributes = parser.getPlateProperties(); Map<Pair<String, String>, String> msids = parser.getCompositionTables().get("msid"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(msids.keySet()); Collections.sort(sortedCoordinates, new Comparator<Pair<String, String>>() { // TODO: parse the values of these pairs as we read them so we don't need this silly comparator. @Override/*w ww. ja v a 2 s .co m*/ public int compare(Pair<String, String> o1, Pair<String, String> o2) { if (o1.getKey().equals(o2.getKey())) { return Integer.valueOf(Integer.parseInt(o1.getValue())) .compareTo(Integer.parseInt(o2.getValue())); } return o1.getKey().compareTo(o2.getKey()); } }); List<PregrowthWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String msid = msids.get(coords); if (msid == null || msid.isEmpty()) { continue; } String sourcePlate = parser.getCompositionTables().get("source_plate").get(coords); String sourceWell = parser.getCompositionTables().get("source_well").get(coords); String composition = parser.getCompositionTables().get("composition").get(coords); String note = null; if (parser.getCompositionTables().get("note") != null) { note = parser.getCompositionTables().get("note").get(coords); } // TODO: ditch this when we start using floating point numbers for growth values. Integer growth = null; Map<Pair<String, String>, String> growthTable = parser.getCompositionTables().get("growth"); if (growthTable == null || growthTable.get(coords) == null) { String plateGrowth = plateAttributes.get("growth"); if (plateGrowth != null) { growth = Integer.parseInt(trimAndComplain(plateGrowth)); } } else { String growthStr = growthTable.get(coords); if (PLUS_MINUS_GROWTH_TO_INT.containsKey(growthStr)) { growth = PLUS_MINUS_GROWTH_TO_INT.get(growthStr); } else { growth = Integer.parseInt(growthStr); // If it's not using +/- format, it should be an integer from 1-5. } } Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); PregrowthWell s = INSTANCE.insert(db, p.getId(), index.getLeft(), index.getRight(), sourcePlate, sourceWell, msid, composition, note, growth); results.add(s); } return results; }
From source file:com.act.lcms.MS2.java
List<YZ> spectrumToYZList(LCMSSpectrum spectrum) { List<YZ> yzList = new ArrayList<>(spectrum.getIntensities().size()); for (Pair<Double, Double> p : spectrum.getIntensities()) { yzList.add(new YZ(p.getLeft(), p.getRight())); }/*from w w w . ja va2 s. c o m*/ return yzList; }
From source file:com.microsoft.azure.keyvault.extensions.test.SymmetricKeyBCProviderTest.java
@Test public void testSymmetricKeyDefaultAlgorithmAesKw192() { // Arrange//from ww w . j av a2 s . c o m byte[] KEK = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17 }; byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; byte[] EK = { (byte) 0x96, 0x77, (byte) 0x8B, 0x25, (byte) 0xAE, 0x6C, (byte) 0xA4, 0x35, (byte) 0xF9, 0x2B, 0x5B, (byte) 0x97, (byte) 0xC0, 0x50, (byte) 0xAE, (byte) 0xD2, 0x46, (byte) 0x8A, (byte) 0xB8, (byte) 0xA1, 0x7A, (byte) 0xD8, 0x4E, 0x5D }; SymmetricKey key = new SymmetricKey("KEK", KEK, _provider); byte[] encrypted = null; String algorithm = null; try { Pair<byte[], String> result = key.wrapKeyAsync(CEK, null).get(); encrypted = result.getLeft(); algorithm = result.getRight(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertEquals("A192KW", algorithm); assertArrayEquals(EK, encrypted); byte[] decrypted = null; try { decrypted = key.unwrapKeyAsync(EK, algorithm).get(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertArrayEquals(CEK, decrypted); try { key.close(); } catch (IOException e) { fail("Key could not be closed"); } }
From source file:io.cloudslang.intellij.lang.annotator.ExecutableAnnotator.java
private void createWarningsIfNecessary(final String keyForLookup, final List<PsiElement> commentList, AnnotationHolder holder, final List<Pair<PsiElement, String>> pairElementNameList) { for (Pair<PsiElement, String> pairElementName : pairElementNameList) { final Optional isPresentInDescription = commentList.stream().filter( e -> containsDescriptionForElement(keyForLookup, e.getText(), pairElementName.getRight())) .findAny();/*from ww w. jav a2 s . c om*/ boolean isPrivate = isPrivateInput(pairElementName.getLeft(), keyForLookup); if (!isPresentInDescription.isPresent() && !isPrivate) { holder.createWeakWarningAnnotation(pairElementName.getLeft(), format(MISSING_DOCUMENTATION_FOR_NAME_PATTERN, pairElementName.getRight())); } } }
From source file:com.microsoft.azure.keyvault.extensions.test.SymmetricKeyBCProviderTest.java
@Test public void testSymmetricKeyDefaultAlgorithmAesKw256() { // Arrange/*from www.j a v a2s .c o m*/ byte[] KEK = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }; byte[] CEK = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, (byte) 0x88, (byte) 0x99, (byte) 0xAA, (byte) 0xBB, (byte) 0xCC, (byte) 0xDD, (byte) 0xEE, (byte) 0xFF }; byte[] EK = { 0x64, (byte) 0xE8, (byte) 0xC3, (byte) 0xF9, (byte) 0xCE, 0x0F, 0x5B, (byte) 0xA2, 0x63, (byte) 0xE9, 0x77, 0x79, 0x05, (byte) 0x81, (byte) 0x8A, 0x2A, (byte) 0x93, (byte) 0xC8, 0x19, 0x1E, 0x7D, 0x6E, (byte) 0x8A, (byte) 0xE7 }; SymmetricKey key = new SymmetricKey("KEK", KEK, _provider); byte[] encrypted = null; String algorithm = null; try { Pair<byte[], String> result = key.wrapKeyAsync(CEK, null).get(); encrypted = result.getLeft(); algorithm = result.getRight(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertEquals("A256KW", algorithm); assertArrayEquals(EK, encrypted); byte[] decrypted = null; try { decrypted = key.unwrapKeyAsync(EK, algorithm).get(); } catch (InterruptedException e) { fail("InterrupedException"); } catch (ExecutionException e) { fail("ExecutionException"); } catch (NoSuchAlgorithmException e) { fail("NoSuchAlgorithmException"); } // Assert assertArrayEquals(CEK, decrypted); try { key.close(); } catch (IOException e) { fail("Key could not be closed"); } }
From source file:it.polimi.diceH2020.SPACE4CloudWS.solvers.solversImpl.SPNSolver.SPNSolver.java
@Override protected Pair<Double, Boolean> run(Pair<List<File>, List<File>> pFiles, String remoteName, String remoteDirectory) throws Exception { List<File> files = pFiles.getLeft(); if (!pFiles.getRight().isEmpty() || files.size() != 3) { throw new IllegalArgumentException("wrong number of input files"); }/* w w w. ja v a 2 s . com*/ File netFile = files.get(0); File defFile = files.get(1); File statFile = files.get(2); Matcher matcher = prefixRegex.matcher(netFile.getName()); if (!matcher.matches()) { throw new RuntimeException(String.format("problem matching %s", netFile.getName())); } String prefix = matcher.group(1); String remotePath = remoteDirectory + File.separator + remoteName; boolean stillNotOk = true; for (int i = 0; stillNotOk && i < MAX_ITERATIONS; ++i) { logger.info(remoteName + "-> Starting Stochastic Petri Net simulation on the server"); cleanRemoteSubDirectory(remoteDirectory); connector.exec(String.format("mkdir -p %s", remoteDirectory), getClass()); logger.trace("Scenario is " + dataService.getScenario().getStringRepresentation()); connector.sendFile(netFile.getAbsolutePath(), remotePath + ".net", getClass()); logger.debug(remoteName + "-> GreatSPN .net file sent"); connector.sendFile(defFile.getAbsolutePath(), remotePath + ".def", getClass()); logger.debug(remoteName + "-> GreatSPN .def file sent"); if (dataService.getScenario().getTechnology() != Technology.STORM) { connector.sendFile(statFile.getAbsolutePath(), remotePath + ".stat", getClass()); logger.debug(remoteName + "-> GreatSPN .stat file sent"); } String command = String.format("%s %s -a %f -c %d", connSettings.getSolverPath(), remotePath, connSettings.getAccuracy(), ((SPNSettings) connSettings).getConfidence().getFlag()); logger.debug(remoteName + "-> Starting GreatSPN model..."); List<String> remoteMsg = connector.exec(command, getClass()); if (remoteMsg.contains("exit-status: 0")) { stillNotOk = false; logger.info(remoteName + "-> The remote optimization process completed correctly"); } else { logger.debug(remoteName + "-> Remote exit status: " + remoteMsg); } } if (stillNotOk) { logger.info(remoteName + "-> Error in remote optimization"); throw new Exception("Error in the SPN server"); } else { List<String> remoteOutput = connector.exec(String.format("ls %s", remoteDirectory), getClass()); String remoteResultFile = remoteDirectory + File.separator; try (BufferedReader reader = new BufferedReader(new StringReader(remoteOutput.get(0)))) { remoteResultFile += reader.lines().filter(line -> line.contains("simres")).findAny() .orElse(remoteName + ".simres"); } File solFile = fileUtility.provideTemporaryFile(prefix, ".simres"); connector.receiveFile(solFile.getAbsolutePath(), remoteResultFile, getClass()); Map<String, Double> results = new PNSimResFileParser(solFile).parse(); if (fileUtility.delete(solFile)) logger.debug(solFile + " deleted"); double result = results.get(label); /* This is a workaround for the crazy behavior of the PNML transformation * that converts milliseconds to seconds. * Here we turn hertz into kilohertz to obtain results consistent * with our input. */ if (usingInputModel && dataService.getScenario().getTechnology() != Technology.STORM) result /= 1000; logger.info(remoteName + "-> GreatSPN model run."); // TODO: this always returns false, should check if every error just throws return Pair.of(result, false); } }
From source file:net.malisis.blocks.vanishingoption.VanishingOptionsGui.java
@Subscribe public void onConfigChanged(ComponentEvent.ValueChange event) { Pair<EnumFacing, DataType> data = (Pair<EnumFacing, DataType>) event.getComponent().getData(); int time = event.getComponent() instanceof UITextField ? NumberUtils.toInt((String) event.getNewValue()) : 0;/*w w w .j a v a 2 s . co m*/ boolean checked = event.getComponent() instanceof UICheckBox ? (boolean) event.getNewValue() : false; vanishingOptions.set(data.getLeft(), data.getRight(), time, checked); VanishingDiamondFrameMessage.sendConfiguration(tileEntity, data.getLeft(), data.getRight(), time, checked); updateGui(); }
From source file:ml.shifu.shifu.core.ModelRunner.java
/** * Run model to compute score for input NS Data map * /*www . j a va 2 s.c o m*/ * @param rawDataNsMap * - the original input, but key is wrapped by NSColumn * @return CaseScoreResult - model score */ public CaseScoreResult computeNsData(final Map<NSColumn, String> rawDataNsMap) { if (MapUtils.isEmpty(rawDataNsMap)) { return null; } CaseScoreResult scoreResult = new CaseScoreResult(); if (this.scorer != null) { ScoreObject so = scorer.scoreNsData(rawDataNsMap); if (so == null) { return null; } scoreResult.setScores(so.getScores()); scoreResult.setMaxScore(so.getMaxScore()); scoreResult.setMinScore(so.getMinScore()); scoreResult.setAvgScore(so.getMeanScore()); scoreResult.setMedianScore(so.getMedianScore()); scoreResult.setHiddenLayerScores(so.getHiddenLayerScores()); } if (MapUtils.isNotEmpty(this.subScorers)) { if (this.isMultiThread && this.subScorers.size() > 1 && this.executorManager == null) { int threadPoolSize = Math.min(Runtime.getRuntime().availableProcessors(), this.subScorers.size()); this.executorManager = new ExecutorManager<Pair<String, ScoreObject>>(threadPoolSize); // add a shutdown hook as a safe guard if some one not call close Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { @Override public void run() { ModelRunner.this.executorManager.forceShutDown(); } })); log.info("MultiThread is enabled in ModelRunner, threadPoolSize = " + threadPoolSize); } List<Callable<Pair<String, ScoreObject>>> tasks = new ArrayList<Callable<Pair<String, ScoreObject>>>( this.subScorers.size()); Iterator<Map.Entry<String, Scorer>> iterator = this.subScorers.entrySet().iterator(); while (iterator.hasNext()) { final Map.Entry<String, Scorer> entry = iterator.next(); Callable<Pair<String, ScoreObject>> callable = new Callable<Pair<String, ScoreObject>>() { @Override public Pair<String, ScoreObject> call() { String modelName = entry.getKey(); Scorer subScorer = entry.getValue(); ScoreObject so = subScorer.scoreNsData(rawDataNsMap); if (so != null) { return Pair.of(modelName, so); } else { return null; } } }; tasks.add(callable); } if (this.isMultiThread && this.subScorers.size() > 1) { List<Pair<String, ScoreObject>> results = this.executorManager.submitTasksAndWaitResults(tasks); for (Pair<String, ScoreObject> result : results) { if (result != null) { scoreResult.addSubModelScore(result.getLeft(), result.getRight()); } } } else { for (Callable<Pair<String, ScoreObject>> task : tasks) { Pair<String, ScoreObject> result = null; try { result = task.call(); } catch (Exception e) { // do nothing } if (result != null) { scoreResult.addSubModelScore(result.getLeft(), result.getRight()); } } } } return scoreResult; }
From source file:com.formkiq.core.api.FolderFilesController.java
/** * Gets a File./*from w w w. j a va 2 s . co m*/ * @param request {@link HttpServletRequest} * @param response {@link HttpServletResponse} * @param folder {@link String} * @param uuid {@link String} * @param resetuuid {@link String} * @throws IOException IOException */ @Transactional @RequestMapping(value = API_FOLDER_FILE + "/{folder}/{uuid}", method = GET) public void get(final HttpServletRequest request, final HttpServletResponse response, @PathVariable(name = "folder", required = true) final String folder, @PathVariable(name = "uuid", required = true) final String uuid, @RequestParam(value = "resetuuid", required = false) final boolean resetuuid) throws IOException { ArchiveDTO archiveDTO = null; String contentType = "application/zip"; String accept = request.getHeader("Accept"); String uri = request.getRequestURI(); Pair<byte[], String> p = this.folderService.findFormData(folder, uuid); String sha1hash = p.getRight(); byte[] data = p.getLeft(); if (resetuuid) { archiveDTO = this.archiveService.extractJSONFromZipFile(data); this.archiveService.resetUUID(archiveDTO); data = this.archiveService.createZipFile(archiveDTO); sha1hash = ""; } if (hasText(accept) && accept.contains("+json")) { archiveDTO = archiveDTO != null ? archiveDTO : this.archiveService.extractJSONFromZipFile(data); data = this.jsonService.writeValueAsBytes(archiveDTO); contentType = "application/json"; } if (hasText(accept) && (accept.contains("+pdf") || uri.endsWith(".pdf"))) { contentType = "application/pdf"; archiveDTO = archiveDTO != null ? archiveDTO : this.archiveService.extractJSONFromZipFile(data); if (archiveDTO.getPDF().isEmpty()) { this.folderService.createWorkflowOutput(archiveDTO); } if (archiveDTO.getPDF().isEmpty()) { throw new PreconditionFailedException("No PDF Found"); } data = archiveDTO.getPDF().values().iterator().next(); } response.addHeader("sha1hash", sha1hash); response.setContentType(contentType); response.setContentLengthLong(data.length); IOUtils.write(data, response.getOutputStream()); }