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.formkiq.core.util.Strings.java
/** * Extract Label / Value from String.//from w w w. j a v a 2 s . co m * @param s {@link String} * @return {@link Pair} */ public static Pair<String, String> extractLabelAndValue(final String s) { if (!StringUtils.isEmpty(s)) { Matcher m = EXTRACT_LABEL_VALUE.matcher(s); if (m.matches()) { return Pair.of(m.group(1), m.group(2)); } return Pair.of(s, s); } return Pair.of("", ""); }
From source file:enumj.EnumeratorTest.java
@Test public void testOf_Stream() { System.out.println("of stream"); EnumeratorGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().ofStreamEnumerator(), p.getRight().ofStreamEnumerator())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); EnumeratorGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().ofStreamEnumerator(), p.getRight().ofEnumerationEnumerator())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); }
From source file:net.fabricmc.loader.FabricLoader.java
public void load(Collection<File> modFiles) { if (modsLoaded) { throw new RuntimeException("FabricLoader has already had mods loaded!"); }//from w w w .j a v a 2s. com List<Pair<ModInfo, File>> existingMods = new ArrayList<>(); int classpathModsCount = 0; if (Boolean.parseBoolean(System.getProperty("fabric.development", "false"))) { List<Pair<ModInfo, File>> classpathMods = getClasspathMods(); existingMods.addAll(classpathMods); classpathModsCount = classpathMods.size(); LOGGER.debug("Found %d classpath mods", classpathModsCount); } for (File f : modFiles) { if (f.isDirectory()) { continue; } if (!f.getPath().endsWith(".jar")) { continue; } ModInfo[] fileMods = getJarMods(f); if (Launch.classLoader != null && fileMods.length != 0) { try { Launch.classLoader.addURL(f.toURI().toURL()); } catch (MalformedURLException e) { LOGGER.error("Unable to load mod from %s", f.getName()); e.printStackTrace(); continue; } } for (ModInfo info : fileMods) { existingMods.add(Pair.of(info, f)); } } LOGGER.debug("Found %d JAR mods", existingMods.size() - classpathModsCount); mods: for (Pair<ModInfo, File> pair : existingMods) { ModInfo mod = pair.getLeft(); /* if (mod.isLazilyLoaded()) { innerMods: for (Pair<ModInfo, File> pair2 : existingMods) { ModInfo mod2 = pair2.getLeft(); if (mod == mod2) { continue innerMods; } for (Map.Entry<String, ModInfo.Dependency> entry : mod2.getRequires().entrySet()) { String depId = entry.getKey(); ModInfo.Dependency dep = entry.getValue(); if (depId.equalsIgnoreCase(mod.getId()) && dep.satisfiedBy(mod)) { addMod(mod, pair.getRight(), loaderInitializesMods()); } } } continue mods; } */ addMod(mod, pair.getRight(), loaderInitializesMods()); } String modText; switch (mods.size()) { case 0: modText = "Loading %d mods"; break; case 1: modText = "Loading %d mod: %s"; break; default: modText = "Loading %d mods: %s"; break; } LOGGER.info(modText, mods.size(), String.join(", ", mods.stream().map(ModContainer::getInfo).map(ModInfo::getId).collect(Collectors.toList()))); modsLoaded = true; onModsPopulated(); }
From source file:com.twitter.distributedlog.service.balancer.TestClusterBalancer.java
@Ignore @Test(timeout = 60000)//from www . j ava 2s . com public void testBalanceAll() throws Exception { String namePrefix = "clusterbalancer-balance-all-"; initStreams(namePrefix); writeStreams(namePrefix); validateStreams(namePrefix); Optional<RateLimiter> rateLimiter = Optional.absent(); Balancer balancer = new ClusterBalancer(client.dlClientBuilder, Pair.of((DistributedLogClient) client.dlClient, (MonitorServiceClient) client.dlClient)); logger.info("Rebalancing from 'unknown' target"); try { balancer.balanceAll("unknown", 10, rateLimiter); fail("Should fail on balanceAll from 'unknown' target."); } catch (IllegalArgumentException iae) { // expected } validateStreams(namePrefix); logger.info("Rebalancing from 'unexisted' host"); String addr = DLSocketAddress.toString(DLSocketAddress.getSocketAddress(9999)); balancer.balanceAll(addr, 10, rateLimiter); validateStreams(namePrefix); addr = DLSocketAddress.toString(cluster.get(0).getAddress()); logger.info("Rebalancing from host {}.", addr); balancer.balanceAll(addr, 10, rateLimiter); checkStreams(0, cluster.get(0)); checkStreams(4, cluster.get(1)); checkStreams(3, cluster.get(2)); checkStreams(4, cluster.get(3)); checkStreams(4, cluster.get(4)); addr = DLSocketAddress.toString(cluster.get(2).getAddress()); logger.info("Rebalancing from host {}.", addr); balancer.balanceAll(addr, 10, rateLimiter); checkStreams(3, cluster.get(0)); checkStreams(4, cluster.get(1)); checkStreams(0, cluster.get(2)); checkStreams(4, cluster.get(3)); checkStreams(4, cluster.get(4)); logger.info("Rebalancing the cluster"); balancer.balance(0, 0.0f, 10, rateLimiter); for (int i = 0; i < 5; i++) { checkStreams(3, cluster.get(i)); } }
From source file:de.ks.text.view.AsciiDocViewer.java
public void preload(Collection<AsciiDocContent> load) { ActivityExecutor executorService = controller.getExecutorService(); JavaFXExecutorService javaFXExecutor = controller.getJavaFXExecutor(); load.forEach(t -> {/* www .ja v a 2 s . c o m*/ CompletableFuture<Pair<String, String>> completableFuture = CompletableFuture .supplyAsync(() -> preProcess(t.getAdoc()), executorService)// .thenApply(desc -> { if (desc == null || desc.trim().isEmpty()) { return ""; } else { return parser.parse(desc); } })// .thenApply(html -> Pair.of(t.getIdentifier(), html)); completableFuture.thenApply(pair -> { preloaded.put(pair.getKey(), pair.getValue()); return pair; }).thenAcceptAsync(pair -> { if (currentIdentifier.getValueSafe().equals(pair.getKey())) { String html = pair.getValue(); currentHtml.set(html); webView.getEngine().loadContent(html); } }, javaFXExecutor)// .exceptionally(e -> { log.error("Could not parse adoc", e); return null; }); }); }
From source file:li.klass.fhem.domain.culhm.ThermostatTest.java
@Test @SuppressWarnings("unchecked") public void should_use_first_device_when_finding_multiple_prefixes() { CULHMDevice device = getDeviceFor("deviceWithMorePrefix", CULHMDevice.class); assertThat(device).isNotNull();/*www . j av a 2s . c o m*/ WeekProfile<FilledTemperatureInterval, CULHMConfiguration, CULHMDevice> weekProfile = device .getWeekProfile(); assertThat(weekProfile).isNotNull(); assertWeekProfileContainsExactly(weekProfile, SATURDAY, Pair.of("08:00", 20.0), Pair.of("23:00", 22.0), Pair.of("24:00", 20.0)); assertWeekProfileContainsExactly(weekProfile, SUNDAY, Pair.of("08:00", 20.0), Pair.of("22:00", 22.0), Pair.of("24:00", 20.0)); assertWeekProfileContainsExactly(weekProfile, MONDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0), Pair.of("24:00", 20.0)); assertWeekProfileContainsExactly(weekProfile, TUESDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0), Pair.of("24:00", 20.0)); assertWeekProfileContainsExactly(weekProfile, WEDNESDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0), Pair.of("24:00", 20.0)); assertWeekProfileContainsExactly(weekProfile, THURSDAY, Pair.of("04:50", 20.0), Pair.of("22:00", 22.0), Pair.of("24:00", 20.0)); assertWeekProfileContainsExactly(weekProfile, FRIDAY, Pair.of("04:50", 20.0), Pair.of("23:00", 22.0), Pair.of("24:00", 20.0)); }
From source file:com.netflix.imfutility.itunes.audio.ChannelsMapperTest.java
@Test public void testSurroundWithTwoStereo() throws Exception { TemplateParameterContextProvider contextProvider = AudioUtils.createContext( new FFmpegAudioChannels[][] { { FL, FR }, { FC }, { FL, FR, FC, LFE, SL, SR }, { FL, FR } }, new String[] { "fr", "en", "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), 2, 1); assertChannelEquals(channels.get(1), 2, 2); assertChannelEquals(channels.get(2), 2, 3); assertChannelEquals(channels.get(3), 2, 4); assertChannelEquals(channels.get(4), 2, 5); assertChannelEquals(channels.get(5), 2, 6); assertChannelEquals(channels.get(6), 3, 1); assertChannelEquals(channels.get(7), 3, 2); assertEquals(8, channels.size());//from ww w . j a v a 2s .c o m }
From source file:com.teambrmodding.neotech.common.tiles.machines.processors.TileSolidifier.java
/** * Used to tell if this tile is able to process * * @return True if you are able to process *///from ww w. ja va2 s.c o m @Override public boolean canProcess() { if (energyStorage.getEnergyStored() > getEnergyCostPerTick() && tanks[TANK].getFluid() != null) { if (getStackInSlot(OUTPUT_SLOT) == null) { SolidifierRecipe recipe = ((SolidifierRecipeHandler) RecipeManager .getHandler(RecipeManager.RecipeType.SOLIDIFIER)) .getRecipe(Pair.of(currentMode, tanks[TANK].getFluid())); if (recipe != null && tanks[TANK] .getFluidAmount() >= AbstractRecipe.getFluidStackFromString(recipe.inputFluidStack).amount) return true; } else { SolidifierRecipe recipe = ((SolidifierRecipeHandler) RecipeManager .getHandler(RecipeManager.RecipeType.SOLIDIFIER)) .getRecipe(Pair.of(currentMode, tanks[TANK].getFluid())); if (recipe != null) { ItemStack output = AbstractRecipe.getItemStackFromString(recipe.outputItemStack); if (tanks[TANK].getFluidAmount() >= AbstractRecipe .getFluidStackFromString(recipe.inputFluidStack).amount) { ItemStack ourStack = getStackInSlot(OUTPUT_SLOT); if (output.getItem() == ourStack.getItem() && output.getItemDamage() == ourStack.getItemDamage() && ourStack.getCount() + output.getCount() <= ourStack.getMaxStackSize()) return true; } } return false; } } failCoolDown = 40; return false; }
From source file:enumj.EnumerableTest.java
@Test public void testOf_Supplier() { System.out.println("of"); EnumerableGenerator.generatorPairs().limit(100) .map(p -> Pair.of(p.getLeft().ofSupplierEnumerable(), p.getRight().ofSupplierEnumerable())) .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight()))); }
From source file:com.foudroyantfactotum.mod.fousarchive.command.CommandPianoRollID.java
private List<Pair<SearchMatch, String>> parse(String s) throws CommandException { final List<Pair<SearchMatch, String>> list = new LinkedList<>(); while (!s.isEmpty() && s.length() >= 1) { final SearchMatch sm = SearchMatch.getOnChar(s.charAt(0)); if (sm == null) throw new CommandException("Expected SearchMatch value found '" + s.charAt(0) + '\''); if (s.length() <= 1) { list.add(Pair.of(sm, "")); s = ""; continue; }/*from w w w . j ava2s . c o m*/ if (s.charAt(1) == '\"') { s = s.substring(2); final int ifq = s.indexOf('\"'); if (ifq < 0) throw new CommandException("Missing matching \" for '" + sm + '\''); final String s1 = s.substring(0, ifq); s = s.substring(ifq + 1).trim(); list.add(Pair.of(sm, s1)); } else { list.add(Pair.of(sm, "")); s = s.substring(1).trim(); } } return list; }