Example usage for org.apache.commons.lang3.tuple Pair of

List of usage examples for org.apache.commons.lang3.tuple Pair of

Introduction

In this page you can find the example usage for org.apache.commons.lang3.tuple Pair of.

Prototype

public static <L, R> Pair<L, R> of(final L left, final R right) 

Source Link

Document

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.

Usage

From source file:net.lldp.checksims.util.PairGeneratorTest.java

@Test
public void TestGeneratePairsWithArchiveOneElementArchive() {
    Set<Submission> submissions = setFromElements(a, b);
    Set<Submission> archive = singleton(c);

    Set<Pair<Submission, Submission>> expected = setFromElements(Pair.of(a, b), Pair.of(a, c), Pair.of(b, c));
    Set<Pair<Submission, Submission>> results = PairGenerator.generatePairsWithArchive(submissions, archive);

    checkPairsAreInSet(results, expected);
}

From source file:net.minecraftforge.fml.common.network.internal.FMLNetworkHandler.java

/**
 * @param listData map of modId string to version string, represents the mods available on the given side
 * @param side the side that listData is coming from, either client or server
 * @return null if everything is fine, returns a string error message if there are mod rejections
 *//*from   ww w.  ja  va 2 s.  com*/
@Nullable
public static String checkModList(Map<String, String> listData, Side side) {
    List<Pair<ModContainer, String>> rejects = NetworkRegistry.INSTANCE.registry().entrySet().stream()
            .map(entry -> Pair.of(entry.getKey(), entry.getValue().checkCompatible(listData, side)))
            .filter(pair -> pair.getValue() != null).sorted(Comparator.comparing(o -> o.getKey().getName()))
            .collect(Collectors.toList());
    if (rejects.isEmpty()) {
        return null;
    } else {
        List<String> rejectStrings = new ArrayList<>();
        for (Pair<ModContainer, String> reject : rejects) {
            ModContainer modContainer = reject.getKey();
            rejectStrings.add(modContainer.getName() + ": " + reject.getValue());
        }
        String rejectString = String.join("\n", rejectStrings);
        FMLLog.log.info("Rejecting connection {}: {}", side, rejectString);
        return String.format("Server Mod rejections:\n%s", rejectString);
    }
}

From source file:edu.umd.umiacs.clip.tools.classifier.ConfusionMatrix.java

public Pair<Float, Float> getF1CI() {
    Percentile percentile = new Percentile();
    percentile.setData(Stream.of(sampleFromPosterior()).parallel().mapToDouble(cm -> cm.getF1()).toArray());
    double alpha = (1 - CONF_LEVEL) / 2;
    return Pair.of((float) percentile.evaluate(100 * alpha), (float) percentile.evaluate(100 * (1 - alpha)));
}

From source file:enumj.EnumeratorTest.java

@Test
public void testOf_Spliterator() {
    System.out.println("of spliterator");
    EnumeratorGenerator.generatorPairs().limit(100)
            .map(p -> Pair.of(p.getLeft().ofSpliteratorEnumerator(), p.getRight().ofSpliteratorEnumerator()))
            .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight())));
    EnumeratorGenerator.generatorPairs().limit(100)
            .map(p -> Pair.of(p.getLeft().ofSpliteratorEnumerator(), p.getRight().ofStreamEnumerator()))
            .forEach(p -> assertTrue(p.getLeft().elementsEqual(p.getRight())));
}

From source file:enumj.StreamComparator.java

private Pair<Function<Stream<T>, Stream<T>>, Function<E, E>> getSkipFuns() {
    final int seed = rnd.nextInt();
    final long n = this.skipLimitOfSeed.apply(seed);
    final Function<Stream<T>, Stream<T>> lhs = s -> s.skip(n);
    final Function<E, E> rhs = e -> skip(e, n);
    if (statistics != null) {
        statistics.skip();/*w w w . j a va 2  s  .c om*/
    }
    return Pair.of(lhs, rhs);
}

From source file:com.act.lcms.v2.MassChargeCalculatorTest.java

@Test
public void testComputeMass() throws Exception {
    List<Pair<MassChargeCalculator.MZSource, Double>> testCases = Arrays.asList(
            Pair.of(new MassChargeCalculator.MZSource(
                    "InChI=1S/C8H9NO2/c1-6(10)9-7-2-4-8(11)5-3-7/h2-5,11H,1H3,(H,9,10)"), 151.063329),
            Pair.of(new MassChargeCalculator.MZSource(151.063329), 151.063329),
            Pair.of(new MassChargeCalculator.MZSource(Pair.of("APAP", 151.063329)), 151.063329));

    for (Pair<MassChargeCalculator.MZSource, Double> testCase : testCases) {
        Double actualMass = MassChargeCalculator.computeMass(testCase.getLeft());
        assertEquals(/*  ww w  .j a  v a 2  s  . c o m*/
                String.format("(Case %d) Actual mass is within bounds: %.6f ~ %.6f", testCase.getLeft().getId(),
                        testCase.getRight(), actualMass),
                testCase.getRight(), actualMass, MASS_ERROR_TOLERANCE);
    }
}

