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

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

Introduction

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

Prototype

public abstract R getRight();

Source Link

Document

Gets the right element from this pair.

When treated as a key-value pair, this is the value.

Usage

From source file:com.grandhunterman.dnvm.common.Message.java

private final void writeField(Field f, Class clazz, ByteBuf buf)
        throws IllegalArgumentException, IllegalAccessException {
    Pair<Reader, Writer> handler = getHandler(clazz);
    handler.getRight().write(f.get(this), buf);
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.core.DataProcessor.java

private long calculateMetric(@NonNull List<SolutionPerJob> spjList,
        BiConsumer<SolutionPerJob, Double> resultSaver, Consumer<SolutionPerJob> ifEmpty) {
    //to support also parallel stream.
    AtomicLong executionTime = new AtomicLong();

    spjList.forEach(spj -> {/* ww w  . j a  v a  2 s  .c  o m*/
        Pair<Optional<Double>, Long> result = simulateClass(spj);
        executionTime.addAndGet(result.getRight());
        Optional<Double> optionalValue = result.getLeft();
        if (optionalValue.isPresent())
            resultSaver.accept(spj, optionalValue.get());
        else
            ifEmpty.accept(spj);
    });

    return executionTime.get();
}

From source file:com.qq.tars.service.PatchService.java

public String war2tgz(String packageWarPath, String serverName) throws Exception {
    String basePath = FilenameUtils.removeExtension(packageWarPath);
    String serverPath = basePath + "/" + serverName;
    String frameZipPath = new ClassPathResource("frame.zip").getFile().getCanonicalPath();

    StringBuilder script = new StringBuilder();
    script.append(String.format("rm -rf %s;", basePath));
    script.append(String.format("mkdir -p %s;", serverPath));
    script.append(String.format("unzip -q %s -d %s;", frameZipPath, serverPath));
    script.append(String.format("unzip -q %s -d %s/apps/ROOT/;", packageWarPath, serverPath));
    script.append(String.format("cd %s;tar -cvzf %s.tgz *;cd -;", basePath, basePath));
    script.append(String.format("rm -rf %s;", basePath));
    script.append(String.format("rm -rf %s;", packageWarPath));
    Pair<Integer, Pair<String, String>> result = SystemUtils.exec(script.toString());
    log.info("script={}, code={}, stdout={}, stderr={}", script, result.getLeft(), result.getRight().getLeft(),
            result.getRight().getRight());
    return basePath + ".tgz";
}

From source file:net.lldp.checksims.util.threading.SimilarityDetectionWorker.java

/**
 * Construct a Callable to perform pairwise similarity detection for one pair of assignments.
 *
 * @param algorithm Algorithm to use//w  ww  .  j  a va2  s.  com
 * @param submissions Assignments to compare
 */
public SimilarityDetectionWorker(SimilarityDetector<T> algorithm, Pair<Submission, Submission> submissions) {
    checkNotNull(algorithm);
    checkNotNull(submissions);
    checkNotNull(submissions.getLeft());
    checkNotNull(submissions.getRight());

    this.algorithm = algorithm;
    this.submissions = submissions;
}

From source file:com.hortonworks.registries.schemaregistry.state.DefaultCustomSchemaStateExecutor.java

@Override
public void init(SchemaVersionLifecycleStateMachine.Builder builder, Byte successStateId, Byte retryStateId,
        Map<String, ?> props) {
    this.successState = builder.getStates().get(successStateId);
    this.retryState = builder.getStates().get(retryStateId);
    inReviewState = new InReviewState(successState);
    builder.register(inReviewState);/*from   w  ww. ja v  a 2  s . c  om*/

    for (Pair<SchemaVersionLifecycleStateTransition, SchemaVersionLifecycleStateAction> pair : inReviewState
            .getTransitionActions()) {
        builder.transition(pair.getLeft(), pair.getRight());
    }
}

From source file:de.hub.cs.dbis.lrb.operators.AverageVehicleSpeedBolt.java

@Override
public void execute(Tuple input) {
    this.inputPositionReport.clear();
    this.inputPositionReport.addAll(input.getValues());
    LOGGER.trace(this.inputPositionReport.toString());

    Integer vid = this.inputPositionReport.getVid();
    short minute = this.inputPositionReport.getMinuteNumber();
    int speed = this.inputPositionReport.getSpeed().intValue();
    this.segment.set(this.inputPositionReport);

    assert (minute >= this.currentMinute);

    if (minute > this.currentMinute) {
        // emit all values for last minute
        // (because input tuples are ordered by ts, we can close the last minute safely)
        for (Entry<Integer, Pair<AvgValue, SegmentIdentifier>> entry : this.avgSpeedsMap.entrySet()) {
            Pair<AvgValue, SegmentIdentifier> value = entry.getValue();
            SegmentIdentifier segId = value.getRight();

            // VID, Minute-Number, X-Way, Segment, Direction, Avg(speed)
            this.collector.emit(new AvgVehicleSpeedTuple(entry.getKey(), new Short(this.currentMinute),
                    segId.getXWay(), segId.getSegment(), segId.getDirection(), value.getLeft().getAverage()));
        }/*www. j  a  v  a  2  s  .co  m*/

        this.avgSpeedsMap.clear();
        this.currentMinute = minute;
    }

    Pair<AvgValue, SegmentIdentifier> vehicleEntry = this.avgSpeedsMap.get(vid);
    if (vehicleEntry != null && !vehicleEntry.getRight().equals(this.segment)) {
        SegmentIdentifier segId = vehicleEntry.getRight();

        // VID, Minute-Number, X-Way, Segment, Direction, Avg(speed)
        this.collector.emit(new AvgVehicleSpeedTuple(vid, new Short(this.currentMinute), segId.getXWay(),
                segId.getSegment(), segId.getDirection(), vehicleEntry.getLeft().getAverage()));

        // set to null to get new vehicle entry below
        vehicleEntry = null;
    }

    if (vehicleEntry == null) {
        vehicleEntry = new MutablePair<AvgValue, SegmentIdentifier>(new AvgValue(speed), this.segment.copy());
        this.avgSpeedsMap.put(vid, vehicleEntry);
    } else {
        vehicleEntry.getLeft().updateAverage(speed);
    }

    this.collector.ack(input);
}

From source file:cc.recommenders.evaluation.OverviewOfSizeLambdas.java

private void visualizeResults() {
    for (Double lambda : results.keySet()) {
        System.out.println("## Lambda: " + lambda);
        System.out.println("best options: " + lambdaOptions.get(lambda));
        Pair<Boxplot, Integer> pair = results.get(lambda);
        System.out.println("avg. f1: " + pair.getLeft());
        System.out.println("avg. size: " + pair.getRight());
        System.out.println();//from  ww  w.  ja v  a  2s .  c o  m
    }
}

From source file:com.streamsets.datacollector.event.handler.remote.TestRemoteStateEventListener.java

@Test
public void testRemoteStateEventListener() throws Exception {
    RemoteStateEventListener remoteStateEventListener = new RemoteStateEventListener(new Configuration());
    remoteStateEventListener.init();// w w w . ja v  a 2 s.c om
    Map<String, Object> attributes = new HashMap<>();
    attributes.put(RemoteDataCollector.IS_REMOTE_PIPELINE, true);
    PipelineState pipelineState = new PipelineStateImpl("user", "name", "0", PipelineStatus.RUNNING, "msg", -1,
            attributes, ExecutionMode.STANDALONE, "", 1, -1);
    remoteStateEventListener.onStateChange(null, pipelineState, null, null,
            Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:1000"));
    Collection<Pair<PipelineState, Map<String, String>>> pipelineStateAndOffset = remoteStateEventListener
            .getPipelineStateEvents();
    Assert.assertEquals(1, pipelineStateAndOffset.size());
    Assert.assertEquals(PipelineStatus.RUNNING, pipelineStateAndOffset.iterator().next().getLeft().getStatus());
    Assert.assertEquals("offset:1000",
            pipelineStateAndOffset.iterator().next().getRight().get(Source.POLL_SOURCE_OFFSET_KEY));
    Assert.assertEquals(0, remoteStateEventListener.getPipelineStateEvents().size());

    PipelineState pipelineStateDeleted = new PipelineStateImpl("user", "name", "0", PipelineStatus.DELETED,
            "msg", -1, attributes, ExecutionMode.STANDALONE, "", 1, -1);
    remoteStateEventListener.onStateChange(null, pipelineState, null, null,
            Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:old"));
    remoteStateEventListener.onStateChange(null, pipelineStateDeleted, null, null,
            Collections.singletonMap(Source.POLL_SOURCE_OFFSET_KEY, "offset:new"));
    pipelineStateAndOffset = remoteStateEventListener.getPipelineStateEvents();
    Assert.assertEquals(2, pipelineStateAndOffset.size());
    Iterator<Pair<PipelineState, Map<String, String>>> iterator = pipelineStateAndOffset.iterator();
    iterator.next();
    Pair<PipelineState, Map<String, String>> pair = iterator.next();
    Assert.assertEquals(PipelineStatus.DELETED, pair.getLeft().getStatus());
    Assert.assertEquals("offset:new", pair.getRight().get(Source.POLL_SOURCE_OFFSET_KEY));
    Assert.assertEquals(0, remoteStateEventListener.getPipelineStateEvents().size());
}

From source file:it.polimi.diceH2020.SPACE4CloudWS.fineGrainedLogicForOptimization.ReactorConsumer.java

private Pair<Boolean, Long> runSolver(SolutionPerJob solPerJob) {
    Pair<Optional<Double>, Long> solverResult = solverCache.evaluate(solPerJob);
    Optional<Double> solverMetric = solverResult.getLeft();
    long runtime = solverResult.getRight();

    if (solverMetric.isPresent()) {
        PerformanceSolver solver = solverCache.getPerformanceSolver();
        Technology technology = dataService.getScenario().getTechnology();
        Double mainMetric = solver.transformationFromSolverResult(solPerJob, technology)
                .apply(solverMetric.get());
        solver.metricUpdater(solPerJob, technology).accept(mainMetric);
        boolean feasible = solver.feasibilityCheck(solPerJob, technology).test(mainMetric);
        solPerJob.setFeasible(feasible);
        return new ImmutablePair<>(true, runtime);
    }//w w w  .jav  a 2 s  . com

    solverCache.invalidate(solPerJob);
    return new ImmutablePair<>(false, runtime);
}

From source file:alfio.controller.support.TemplateProcessorTest.java

private void assertDimensionsUnder300x150(Pair<String, String> p) {
    Map<String, String> parameters = new HashMap<>();
    parameters.put(FileBlobMetadata.ATTR_IMG_WIDTH, p.getLeft());
    parameters.put(FileBlobMetadata.ATTR_IMG_HEIGHT, p.getRight());
    FileBlobMetadata metadata = mock(FileBlobMetadata.class);
    when(metadata.getAttributes()).thenReturn(parameters);
    Event e = mock(Event.class);
    when(e.getFileBlobIdIsPresent()).thenReturn(true);
    FileUploadManager fileUploadManager = mock(FileUploadManager.class);
    when(fileUploadManager.findMetadata(e.getFileBlobId())).thenReturn(Optional.of(metadata));
    TemplateProcessor.extractImageModel(e, fileUploadManager).ifPresent(imageData -> {
        assertTrue(imageData.getImageWidth() <= 300);
        assertTrue(imageData.getImageHeight() <= 150);
    });//  w  w  w  . j a v  a 2  s . c om
}