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:com.netflix.genie.web.data.entities.AgentConnectionEntityTest.java

/**
 * Verify validated fields value.//w  ww. j  av a 2s .  c  om
 */
@Test
public void cantCreateAgentConnectionEntityDueToSize() {

    final List<Pair<String, String>> invalidParameterPairs = Lists.newArrayList();

    invalidParameterPairs.add(Pair.of(JOB, null));
    invalidParameterPairs.add(Pair.of(null, HOST));
    invalidParameterPairs.add(Pair.of(JOB, " "));
    invalidParameterPairs.add(Pair.of(" ", HOST));
    invalidParameterPairs.add(Pair.of(StringUtils.rightPad(JOB, 256), HOST));
    invalidParameterPairs.add(Pair.of(JOB, StringUtils.rightPad(HOST, 256)));

    for (final Pair<String, String> invalidParameters : invalidParameterPairs) {
        final AgentConnectionEntity entity = new AgentConnectionEntity(invalidParameters.getLeft(),
                invalidParameters.getRight());

        try {
            this.validate(entity);
        } catch (final ConstraintViolationException e) {
            // Expected, move on to the next pair.
            continue;
        }

        Assert.fail("Entity unexpectedly passed validation: " + entity.toString());
    }
}

From source file:com.yahoo.elide.core.exceptions.HttpStatusException.java

private Pair<Integer, JsonNode> buildResponse(Map<String, List<String>> errors) {
    JsonNode responseBody = OBJECT_MAPPER.convertValue(errors, JsonNode.class);
    return Pair.of(getStatus(), responseBody);
}

From source file:com.twitter.distributedlog.service.balancer.CountBasedStreamChooser.java

CountBasedStreamChooser(Map<SocketAddress, Set<String>> streams) {
    Preconditions.checkArgument(streams.size() > 0, "Only support no-empty streams distribution");
    streamsDistribution = new ArrayList<Pair<SocketAddress, LinkedList<String>>>(streams.size());
    for (Map.Entry<SocketAddress, Set<String>> entry : streams.entrySet()) {
        LinkedList<String> randomizedStreams = new LinkedList<String>(entry.getValue());
        Collections.shuffle(randomizedStreams);
        streamsDistribution.add(Pair.of(entry.getKey(), randomizedStreams));
    }/*from w  ww. j  ava 2s  .  c om*/
    // sort the hosts by the number of streams in descending order
    Collections.sort(streamsDistribution, this);
    pivot = 0;
    pivotCount = streamsDistribution.get(0).getValue().size();
    findNextPivot();
    next = 0;
}

From source file:fr.landel.utils.commons.function.BiSupplierThrowableTest.java

/**
 * Test method for {@link BiSupplierThrowable#getThrows()}.
 */// www .j  a v  a 2  s.co  m
@Test
public void testGetThrows() {
    boolean test = false;
    final String error = "error";

    final BiSupplierThrowable<String, String, IllegalArgumentException> s1 = () -> Pair.of("l", "r");
    final BiSupplierThrowable<String, String, IOException> s2 = () -> {
        if (test) {
            return Pair.of("l", "r");
        }
        throw new IOException(error);
    };

    try {
        assertEquals("(l,r)", s1.getThrows().toString());
    } catch (IllegalArgumentException e) {
        fail("Supplier failed");
    }

    try {
        s2.getThrows();
        fail("Supplier has to fail");
    } catch (IOException e) {
        assertNotNull(e);
        assertEquals(error, e.getMessage());
    }
}

From source file:de.vandermeer.skb.mvn.pm.model.ModelLoader.java

/**
 * Creates a new model loader./*from  w ww .jav a  2 s . c  om*/
 * @param mc model context
 * @param folders collection of project folders
 * @throws NullPointerException if the collection or any member was null
 * @throws IllegalArgumentException if any collection member resulted in a was a blank string or pointed to an unreadable/unwritable directory
 */
public ModelLoader(PM_Context mc, Collection<Object> folders) {
    Validate.notNull(mc);
    this.mc = mc;

    this.projectFiles = new LinkedHashMap<>();

    StrBuilder errors = new StrBuilder();
    StrBuilder _err;
    for (Object o : folders) {
        File prjDir = new File(o.toString());

        //set the loaded map entry
        this.projectFiles.put(prjDir,
                Pair.of(new File(prjDir + File.separator + this.mc.getProjectPmDir()),
                        new File(prjDir + File.separator + this.mc.getProjectPmDir() + File.separator
                                + ProjectFiles.MANAGED_PROJECT_PROPERTIES.getFileName())));

        _err = this.testProjectDirectory(prjDir);
        errors.append(_err);
        if (_err.size() == 0) {
            _err = this.testProjectPmDirectory(this.projectFiles.get(prjDir).getKey());
            errors.append(_err);
            if (_err.size() == 0) {
                _err = this.testProjectPmFiles(this.projectFiles.get(prjDir).getValue());
                errors.append(_err);
            }
        }
    }

    if (errors.size() > 0) {
        throw new IllegalArgumentException(
                "pm loader: problems with one or more directories, see below\n" + errors.toString());
    }
}