From source file:alfio.manager.system.DataMigratorIntegrationTest.java

private Pair<Event, String> initEvent(List<TicketCategoryModification> categories, String displayName) {
    String organizationName = UUID.randomUUID().toString();
    String username = UUID.randomUUID().toString();
    String eventName = UUID.randomUUID().toString();

    organizationRepository.create(organizationName, "org", "email@example.com");
    Organization organization = organizationRepository.findByName(organizationName).get();
    userManager.insertUser(organization.getId(), username, "test", "test", "test@example.com", Role.OPERATOR,
            User.Type.INTERNAL);

    Map<String, String> desc = new HashMap<>();
    desc.put("en", "muh description");
    desc.put("it", "muh description");
    desc.put("de", "muh description");

    EventModification em = new EventModification(null, Event.EventType.INTERNAL, "url", "url", "url", null,
            null, eventName, displayName, organization.getId(), "muh location", "0.0", "0.0",
            ZoneId.systemDefault().getId(), desc,
            new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now()),
            new DateTimeModification(LocalDate.now().plusDays(5), LocalTime.now().plusHours(1)), BigDecimal.TEN,
            "CHF", AVAILABLE_SEATS, BigDecimal.ONE, true, null, categories, false,
            new LocationDescriptor("", "", "", ""), 7, null, null);
    eventManager.createEvent(em);/*from  w  w  w  . java2  s.  c  om*/
    return Pair.of(eventManager.getSingleEvent(eventName, username), username);
}

From source file:eu.openanalytics.rsb.component.AdminResourceTestCase.java

@Test
public void getApplicationUnawareCatalog() throws Exception {
    final File fakeCatalogDir = new File(FileUtils.getTempDirectory(), "rsb_test_catalog");
    FileUtils.forceMkdir(fakeCatalogDir);
    final Map<Pair<CatalogSection, File>, List<File>> fakeCatalog = Collections
            .singletonMap(Pair.of(CatalogSection.R_SCRIPTS, fakeCatalogDir), Collections.<File>emptyList());
    when(catalogManager.getCatalog(null)).thenReturn(fakeCatalog);

    final Catalog catalog = adminResource.getCatalogIndex(null, httpHeaders, uriInfo);
    assertThat(catalog, is(not(nullValue())));
    assertThat(catalog.getDirectories().size(), is(1));
}

From source file:eu.openanalytics.rsb.data.FileCatalogManager.java

@Override
@PreAuthorize("hasPermission(#applicationName, 'CATALOG_ADMIN')")
public Pair<PutCatalogFileResult, File> putCatalogFile(final CatalogSection catalogSection,
        final String applicationName, final String fileName, final InputStream in) throws IOException {
    final File catalogSectionDirectory = getCatalogSectionDirectory(catalogSection, applicationName);

    final File catalogFile = new File(catalogSectionDirectory, fileName);
    final boolean preExistingFile = catalogFile.isFile();

    final FileWriter fw = new FileWriter(catalogFile);
    IOUtils.copy(in, fw);/*from  w w  w. java 2  s .  c o  m*/
    IOUtils.closeQuietly(fw);

    final PutCatalogFileResult putCatalogFileResult = preExistingFile ? PutCatalogFileResult.UPDATED
            : PutCatalogFileResult.CREATED;

    getLogger().info(StringUtils.capitalize(putCatalogFileResult.toString().toLowerCase()) + " " + fileName
            + " in catalog section " + catalogSection.toString() + " as file: " + catalogFile);

    return Pair.of(putCatalogFileResult, catalogFile);
}

From source file:com.quartercode.eventbridge.test.def.extra.extension.DefaultSendPredicateCheckExtensionTest.java

private Event[] beforeCustomActions(Pair<BridgeConnector, Class<?>[]>... expectedEvents) {

    Event[] events = { new EmptyEvent1(), new EmptyEvent2(), new EmptyEvent3(), new EmptyEvent4(),
            new EmptyEvent5() };

    final List<Pair<BridgeConnector, Event>> actualExpectedEvents = new ArrayList<>();
    for (Event event : events) {
        for (Pair<BridgeConnector, Class<?>[]> expectation : expectedEvents) {
            if (Arrays.asList(expectation.getRight()).contains(event.getClass())) {
                actualExpectedEvents.add(Pair.of(expectation.getLeft(), event));
            }/*  w w w .  j  a  va2 s .  c  o  m*/
        }
    }

    // @formatter:off
    context.checking(new Expectations() {
        {

            for (Pair<BridgeConnector, Event> expectedEvent : actualExpectedEvents) {
                oneOf(interceptor).send(with(any(ChannelInvocation.class)), with(expectedEvent.getRight()),
                        with(expectedEvent.getLeft()));
            }

        }
    });
    // @formatter:on

    return events;
}