List of usage examples for org.apache.commons.lang3.tuple Pair getLeft
public abstract L getLeft();
Gets the left element from this pair.
When treated as a key-value pair, this is the key.
From source file:com.twitter.distributedlog.client.proxy.TestProxyClientManager.java
@Test(timeout = 60000) public void testCreateClientShouldHandshake() throws Exception { SocketAddress address = createSocketAddress(3000); MockProxyClientBuilder builder = new MockProxyClientBuilder(); ServerInfo serverInfo = new ServerInfo(); serverInfo.putToOwnerships(runtime.getMethodName() + "_stream", runtime.getMethodName() + "_owner"); Pair<MockProxyClient, MockServerInfoService> mockProxyClient = createMockProxyClient(address, serverInfo); builder.provideProxyClient(address, mockProxyClient.getLeft()); final AtomicReference<ServerInfo> resultHolder = new AtomicReference<ServerInfo>(null); final CountDownLatch doneLatch = new CountDownLatch(1); ProxyListener listener = new ProxyListener() { @Override/*from w w w.j ava 2s . c o m*/ public void onHandshakeSuccess(SocketAddress address, ProxyClient client, ServerInfo serverInfo) { resultHolder.set(serverInfo); doneLatch.countDown(); } @Override public void onHandshakeFailure(SocketAddress address, ProxyClient client, Throwable cause) { } }; ProxyClientManager clientManager = createProxyClientManager(builder, 0L); clientManager.registerProxyListener(listener); assertEquals("There should be no clients in the manager", 0, clientManager.getNumProxies()); clientManager.createClient(address); assertEquals("Create client should build the proxy client", 1, clientManager.getNumProxies()); // When a client is created, it would handshake with that proxy doneLatch.await(); assertEquals("Handshake should return server info", serverInfo, resultHolder.get()); }
From source file:com.microsoft.azure.keyvault.extensions.test.SymmetricKeyBCProviderTest.java
@Test public void testSymmetricKeyDefaultAlgorithmAesKw192() { // Arrange/*w ww.ja va 2 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:com.cisco.oss.foundation.message.HornetQMessageConsumer.java
private String createQueueIfNeeded() { Configuration subset = configuration.subset(consumerName); queueName = subset.getString("queue.name"); String filter = subset.getString("queue.filter", ""); boolean isDurable = subset.getBoolean("queue.isDurable", true); boolean isSubscription = subset.getBoolean("queue.isSubscription", false); String subscribedTo = isSubscription ? subset.getString("queue.subscribedTo", "") : queueName; if (isSubscription) { if (StringUtils.isBlank(subscribedTo)) { throw new QueueException( "Check Configuration - missing required subscribedTo name for consumerThreadLocal[" + consumerName + "] as it is marked as isSubscription=true"); }//from w w w. j a v a 2 s . co m // subscribedTo = "foundation." + subscribedTo; } if (StringUtils.isBlank(queueName)) { String rpmSoftwareName = System.getenv("_RPM_SOFTWARE_NAME"); String artifactId = System.getenv("_ARTIFACT_ID"); String componentName = ""; if (StringUtils.isNoneBlank(rpmSoftwareName)) { componentName = rpmSoftwareName; } else { if (StringUtils.isNoneBlank(artifactId)) { componentName = artifactId; } } if (StringUtils.isNoneBlank(componentName)) { queueName = componentName + "_" + subscribedTo; } if (StringUtils.isBlank(queueName)) { throw new QueueException( "Check Configuration - missing required queue name for consumerThreadLocal: " + consumerName); } } String realQueueName = /*"foundation." + */queueName; boolean queueExists = false; for (Pair<ClientSession, SessionFailureListener> clientSessionSessionFailureListenerPair : HornetQMessagingFactory .getSession(FoundationQueueConsumerFailureListener.class)) { ClientSession clientSession = clientSessionSessionFailureListenerPair.getLeft(); try { queueExists = clientSession.queueQuery(new SimpleString(realQueueName)).isExists(); if (!queueExists) { clientSession.createQueue(isSubscription ? subscribedTo : realQueueName, realQueueName, filter, isDurable); } } catch (HornetQException e) { try { clientSession.createQueue(isSubscription ? subscribedTo : realQueueName, realQueueName, filter, isDurable); } catch (HornetQException e1) { throw new QueueException("Can't create queue: " + realQueueName + ". Error: " + e1, e1); } } } return realQueueName; }
From source file:com.microsoft.azure.keyvault.extensions.test.SymmetricKeyBCProviderTest.java
@Test public void testSymmetricKeyDefaultAlgorithmAesKw256() { // Arrange/* ww w. j a v a 2s. 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:ee.ria.xroad.common.hashchain.HashChainVerifier.java
/** * Downloads hash step, calculates all the values and concatenates the * results to DigestList data structure. * @return DER-encoding of the DigestList data structure. *///from w ww . j a va 2 s .c o m private byte[] resolveHashStep(String uri, HashChainType currentChain) throws Exception { LOG.trace("resolveHashStep({})", uri); Pair<HashStepType, HashChainType> hashStep = fetchHashStep(uri, currentChain); List<AbstractValueType> values = hashStep.getLeft().getHashValueOrStepRefOrDataRef(); DigestValue[] digests = new DigestValue[values.size()]; // Calculate digests of all the individual values in the hash step for (int i = 0; i < digests.length; ++i) { digests[i] = resolveValue(values.get(i), hashStep.getRight()); } return DigestList.concatDigests(digests); }
From source file:com.vmware.photon.controller.apife.backends.TenantSqlBackend.java
@Override @Transactional//from w ww .j a v a 2s .c o m public TaskEntity prepareSetSecurityGroups(String id, List<String> securityGroups) throws ExternalException { logger.info("Updating the security groups of tenant {} to {}", id, securityGroups.toString()); TenantEntity tenantEntity = findById(id); List<SecurityGroup> currSecurityGroups = SecurityGroupUtils .toApiRepresentation(tenantEntity.getSecurityGroups()); Pair<List<SecurityGroup>, List<String>> result = SecurityGroupUtils .mergeSelfSecurityGroups(currSecurityGroups, securityGroups); tenantEntity.setSecurityGroups(SecurityGroupUtils.fromApiRepresentation(result.getLeft())); TaskEntity taskEntity = taskBackend.createQueuedTask(tenantEntity, Operation.SET_TENANT_SECURITY_GROUPS); StepEntity stepEntity = taskBackend.getStepBackend().createQueuedStep(taskEntity, tenantEntity, Operation.SET_TENANT_SECURITY_GROUPS); if (!result.getRight().isEmpty()) { stepEntity.addWarning(new SecurityGroupsAlreadyInheritedException(result.getRight())); } taskBackend.getStepBackend().createQueuedStep(taskEntity, tenantEntity, Operation.PUSH_TENANT_SECURITY_GROUPS); logger.info("Created Task: {}", taskEntity); return taskEntity; }
From source file:net.malisis.blocks.tileentity.SwapperTileEntity.java
public void swap() { AxisAlignedBB aabb = getAABB();/*from w ww. j a v a 2 s. c o m*/ for (BlockPos p : BlockPosUtils.getAllInBox(aabb)) { int x = (int) (p.getX() - aabb.minX); int y = (int) (p.getY() - aabb.minY); int z = (int) (p.getZ() - aabb.minZ); Pair<IBlockState, NBTTagCompound> worldState = getWorldState(p); Pair<IBlockState, NBTTagCompound> storedState = getStoredState(x, y, z); storeState(x, y, z, worldState); applyState(p, storedState); getWorld().markAndNotifyBlock(p, getWorld().getChunkFromBlockCoords(p), worldState.getLeft(), storedState.getLeft(), 2); } }
From source file:com.act.biointerpretation.desalting.ReactionDesalter.java
private void migrateReactionSubsProdsWCoeffs(Reaction newReaction, Reaction oldReaction) { {/* w w w . j av a 2s .c o m*/ Pair<List<Long>, Map<Long, Integer>> newSubstratesAndCoefficients = buildIdAndCoefficientMapping( oldReaction, SUBSTRATE); newReaction.setSubstrates(newSubstratesAndCoefficients.getLeft() .toArray(new Long[newSubstratesAndCoefficients.getLeft().size()])); newReaction.setAllSubstrateCoefficients(newSubstratesAndCoefficients.getRight()); List<Long> newSubstrateCofactors = buildIdMapping(oldReaction.getSubstrateCofactors()); newReaction .setSubstrateCofactors(newSubstrateCofactors.toArray(new Long[newSubstrateCofactors.size()])); } { Pair<List<Long>, Map<Long, Integer>> newProductsAndCoefficients = buildIdAndCoefficientMapping( oldReaction, PRODUCT); newReaction.setProducts(newProductsAndCoefficients.getLeft() .toArray(new Long[newProductsAndCoefficients.getLeft().size()])); newReaction.setAllProductCoefficients(newProductsAndCoefficients.getRight()); List<Long> newproductCofactors = buildIdMapping(oldReaction.getProductCofactors()); newReaction.setProductCofactors(newproductCofactors.toArray(new Long[newproductCofactors.size()])); } }
From source file:com.act.lcms.v2.fullindex.Searcher.java
private List<MZWindow> mzWindowsInRange(Pair<Double, Double> mzRange) { List<MZWindow> mzWindowsInRange = new ArrayList<>( // Same here--access by index. mzWindows.stream()//from w w w .j a va 2 s. com .filter(x -> rangesOverlap(mzRange.getLeft(), mzRange.getRight(), x.getMin(), x.getMax())) .collect(Collectors.toList())); if (mzWindowsInRange.size() == 0) { LOGGER.warn("Found zero m/z windows in range %.6f - %.6f", mzRange.getLeft(), mzRange.getRight()); } return mzWindowsInRange; }
From source file:com.github.steveash.jg2p.train.EncoderEval.java
private void printExamples() { for (Integer phoneEdit : examples.keySet()) { log.info(" ---- Examples with edit distance " + phoneEdit + " ----"); Iterable<Pair<InputRecord, List<PhoneticEncoder.Encoding>>> toPrint = limit(examples.get(phoneEdit), MAX_EXAMPLE_TO_PRINT);//from w w w . ja v a 2 s . c om for (Pair<InputRecord, List<PhoneticEncoder.Encoding>> example : toPrint) { String got = "<null>"; if (example.getRight().size() > 0) { got = example.getRight().get(0).toString(); } log.info(" Got: " + got + " expected: " + example.getLeft().getRight().getAsSpaceString()); } } }