From source file:edu.washington.gs.skyline.model.quantification.GroupComparisonDataSet.java

public LinearFitResult calculateFoldChange(String label) {
    List<Replicate> replicates = removeIncompleteReplicates(label, this.replicates);
    if (replicates.size() == 0) {
        return null;
    }/*w w  w.  jav  a2 s  .  c om*/
    List<Replicate> summarizedRows;
    if (replicates.stream().anyMatch(row -> null != row.getBioReplicate())) {
        Map<Pair<Boolean, Object>, List<Replicate>> groupedByBioReplicate = replicates.stream().collect(
                Collectors.groupingBy(replicate -> Pair.of(replicate.isControl(), replicate.bioReplicate)));
        summarizedRows = new ArrayList<>();
        for (Map.Entry<Pair<Boolean, Object>, List<Replicate>> entry : groupedByBioReplicate.entrySet()) {
            Double log2Abundance = calculateMean(entry.getValue().stream()
                    .map(replicateData -> replicateData.getLog2Abundance(label)).collect(Collectors.toList()));
            if (log2Abundance == null) {
                continue;
            }
            Replicate combinedReplicate = new Replicate(entry.getKey().getLeft(), entry.getKey().getValue());
            ResultFileData resultFileData = combinedReplicate.ensureResultFileData();
            resultFileData.setTransitionAreas(label,
                    TransitionAreas.fromMap(Collections.singletonMap("", Math.pow(2.0, log2Abundance))));
            if (getNormalizationMethod() instanceof NormalizationMethod.RatioToLabel) {
                TransitionAreas denominator = TransitionAreas.fromMap(Collections.singletonMap("", 1.0));
                resultFileData.setTransitionAreas(
                        ((NormalizationMethod.RatioToLabel) getNormalizationMethod()).getIsotopeLabelTypeName(),
                        denominator);
            }
            summarizedRows.add(combinedReplicate);
        }
    } else {
        summarizedRows = replicates;
    }

    List<Double> abundances = summarizedRows.stream()
            .map(replicateData -> replicateData.getLog2Abundance(label)).collect(Collectors.toList());
    List<Integer> features = Collections.nCopies(summarizedRows.size(), 0);
    List<Integer> runs = IntStream.range(0, summarizedRows.size()).boxed().collect(Collectors.toList());
    List<Integer> subjects = IntStream.range(0, summarizedRows.size()).boxed().collect(Collectors.toList());
    List<Boolean> subjectControls = summarizedRows.stream().map(Replicate::isControl)
            .collect(Collectors.toList());
    FoldChangeDataSet foldChangeDataSet = new FoldChangeDataSet(abundances, features, runs, subjects,
            subjectControls);
    DesignMatrix designMatrix = DesignMatrix.getDesignMatrix(foldChangeDataSet, false);
    LinearFitResult linearFitResult = designMatrix.performLinearFit().get(0);
    return linearFitResult;
}

From source file:alfio.util.MustacheCustomTagInterceptor.java

private static Pair<String, Optional<Locale>> parseParams(String r) {

    int indexLocale = r.indexOf(LOCALE_LABEL),
            end = Math.min(r.length(), indexLocale != -1 ? indexLocale : r.length());
    String format = substring(r, r.indexOf(" "), end);

    ////from   w w  w .  j a va  2s  . c o  m
    String[] res = r.split("\\s+");
    Optional<Locale> locale = Arrays.asList(res).stream().filter((s) -> s.startsWith(LOCALE_LABEL)).findFirst()
            .map((l) -> {
                return Locale.forLanguageTag(substring(l, LOCALE_LABEL.length()));
            });
    //

    return Pair.of(format, locale);
}

From source file:com.github.steveash.guavate.ObjIntPair.java

/**
 * Converts this pair to an object-based {@code Pair}.
 *
 * @return the object-based pair
 */
public Pair<A, Integer> toPair() {
    return Pair.of(first, second);
}

From source file:de.hasait.clap.impl.CLAPParseContext.java

public void addOption(final CLAPOptionNode<?> pOption, final List<String> pArgs) {
    _nodeContextMap.add(Pair.of(pOption, pArgs));
}

From source file:cc.recommenders.evaluation.distribution.calc.F1AndSizeWorkerTest.java

private void setResult(int sizeInB, double... values) {
    when(sut.evaluator.getRawResults()).thenReturn(Pair.of(values, sizeInB));
}