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.act.lcms.db.model.FeedingLCMSWell.java
public List<FeedingLCMSWell> insertFromPlateComposition(DB db, PlateCompositionParser parser, Plate p) throws SQLException, IOException { Map<String, String> plateProperties = parser.getPlateProperties(); String msid = null, composition = null; if (!plateProperties.containsKey("msid") && plateProperties.containsKey("composition")) { throw new RuntimeException("ERROR: assumed plate properties 'msid' and 'composition' do not exist"); }//w w w. jav a2 s . c om msid = trimAndComplain(plateProperties.get("msid")); composition = trimAndComplain(plateProperties.get("composition")); // If a few well dones't have a concentration, it's not work keeping. Map<Pair<String, String>, String> concentrations = parser.getCompositionTables().get("concentration"); List<Pair<String, String>> sortedCoordinates = new ArrayList<>(concentrations.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 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<FeedingLCMSWell> results = new ArrayList<>(); for (Pair<String, String> coords : sortedCoordinates) { String concentraitonStr = parser.getCompositionTables().get("concentration").get(coords); if (concentraitonStr == null || concentraitonStr.isEmpty()) { continue; } String extract = parser.getCompositionTables().get("extract").get(coords); String chemical = parser.getCompositionTables().get("chemical").get(coords); Double concentration = Double.parseDouble(concentraitonStr); String note = null; if (parser.getCompositionTables().get("note") != null) { note = parser.getCompositionTables().get("note").get(coords); } Pair<Integer, Integer> index = parser.getCoordinatesToIndices().get(coords); FeedingLCMSWell s = INSTANCE.insert(db, new FeedingLCMSWell(null, p.getId(), index.getLeft(), index.getRight(), msid, composition, extract, chemical, concentration, note)); results.add(s); } return results; }
From source file:enterprises.orbital.evekit.model.corporation.sync.ESICorporationIndustryJobSync.java
@Override protected ESIAccountServerResult<List<GetCorporationsCorporationIdIndustryJobs200Ok>> getServerData( ESIAccountClientProvider cp) throws ApiException, IOException { IndustryApi apiInstance = cp.getIndustryApi(); Pair<Long, List<GetCorporationsCorporationIdIndustryJobs200Ok>> result = pagedResultRetriever((page) -> { ESIThrottle.throttle(endpoint().name(), account); return apiInstance.getCorporationsCorporationIdIndustryJobsWithHttpInfo( (int) account.getEveCorporationID(), null, null, true, page, accessToken()); });//w w w . j a va 2s . c o m return new ESIAccountServerResult<>( result.getLeft() > 0 ? result.getLeft() : OrbitalProperties.getCurrentTime() + maxDelay(), result.getRight()); }
From source file:com.act.lcms.MS2.java
private MS2Collected normalizeAndThreshold(MS2Collected ms2) { Pair<Double, Double> largestAndNth = getMaxAndNth(ms2.ms2, REPORT_TOP_N); Double largest = largestAndNth.getLeft(); Double nth = largestAndNth.getRight(); List<YZ> ms2AboveThreshold = new ArrayList<>(); // print out the spectra to outDATA for (YZ yz : ms2.ms2) { // threshold to remove everything that is not in the top peaks if (yz.intensity < nth) continue; ms2AboveThreshold.add(new YZ(yz.mz, 100.0 * yz.intensity / largest)); }/* www. j a v a 2s . c om*/ return new MS2Collected(ms2.triggerTime, ms2.voltage, ms2AboveThreshold); }
From source file:com.silverpeas.notation.model.RatingDAOTest.java
@Test public void moveRating() throws Exception { IDataSet actualDataSet = getActualDataSet(); ITable table = actualDataSet.getTable("sb_notation_notation"); int[] aimedIds = new int[] { 1, 2, 3, 7 }; Map<Integer, Pair<String, Integer>> raterRatings = new HashMap<Integer, Pair<String, Integer>>(); for (int id : aimedIds) { int index = getTableIndexForId(table, id); assertThat((Integer) table.getValue(index, "id"), is(id)); assertThat((String) table.getValue(index, "instanceId"), is(INSTANCE_ID)); assertThat((String) table.getValue(index, "externalId"), is(CONTRIBUTION_ID)); assertThat((String) table.getValue(index, "externalType"), is(CONTRIBUTION_TYPE)); raterRatings.put(id,/*from w w w .j av a2 s . co m*/ Pair.of((String) table.getValue(index, "author"), (Integer) table.getValue(index, "note"))); } long nbMoved = RatingDAO.moveRatings(getConnection(), new ContributionRatingPK(CONTRIBUTION_ID, INSTANCE_ID, CONTRIBUTION_TYPE), "otherInstanceId"); actualDataSet = getActualDataSet(); table = actualDataSet.getTable("sb_notation_notation"); assertThat(table.getRowCount(), is(RATING_ROW_COUNT)); assertThat(nbMoved, is((long) aimedIds.length)); for (int id : aimedIds) { int index = getTableIndexForId(table, id); assertThat((Integer) table.getValue(index, "id"), is(id)); assertThat((String) table.getValue(index, "instanceId"), is("otherInstanceId")); assertThat((String) table.getValue(index, "externalId"), is(CONTRIBUTION_ID)); assertThat((String) table.getValue(index, "externalType"), is(CONTRIBUTION_TYPE)); Pair<String, Integer> raterRating = raterRatings.get(id); assertThat((String) table.getValue(index, "author"), is(raterRating.getLeft())); assertThat((Integer) table.getValue(index, "note"), is(raterRating.getRight())); } }
From source file:candr.yoclip.DefaultParserHelpFactoryTest.java
@Test public void testGetOptionDescription() { final ParserHelpFactory<TestCase> testCase = new DefaultParserHelpFactory<TestCase>(); final ParserOptions<TestCase> parserOptions = new ParserOptionsFactory<TestCase>(TestCase.class).create(); final String prefix = parserOptions.getPrefix(); final String separator = parserOptions.getSeparator(); ParserOption<TestCase> optionParameter = parserOptions.get("s"); Pair<String, String> description = testCase.getOptionDescription(prefix, separator, optionParameter); assertThat("option usage", description.getLeft(), is("/s|/string=STRING")); assertThat("option description", description.getRight(), is("Sets the 'option' field option.")); optionParameter = parserOptions.get("D"); description = testCase.getOptionDescription(prefix, separator, optionParameter); assertThat("properties usage", description.getLeft(), is("/DKEY=VALUE")); assertThat("option description", description.getRight(), is("Sets a property and value into the 'properties' Map field.")); optionParameter = parserOptions.get(ParserOptions.ARGUMENTS_KEY); description = testCase.getOptionDescription(prefix, separator, optionParameter); assertThat("arguments usage", description.getLeft(), is("ARG")); assertThat("option description", description.getRight(), is("Sets an argument into the 'arguments' List field.")); }
From source file:com.wolvereness.renumerated.Renumerated.java
private void process() throws Throwable { validateInput();// w ww.j a v a 2s. c om final MultiProcessor executor = MultiProcessor.newMultiProcessor(cores - 1, new ThreadFactoryBuilder().setDaemon(true) .setNameFormat(Renumerated.class.getName() + "-processor-%d") .setUncaughtExceptionHandler(this).build()); final Future<?> fileCopy = executor.submit(new Callable<Object>() { @Override public Object call() throws Exception { if (original != null) { if (original.exists()) { original.delete(); } Files.copy(input, original); } return null; } }); final List<Pair<ZipEntry, Future<byte[]>>> fileEntries = newArrayList(); final List<Pair<MutableObject<ZipEntry>, Future<byte[]>>> classEntries = newArrayList(); { final ZipFile input = new ZipFile(this.input); final Enumeration<? extends ZipEntry> inputEntries = input.entries(); while (inputEntries.hasMoreElements()) { final ZipEntry entry = inputEntries.nextElement(); final Future<byte[]> future = executor.submit(new Callable<byte[]>() { @Override public byte[] call() throws Exception { return ByteStreams.toByteArray(input.getInputStream(entry)); } }); if (entry.getName().endsWith(".class")) { classEntries.add(new MutablePair<MutableObject<ZipEntry>, Future<byte[]>>( new MutableObject<ZipEntry>(entry), future)); } else { fileEntries.add(new ImmutablePair<ZipEntry, Future<byte[]>>(entry, future)); } } for (final Pair<MutableObject<ZipEntry>, Future<byte[]>> pair : classEntries) { final byte[] data = pair.getRight().get(); pair.setValue(executor.submit(new Callable<byte[]>() { String className; List<String> fields; @Override public byte[] call() throws Exception { try { return method(); } catch (final Exception ex) { throw new Exception(pair.getLeft().getValue().getName(), ex); } } private byte[] method() throws Exception { final ClassReader clazz = new ClassReader(data); clazz.accept(new ClassVisitor(ASM4) { @Override public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) { if (superName.equals("java/lang/Enum")) { className = name; } } @Override public FieldVisitor visitField(final int access, final String name, final String desc, final String signature, final Object value) { if (className != null && (access & 0x4000) != 0) { List<String> fieldNames = fields; if (fieldNames == null) { fieldNames = fields = newArrayList(); } fieldNames.add(name); } return null; } }, ClassReader.SKIP_CODE); if (className == null) return data; final String classDescriptor = Type.getObjectType(className).getDescriptor(); final ClassWriter writer = new ClassWriter(0); clazz.accept(new ClassVisitor(ASM4, writer) { @Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { final MethodVisitor methodVisitor = super.visitMethod(access, name, desc, signature, exceptions); if (!name.equals("<clinit>")) { return methodVisitor; } return new MethodVisitor(ASM4, methodVisitor) { final Iterator<String> it = fields.iterator(); boolean active; String lastName; @Override public void visitTypeInsn(final int opcode, final String type) { if (!active && it.hasNext()) { // Initiate state machine if (opcode != NEW) throw new AssertionError("Unprepared for " + opcode + " on " + type + " in " + className); active = true; } super.visitTypeInsn(opcode, type); } @Override public void visitLdcInsn(final Object cst) { if (active && lastName == null) { if (!(cst instanceof String)) throw new AssertionError( "Unprepared for " + cst + " in " + className); // Switch the first constant in the Enum constructor super.visitLdcInsn(lastName = it.next()); } else { super.visitLdcInsn(cst); } } @Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { if (opcode == PUTSTATIC && active && lastName != null && owner.equals(className) && desc.equals(classDescriptor) && name.equals(lastName)) { // Finish the current state machine active = false; lastName = null; } super.visitFieldInsn(opcode, owner, name, desc); } }; } }, ClassReader.EXPAND_FRAMES); final MutableObject<ZipEntry> key = pair.getLeft(); key.setValue(new ZipEntry(key.getValue().getName())); return writer.toByteArray(); } })); } for (final Pair<ZipEntry, Future<byte[]>> pair : fileEntries) { pair.getRight().get(); } input.close(); } fileCopy.get(); FileOutputStream fileOut = null; JarOutputStream jar = null; try { jar = new JarOutputStream(fileOut = new FileOutputStream(output)); for (final Pair<ZipEntry, Future<byte[]>> fileEntry : fileEntries) { jar.putNextEntry(fileEntry.getLeft()); jar.write(fileEntry.getRight().get()); } for (final Pair<MutableObject<ZipEntry>, Future<byte[]>> classEntry : classEntries) { final byte[] data = classEntry.getRight().get(); final ZipEntry entry = classEntry.getLeft().getValue(); entry.setSize(data.length); jar.putNextEntry(entry); jar.write(data); } } finally { if (jar != null) { try { jar.close(); } catch (final IOException ex) { } } if (fileOut != null) { try { fileOut.close(); } catch (final IOException ex) { } } } final Pair<Thread, Throwable> uncaught = this.uncaught; if (uncaught != null) throw new MojoExecutionException(String.format("Uncaught exception in %s", uncaught.getLeft()), uncaught.getRight()); }
From source file:com.vmware.identity.openidconnect.server.LoginTest.java
@Test public void testLoginStringWithSessionCookieMatching() throws Exception { // if request has both a loginString and session cookie, then if the session cookie matches, use it and ignore the loginString String loginString = passwordLoginString(); Cookie sessionCookie = new Cookie(SESSION_COOKIE_NAME, SESSION_ID); Pair<ModelAndView, MockHttpServletResponse> result = doRequest(loginString, sessionCookie); ModelAndView modelView = result.getLeft(); MockHttpServletResponse response = result.getRight(); Assert.assertNull("modelView", modelView); boolean ajaxRequest = false; // it is actually an ajax request but then TestContext would expect a session cookie to be returned validateAuthnSuccessResponse(response, Flow.AUTHZ_CODE, Scope.OPENID, false, ajaxRequest, STATE, NONCE); }
From source file:net.minecraftforge.common.model.animation.AnimationStateMachine.java
public Pair<IModelState, Iterable<Event>> apply(float time) { if (lastPollTime == Float.NEGATIVE_INFINITY) { lastPollTime = time;/*from w w w . j av a 2 s. co m*/ } Pair<IModelState, Iterable<Event>> pair = clipCache .getUnchecked(Triple.of(currentState, lastPollTime, time)); lastPollTime = time; boolean shouldFilter = false; if (shouldHandleSpecialEvents) { for (Event event : ImmutableList.copyOf(pair.getRight()).reverse()) { if (event.event().startsWith("!")) { shouldFilter = true; if (event.event().startsWith("!transition:")) { String newState = event.event().substring("!transition:".length()); transition(newState); } else { System.out.println("Unknown special event \"" + event.event() + "\", ignoring"); } } } } if (!shouldFilter) { return pair; } return Pair.of(pair.getLeft(), Iterables.filter(pair.getRight(), new Predicate<Event>() { public boolean apply(Event event) { return !event.event().startsWith("!"); } })); }
From source file:at.gridtec.lambda4j.consumer.tri.obj.BiObjByteConsumer.java
/** * Applies this consumer to the given tuple. * * @param tuple The tuple to be applied to the consumer * @param value The primitive value to be applied to the consumer * @throws NullPointerException If given argument is {@code null} * @see org.apache.commons.lang3.tuple.Pair */// w w w .j a v a 2s .co m default void accept(@Nonnull Pair<T, U> tuple, byte value) { Objects.requireNonNull(tuple); accept(tuple.getLeft(), tuple.getRight(), value); }