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.netflix.imfutility.itunes.audio.ChannelsMapperTest.java
@Test public void testSurroundWithNoStereo() throws Exception { TemplateParameterContextProvider contextProvider = AudioUtils.createContext( new FFmpegAudioChannels[][] { { FL, FR, FC, LFE, SL, SR }, { FC } }, new String[] { "en", "en" }); ChannelsMapper mapper = new ChannelsMapper(contextProvider); mapper.mapChannels(createLayoutOptions(new LayoutType[] { SURROUND }, new String[] { "en" })); List<Pair<SequenceUUID, Integer>> channels = mapper.getChannels(Pair.of(SURROUND, "en")); assertChannelEquals(channels.get(0), 0, 1); assertChannelEquals(channels.get(1), 0, 2); assertChannelEquals(channels.get(2), 0, 3); assertChannelEquals(channels.get(3), 0, 4); assertChannelEquals(channels.get(4), 0, 5); assertChannelEquals(channels.get(5), 0, 6); assertChannelEquals(channels.get(6), 0, 1); assertChannelEquals(channels.get(7), 0, 2); assertEquals(8, channels.size());// ww w. jav a2 s .c om }
From source file:edu.umd.umiacs.clip.tools.classifier.LibSVMUtils.java
public static Map<Integer, Pair<Double, Double>> learnZscoringModel(List<String> training) { return training.stream().map(LibSVMUtils::split).map(Triple::getMiddle).flatMap(List::stream) .collect(groupingBy(Pair::getKey, ConcurrentHashMap::new, reducing(new ArrayList<Float>(), pair -> asList(pair.getRight()), (p1, p2) -> Stream.of(p1, p2).flatMap(List::stream).collect(toList())))) .entrySet().stream()//from ww w .ja va2s . c om .map(entry -> Pair.of(entry.getKey(), entry.getValue().stream().mapToDouble(f -> f).toArray())) .collect(toMap(Entry::getKey, entry -> Pair.of(new Mean().evaluate(entry.getValue()), new StandardDeviation().evaluate(entry.getValue())))); }
From source file:enumj.EnumerableTest.java
@Test public void testOfLazyEnumeration() { System.out.println("ofLazyEnumeration"); EnumerableGenerator.generatorPairs().limit(100).map( p -> Pair.of(p.getLeft().ofLazyEnumerationEnumerable(), p.getRight().ofLazyEnumerationEnumerable())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); }
From source file:com.teambrmodding.neotech.common.tiles.machines.processors.TileAlloyer.java
/** * Called when the tile has completed the cook process *//*from w w w .j a v a2s .c o m*/ @Override protected void completeCook() { for (int x = 0; x < getModifierForCategory(IUpgradeItem.ENUM_UPGRADE_CATEGORY.MEMORY); x++) { if (canProcess()) { AlloyerRecipe recipe = ((AlloyerRecipeHandler) RecipeManager .getHandler(RecipeManager.RecipeType.ALLOYER)) .getRecipe(Pair.of(tanks[INPUT_TANK_1].getFluid(), tanks[INPUT_TANK_2].getFluid())); if (recipe != null) { // Drain the inputs FluidStack drainInputOne; FluidStack drainOutputTwo; // Find Recipe Fluid Stack One if (tanks[INPUT_TANK_1].getFluid().getFluid() == AbstractRecipe .getFluidStackFromString(recipe.fluidStackOne).getFluid()) drainInputOne = tanks[INPUT_TANK_1] .drain(AbstractRecipe.getFluidStackFromString(recipe.fluidStackOne).amount, false); else drainInputOne = tanks[INPUT_TANK_1] .drain(AbstractRecipe.getFluidStackFromString(recipe.fluidStackTwo).amount, false); // Find Recipe Fluid Stack Two if (tanks[INPUT_TANK_2].getFluid().getFluid() == AbstractRecipe .getFluidStackFromString(recipe.fluidStackTwo).getFluid()) drainOutputTwo = tanks[INPUT_TANK_2] .drain(AbstractRecipe.getFluidStackFromString(recipe.fluidStackTwo).amount, false); else drainOutputTwo = tanks[INPUT_TANK_2] .drain(AbstractRecipe.getFluidStackFromString(recipe.fluidStackOne).amount, false); if (drainInputOne != null && drainOutputTwo != null && drainInputOne.amount > 0 && drainOutputTwo.amount > 0) { tanks[INPUT_TANK_1].drain(drainInputOne, true); tanks[INPUT_TANK_2].drain(drainOutputTwo, true); tanks[OUTPUT_TANK].fill(AbstractRecipe.getFluidStackFromString(recipe.fluidStackOutput), true); } } } else break; } markForUpdate(6); }
From source file:com.pgcraft.spectatorplus.guis.SpectatorsToolsGUI.java
@Override protected void onUpdate() { Spectator spectator = SpectatorPlus.get().getPlayerData(getPlayer()); /* ** ----- Size ----- ** */ // We first need to know what is the size of the inventory // If a death location is registered for this player, and if every tool is // enabled, a line will have to be added. // That's why this is defined here, not below. // If the "tp to death" tool is disabled, the death location is not set. So it's useless to // check this here. Location deathPoint = spectator.getDeathLocation(); int height = 0, offset = 0; if (Toggles.TOOLS_TOOLS_SPEED.get()) { height++;/*from ww w . j a v a 2 s .c om*/ offset = 9; } if (Toggles.TOOLS_TOOLS_DIVINGSUIT.get() || Toggles.TOOLS_TOOLS_NIGHTVISION.get() || Toggles.TOOLS_TOOLS_NOCLIP.get() || (Toggles.TOOLS_TOOLS_TPTODEATH_ENABLED.get() && deathPoint != null)) height++; if (Toggles.TOOLS_TOOLS_DIVINGSUIT.get() && Toggles.TOOLS_TOOLS_NIGHTVISION.get() && Toggles.TOOLS_TOOLS_NOCLIP.get() && Toggles.TOOLS_TOOLS_TPTODEATH_ENABLED.get() && deathPoint != null) height++; setSize(height * 9); setTitle(ChatColor.BLACK + "Spectators' tools"); /* ** ----- Active tools & effects ----- ** */ // Retrieves the current speed level, and the other enabled effects // 0 = no speed; 1 = speed I, etc. Integer speedLevel = 0; Boolean nightVisionActive = false; for (PotionEffect effect : getPlayer().getActivePotionEffects()) { if (effect.getType().equals(PotionEffectType.SPEED)) { speedLevel = effect.getAmplifier() + 1; // +1 because Speed I = amplifier 0. } else if (effect.getType().equals(PotionEffectType.NIGHT_VISION)) { nightVisionActive = true; } } Boolean divingSuitEquipped = false; if (getPlayer().getInventory().getBoots() != null && getPlayer().getInventory().getBoots().getType() == Material.DIAMOND_BOOTS) { divingSuitEquipped = true; } List<String> activeLore = Collections.singletonList("" + ChatColor.GRAY + ChatColor.ITALIC + "Active"); /* ** ----- Speed tools ----- ** */ if (Toggles.TOOLS_TOOLS_SPEED.get()) { // Normal speed ItemStack normalSpeed = GuiUtils.makeItem(Material.STRING, ChatColor.DARK_AQUA + "Normal speed", speedLevel == 0 ? activeLore : null); if (speedLevel == 0) GlowEffect.addGlow(normalSpeed); action("speed_0", 2, normalSpeed); // Speed I ItemStack speedI = GuiUtils.makeItem(Material.FEATHER, ChatColor.AQUA + "Speed I", speedLevel == 1 ? activeLore : null); if (speedLevel == 1) GlowEffect.addGlow(speedI); action("speed_1", 3, speedI); // Speed II ItemStack speedII = GuiUtils.makeItem(Material.FEATHER, ChatColor.AQUA + "Speed II", speedLevel == 2 ? activeLore : null); speedII.setAmount(2); if (speedLevel == 2) GlowEffect.addGlow(speedII); action("speed_2", 4, speedII); // Speed III ItemStack speedIII = GuiUtils.makeItem(Material.FEATHER, ChatColor.AQUA + "Speed III", speedLevel == 3 ? activeLore : null); speedIII.setAmount(3); if (speedLevel == 3) GlowEffect.addGlow(speedIII); action("speed_3", 5, speedIII); // Speed IV ItemStack speedIV = GuiUtils.makeItem(Material.FEATHER, ChatColor.AQUA + "Speed IV", speedLevel == 4 ? activeLore : null); speedIV.setAmount(4); if (speedLevel == 4) GlowEffect.addGlow(speedIV); action("speed_4", 6, speedIV); } /* ** ----- Lines 2 & 3: content ----- ** */ List<Pair<String, ItemStack>> toolsOnLine2 = new ArrayList<>(); // No-clip if (Toggles.TOOLS_TOOLS_NOCLIP.get()) { ItemStack noClip = GuiUtils.makeItem(Material.BARRIER, ChatColor.LIGHT_PURPLE + "No-clip mode", Arrays.asList(ChatColor.GRAY + "Allows you to go through all the blocks.", "", ChatColor.GRAY + "You can also first-spectate a player", ChatColor.GRAY + "by left-clicking on him", ChatColor.DARK_GRAY + "Use Shift to quit the first-person", ChatColor.DARK_GRAY + "spectator mode.", "", ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "In this mode, open your inventory", ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "to access controls!")); toolsOnLine2.add(Pair.of("noClip", noClip)); } // Night vision if (Toggles.TOOLS_TOOLS_NIGHTVISION.get()) { ItemStack nightVision = GuiUtils.makeItem( nightVisionActive ? Material.EYE_OF_ENDER : Material.ENDER_PEARL, nightVisionActive ? ChatColor.DARK_PURPLE + "Disable night vision" : ChatColor.GOLD + "Enable night vision"); toolsOnLine2.add(Pair.of("nightVision", nightVision)); } // Diving suit if (Toggles.TOOLS_TOOLS_DIVINGSUIT.get()) { ItemStack divingSuit = GuiUtils.makeItem(Material.DIAMOND_BOOTS, ChatColor.BLUE + "Diving suit", Collections.singletonList(ChatColor.GRAY + "Get a pair of Depth Strider III boots")); if (divingSuitEquipped) { ItemMeta meta = divingSuit.getItemMeta(); List<String> lore = meta.getLore(); lore.add(activeLore.get(0)); meta.setLore(lore); divingSuit.setItemMeta(meta); GlowEffect.addGlow(divingSuit); } toolsOnLine2.add(Pair.of("divingSuit", divingSuit)); } // Teleportation to the death point ItemStack tpToDeathPoint = null; if (Toggles.TOOLS_TOOLS_TPTODEATH_ENABLED.get() && deathPoint != null) { tpToDeathPoint = GuiUtils.makeItem(Material.NETHER_STAR, ChatColor.YELLOW + "Go to your death point", Toggles.TOOLS_TOOLS_TPTODEATH_DISPLAYCAUSE.get() && spectator.getLastDeathMessage() != null ? Collections.singletonList(ChatColor.GRAY + spectator.getLastDeathMessage()) : null); } /* ** ----- Lines 2 & 3: display ----- ** */ int lineSize = toolsOnLine2.size(); if (lineSize == 0 && deathPoint != null) { action("deathPoint", offset + 4, tpToDeathPoint); } else if (lineSize == 1) { if (deathPoint != null) { final Pair<String, ItemStack> toolZero = toolsOnLine2.get(0); action(toolZero.getKey(), offset + 2, toolZero.getValue()); action("deathPoint", offset + 6, tpToDeathPoint); } else { final Pair<String, ItemStack> toolZero = toolsOnLine2.get(0); action(toolZero.getKey(), offset + 4, toolZero.getValue()); } } else if (lineSize == 2) { if (deathPoint != null) { final Pair<String, ItemStack> toolZero = toolsOnLine2.get(0); final Pair<String, ItemStack> toolOne = toolsOnLine2.get(1); action(toolZero.getKey(), offset + 2, toolZero.getValue()); action(toolOne.getKey(), offset + 4, toolOne.getValue()); action("deathPoint", offset + 6, tpToDeathPoint); } else { final Pair<String, ItemStack> toolZero = toolsOnLine2.get(0); final Pair<String, ItemStack> toolOne = toolsOnLine2.get(1); action(toolZero.getKey(), offset + 2, toolZero.getValue()); action(toolOne.getKey(), offset + 6, toolOne.getValue()); } } else if (lineSize == 3) { final Pair<String, ItemStack> toolZero = toolsOnLine2.get(0); final Pair<String, ItemStack> toolOne = toolsOnLine2.get(1); final Pair<String, ItemStack> toolTwo = toolsOnLine2.get(2); action(toolZero.getKey(), offset + 2, toolZero.getValue()); action(toolOne.getKey(), offset + 4, toolOne.getValue()); action(toolTwo.getKey(), offset + 6, toolTwo.getValue()); if (deathPoint != null) { action("deathPoint", offset + 6, tpToDeathPoint); } } }
From source file:com.microsoft.azure.keyvault.cryptography.RsaKey.java
@Override public ListenableFuture<Pair<byte[], String>> wrapKeyAsync(final byte[] key, final String algorithm) throws NoSuchAlgorithmException { if (key == null) { throw new IllegalArgumentException("key"); }//from www. j av a2 s . c o m // Interpret the requested algorithm String algorithmName = (Strings.isNullOrWhiteSpace(algorithm) ? getDefaultKeyWrapAlgorithm() : algorithm); Algorithm baseAlgorithm = AlgorithmResolver.Default.get(algorithmName); if (baseAlgorithm == null || !(baseAlgorithm instanceof AsymmetricEncryptionAlgorithm)) { throw new NoSuchAlgorithmException(algorithmName); } AsymmetricEncryptionAlgorithm algo = (AsymmetricEncryptionAlgorithm) baseAlgorithm; ICryptoTransform transform; ListenableFuture<Pair<byte[], String>> result; try { transform = algo.CreateEncryptor(_keyPair, _provider); result = Futures.immediateFuture(Pair.of(transform.doFinal(key), algorithmName)); } catch (Exception e) { result = Futures.immediateFailedFuture(e); } return result; }
From source file:io.cloudslang.lang.runtime.steps.ExecutableExecutionData.java
/** * This method is executed by the finishExecutable execution step of an operation or flow * * @param runEnv the run environment object * @param executableOutputs the operation outputs data * @param executableResults the operation results data * @param executionRuntimeServices services supplied by score engine for handling the execution */// ww w. j a v a 2s. co m public void finishExecutable(@Param(ScoreLangConstants.RUN_ENV) RunEnvironment runEnv, @Param(ScoreLangConstants.EXECUTABLE_OUTPUTS_KEY) List<Output> executableOutputs, @Param(ScoreLangConstants.EXECUTABLE_RESULTS_KEY) List<Result> executableResults, @Param(EXECUTION_RUNTIME_SERVICES) ExecutionRuntimeServices executionRuntimeServices, @Param(ScoreLangConstants.NODE_NAME_KEY) String nodeName, @Param(ScoreLangConstants.EXECUTABLE_TYPE) ExecutableType executableType) { try { runEnv.getExecutionPath().up(); Context operationContext = runEnv.getStack().popContext(); Map<String, Value> operationVariables = operationContext == null ? null : operationContext.getImmutableViewOfVariables(); ReturnValues actionReturnValues = buildReturnValues(runEnv, executableType); LanguageEventData.StepType stepType = LanguageEventData.convertExecutableType(executableType); fireEvent(executionRuntimeServices, runEnv, ScoreLangConstants.EVENT_OUTPUT_START, "Output binding started", stepType, nodeName, operationVariables, Pair.of(ScoreLangConstants.EXECUTABLE_OUTPUTS_KEY, (Serializable) executableOutputs), Pair.of(ScoreLangConstants.EXECUTABLE_RESULTS_KEY, (Serializable) executableResults), Pair.of(ACTION_RETURN_VALUES_KEY, executableType == ExecutableType.OPERATION ? new ReturnValues(new HashMap<String, Value>(), actionReturnValues.getResult()) : actionReturnValues)); // Resolving the result of the operation/flow String result = resultsBinding.resolveResult(operationVariables, actionReturnValues.getOutputs(), runEnv.getSystemProperties(), executableResults, actionReturnValues.getResult()); Map<String, Value> outputsBindingContext = MapUtils.mergeMaps(operationVariables, actionReturnValues.getOutputs()); Map<String, Value> operationReturnOutputs = outputsBinding.bindOutputs(outputsBindingContext, runEnv.getSystemProperties(), executableOutputs); ReturnValues returnValues = new ReturnValues(operationReturnOutputs, result); runEnv.putReturnValues(returnValues); fireEvent(executionRuntimeServices, runEnv, ScoreLangConstants.EVENT_OUTPUT_END, "Output binding finished", stepType, nodeName, operationVariables, Pair.of(LanguageEventData.OUTPUTS, (Serializable) operationReturnOutputs), Pair.of(LanguageEventData.RESULT, returnValues.getResult())); // If we have parent flow data on the stack, we pop it and request the score engine to switch // to the parent execution plan id once it can, and we set the next position that was stored there // for the use of the navigation if (!runEnv.getParentFlowStack().isEmpty()) { handleNavigationToParent(runEnv, executionRuntimeServices); } else { fireEvent(executionRuntimeServices, runEnv, ScoreLangConstants.EVENT_EXECUTION_FINISHED, "Execution finished running", stepType, nodeName, operationVariables, Pair.of(LanguageEventData.RESULT, returnValues.getResult()), Pair.of(LanguageEventData.OUTPUTS, (Serializable) operationReturnOutputs)); } } catch (RuntimeException e) { logger.error("There was an error running the finish executable execution step of: \'" + nodeName + "\'.\n\tError is: " + e.getMessage()); throw new RuntimeException("Error running: \'" + nodeName + "\'.\n\t" + e.getMessage(), e); } }
From source file:enumj.EnumeratorTest.java
@Test public void testOf_Supplier() { System.out.println("of supplier"); EnumeratorGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().ofSupplierEnumerator(), p.getRight().ofSupplierEnumerator())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); EnumeratorGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().ofSupplierEnumerator(), p.getRight().ofSpliteratorEnumerator())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); }
From source file:com.spotify.heroic.test.AbstractSuggestBackendIT.java
@Test public void tagSuggest() throws Exception { writeSeries(backend, testSeries);/*ww w . jav a2 s. co m*/ final Set<Pair<String, String>> result = getTagSuggest(tagSuggestReq); assertEquals(ImmutableSet.of(Pair.of("role", "bar"), Pair.of("role", "baz")), result); }