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:com.yahoo.elide.parsers.state.RelationshipTerminalState.java
@Override public Supplier<Pair<Integer, JsonNode>> handleGet(StateContext state) { JsonApiDocument doc = new JsonApiDocument(); RequestScope requestScope = state.getRequestScope(); ObjectMapper mapper = requestScope.getMapper().getObjectMapper(); Optional<MultivaluedMap<String, String>> queryParams = requestScope.getQueryParams(); Map<String, Relationship> relationships = record.toResource().getRelationships(); Relationship relationship = null;//from ww w.j a v a 2 s . c om if (relationships != null) { relationship = relationships.get(relationshipName); } // Handle valid relationship if (relationship != null) { // Set data Data<Resource> data = relationship.getData(); doc.setData(data); // Run include processor DocumentProcessor includedProcessor = new IncludedProcessor(); includedProcessor.execute(doc, record, queryParams); return () -> Pair.of(HttpStatus.SC_OK, mapper.convertValue(doc, JsonNode.class)); } // Handle no data for relationship if (relationshipType.isToMany()) { doc.setData(new Data<>(new ArrayList<>())); } else if (relationshipType.isToOne()) { doc.setData(new Data<>((Resource) null)); } else { throw new IllegalStateException( "Failed to GET a relationship; relationship is neither toMany nor toOne"); } return () -> Pair.of(HttpStatus.SC_OK, mapper.convertValue(doc, JsonNode.class)); }
From source file:com.github.steveash.jg2p.align.FilterWalkerDecorator.java
@Override public void forward(Word x, Word y, final Visitor visitor) { delegate.forward(x, y, new Visitor() { @Override//from ww w . j a v a2 s. co m 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:com.hortonworks.registries.schemaregistry.HAServerNotificationManager.java
private void notify(String urlPath, Object postBody) { // If Schema Registry was not started in HA mode then serverURL would be null, in case don't bother making POST calls if (serverUrl != null) { PriorityQueue<Pair<Integer, String>> queue = new PriorityQueue<>(); synchronized (UPDATE_ITERATE_LOCK) { hostIps.stream().forEach(hostIp -> { queue.add(Pair.of(1, hostIp)); });//from w w w. j a v a 2 s .com } while (!queue.isEmpty()) { Pair<Integer, String> priorityWithHostIp = queue.remove(); WebTarget target = ClientBuilder.newClient() .target(String.format("%s%s", priorityWithHostIp.getRight(), urlPath)); Response response = null; try { response = target.request().post(Entity.json(postBody)); } catch (Exception e) { LOG.warn("Failed to notify the peer server '{}' about the current host debut.", priorityWithHostIp.getRight()); } if ((response == null || response.getStatus() != Response.Status.OK.getStatusCode()) && priorityWithHostIp.getLeft() < MAX_RETRY) { queue.add(Pair.of(priorityWithHostIp.getLeft() + 1, priorityWithHostIp.getRight())); } else if (priorityWithHostIp.getLeft() < MAX_RETRY) { LOG.info("Notified the peer server '{}' about the current host debut.", priorityWithHostIp.getRight()); } else if (priorityWithHostIp.getLeft() >= MAX_RETRY) { LOG.warn( "Failed to notify the peer server '{}' about the current host debut, giving up after {} attempts.", priorityWithHostIp.getRight(), MAX_RETRY); } try { Thread.sleep(priorityWithHostIp.getLeft() * 100); } catch (InterruptedException e) { LOG.warn("Failed to notify the peer server '{}'", priorityWithHostIp.getRight(), e); } } } }
From source file:com.github.steveash.jg2p.align.Alignment.java
void append(String xGram, String yGram) { graphones.add(Pair.of(xGram, yGram)); }
From source file:edu.wpi.checksims.algorithm.AlgorithmRunnerTest.java
@Test public void TestRunAlgorithmNullAlgorithm() { expectedEx.expect(NullPointerException.class); AlgorithmRunner.runAlgorithm(singleton(Pair.of(a, b)), null); }
From source file:com.hortonworks.streamline.streams.notification.service.NotificationQueueHandler.java
public Future<?> enqueue(Notifier notifier, Notification notification) { NotificationQueueTask task = new NotificationQueueTask(notifier, notification); Future<?> future = executorService.submit(task); taskMap.put(notification.getId(), Pair.of(task, future)); return future; }
From source file:com.streamsets.pipeline.lib.jdbc.multithread.cache.JdbcTableReadContextLoader.java
@Override public TableReadContext load(TableRuntimeContext tableRuntimeContext) throws Exception { Pair<String, List<Pair<Integer, String>>> queryAndParamValToSet; final boolean nonIncremental = tableRuntimeContext.isUsingNonIncrementalLoad(); if (nonIncremental) { final String baseTableQuery = OffsetQueryUtil.buildBaseTableQuery(tableRuntimeContext, quoteChar); queryAndParamValToSet = Pair.of(baseTableQuery, Collections.emptyList()); } else {//from ww w. j a va 2s . c o m queryAndParamValToSet = OffsetQueryUtil.buildAndReturnQueryAndParamValToSet(tableRuntimeContext, offsets.get(tableRuntimeContext.getOffsetKey()), quoteChar, tableJdbcELEvalContext); } if (isReconnect) { LOGGER.debug("close the connection"); connectionManager.closeConnection(); } TableReadContext tableReadContext = new TableReadContext(connectionManager.getConnection(), queryAndParamValToSet.getLeft(), queryAndParamValToSet.getRight(), fetchSize, nonIncremental); //Clear the initial offset after the query is build so we will not use the initial offset from the next //time the table is used. tableRuntimeContext.getSourceTableContext().clearStartOffset(); return tableReadContext; }
From source file:com.act.lcms.MassCalculator2.java
protected static Pair<Double, Integer> calculateMassAndCharge(String inchi) throws MolFormatException { Molecule mol = MolImporter.importMol(inchi); LOGGER.info("Exact mass vs. just mass for %s: %.6f %.6f", inchi, mol.getExactMass(), mol.getMass()); return Pair.of(mol.getExactMass(), mol.getTotalCharge()); }
From source file:com.github.steveash.jg2p.util.NestedLoopPairIterableTest.java
@Test public void shouldWorkIfOuterIsOnlyOne() throws Exception { ImmutableList<Integer> a = ImmutableList.of(1); ImmutableList<String> b = ImmutableList.of("a", "b"); NestedLoopPairIterable<Integer, String> ible = NestedLoopPairIterable.of(a, b); Iterator<Pair<Integer, String>> iter = ible.iterator(); assertEquals(2, size(ible));//from ww w .j a v a2 s . c o m assertEquals(Pair.of(1, "a"), iter.next()); assertEquals(Pair.of(1, "b"), iter.next()); assertFalse(iter.hasNext()); }
From source file:enumj.EnumerableTest.java
@Test public void testEnumerator() { System.out.println("enumerator"); EnumerableGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().repeatable(), p.getRight().repeatable())).forEach(p -> { assertTrue(p.getLeft().enumerator().elementsEqual(p.getRight().iterator())); });// w w w .j a va 2 s . c o m }