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

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

Introduction

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

Prototype

public abstract L getLeft();

Source Link

Document

Gets the left element from this pair.

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

Usage

From source file:alfio.util.TemplateResourceTest.java

@Test
public void buildModelForTicketPDF() throws Exception {
    Pair<ZonedDateTime, ZonedDateTime> dates = getDates();
    Map<String, Object> model = TemplateResource.buildModelForTicketPDF(organization, event, ticketReservation,
            ticketCategory, ticket, Optional.empty(), "abcd");
    assertEquals(dates.getLeft(), model.get("validityStart"));
    assertEquals(dates.getRight(), model.get("validityEnd"));
}

From source file:com.devicehive.auth.rest.HttpAuthenticationFilter.java

private void processBasicAuth(String authHeader) throws UnsupportedEncodingException {
    Pair<String, String> credentials = extractAndDecodeHeader(authHeader);
    UsernamePasswordAuthenticationToken requestAuth = new UsernamePasswordAuthenticationToken(
            credentials.getLeft().trim(), credentials.getRight().trim());
    tryAuthenticate(requestAuth);//from   w w  w .  j  a va 2s. com
}

From source file:net.lldp.checksims.algorithm.smithwaterman.SmithWaterman.java

/**
 * Apply the Smith-Waterman algorithm to determine the similarity between two submissions.
 *
 * Token list types of A and B must match
 *
 * @param a First submission to apply to
 * @param b Second submission to apply to
 * @return Similarity results of comparing submissions A and B
 * @throws TokenTypeMismatchException Thrown on comparing submissions with mismatched token types
 * @throws InternalAlgorithmError Thrown on internal error
 *//*from w w w. ja  v  a2  s  .co m*/
@Override
public AlgorithmResults detectSimilarity(Pair<Submission, Submission> ab, PercentableTokenListDecorator a,
        PercentableTokenListDecorator b) throws TokenTypeMismatchException, InternalAlgorithmError {
    checkNotNull(a);
    checkNotNull(b);

    // Test for token type mismatch
    // TODO move this to the tokenizer
    /*
    if(!a.getTokenType().equals(b.getTokenType())) {
    throw new TokenTypeMismatchException("Token list type mismatch: submission " + a.getName() + " has type " +
            a.getTokenType().toString() + ", while submission " + b.getName() + " has type "
            + b.getTokenType().toString());
    }
    */

    // Handle a 0-token submission (no similarity)
    if (a.size() == 0 || b.size() == 0) {
        return new AlgorithmResults(ab, a, b);
    } else if (a.equals(b)) {
        PercentableTokenListDecorator aInval = new PercentableTokenListDecorator(
                TokenList.invalidList(b.size()));
        return new AlgorithmResults(ab, aInval, aInval);
    }

    // Alright, easy cases taken care of. Generate an instance to perform the actual algorithm
    SmithWatermanAlgorithm algorithm = new SmithWatermanAlgorithm(a.getDataCopy(), b.getDataCopy());

    Pair<TokenList, TokenList> endLists = algorithm.computeSmithWatermanAlignmentExhaustive();

    PercentableTokenListDecorator atb = new PercentableTokenListDecorator(endLists.getLeft());
    PercentableTokenListDecorator bta = new PercentableTokenListDecorator(endLists.getRight());

    double x = atb.getPercentageMatched().asDouble();
    double y = bta.getPercentageMatched().asDouble();

    ab.getLeft().increaseScore(y * y, y);
    ab.getRight().increaseScore(x * x, x);

    return new AlgorithmResults(ab, new PercentableTokenListDecorator(endLists.getLeft()),
            new PercentableTokenListDecorator(endLists.getRight()));
}

From source file:controllers.admin.AttachmentsController.java

/**
 * Filters the attachment management table.
 *//*  w  w  w .java  2  s. co m*/
public Result attachmentsFilter() {
    String uid = getUserSessionManagerPlugin().getUserSessionId(ctx());
    FilterConfig<AttachmentManagementListView> filterConfig = this.getTableProvider()
            .get().attachmentManagement.filterConfig.persistCurrentInDefault(uid, request());

    if (filterConfig == null) {
        return ok(views.html.framework_views.parts.table.dynamic_tableview_no_more_compatible.render());
    } else {
        Pair<Table<AttachmentManagementListView>, Pagination<Attachment>> t = getTable(filterConfig);

        return ok(views.html.framework_views.parts.table.dynamic_tableview.render(t.getLeft(), t.getRight()));
    }

}

From source file:io.cloudslang.lang.compiler.parser.MetadataParser.java

private void handleDescriptionLineGeneralSyntax(DescriptionBuilder descriptionBuilder, String currentLine) {
    // if description is opened
    if (descriptionBuilder.descriptionOpened()) {
        // add/*from   w w  w .j a v a 2 s.co m*/
        Pair<String, String> data = descriptionPatternMatcher.getDescriptionGeneralLineData(currentLine);
        descriptionBuilder.addToDescription(data.getLeft(), data.getRight());
    }
    // otherwise ignore
}

From source file:io.cloudslang.lang.compiler.parser.MetadataParser.java

private void handleDescriptionLineVariableSyntax(DescriptionBuilder descriptionBuilder, String currentLine) {
    // if description is opened
    if (descriptionBuilder.descriptionOpened()) {
        // add/*  w ww.ja va2  s. c o m*/
        Pair<String, String> data = descriptionPatternMatcher.getDescriptionVariableLineData(currentLine);
        descriptionBuilder.addToDescription(data.getLeft(), data.getRight());
    }
    // otherwise ignore
}

From source file:com.dancorder.Archiverify.SynchingVisitor.java

@Override
public void visitFile(Path relativeFilePath, FileExistence existence) {
    try {//from  ww  w .j a v a  2 s  .  co m
        if (isNotInErrorPath(relativeFilePath) && !fileHashStoreFactory.isHashFile(relativeFilePath)) {
            Path file1 = root1.resolve(relativeFilePath);
            Path file2 = root2.resolve(relativeFilePath);

            visitedFilesByDirectory.get(currentRelativeDirectoryPath).add(relativeFilePath.getFileName());

            Pair<FileHashStore, FileHashStore> hashStorePair = hashStoresByDirectory
                    .get(currentRelativeDirectoryPath);
            List<Action> newActions = syncLogic.compareFiles(file1, hashStorePair.getLeft(), file2,
                    hashStorePair.getRight());
            actions.addAll(newActions);
        }
    } catch (Exception e) {
        actions.add(new WarningAction(String.format(
                "Error caught visiting file %s this file will not be synched. %s", relativeFilePath, e)));
    }
}

From source file:com.netflix.genie.agent.execution.statemachine.StateMachineAutoConfiguration.java

private void configureStates(final StateMachineBuilder.Builder<States, Events> builder,
        final Collection<Pair<States, StateAction>> statesWithActions) throws Exception {
    // Set up initial and terminal states (action-free)
    final StateConfigurer<States, Events> stateConfigurer = builder.configureStates().withStates()
            .initial(States.READY).end(States.END);

    // Set up the rest of the states with their corresponding action
    for (Pair<States, StateAction> stateWithAction : statesWithActions) {
        final States state = stateWithAction.getLeft();
        final StateAction action = stateWithAction.getRight();
        stateConfigurer//from w  ww.  ja  v a2 s.  c  o m
                // Use entryAction because it is not interruptible.
                // StateAction is susceptible to cancellation in case of event-triggered transition out of the state.
                .state(state, action, null);
        log.info("Configured state {} with action {}", state, action.getClass().getSimpleName());
    }
}

From source file:com.netflix.spinnaker.clouddriver.kubernetes.v2.caching.view.provider.KubernetesV2ManifestProvider.java

@Override
public KubernetesV2Manifest getManifest(String account, String location, String name) {
    Pair<KubernetesKind, String> parsedName;
    try {/*from   ww  w . ja v a2s .  c om*/
        parsedName = KubernetesManifest.fromFullResourceName(name);
    } catch (Exception e) {
        return null;
    }

    KubernetesKind kind = parsedName.getLeft();
    String key = Keys.infrastructure(kind, account, location, parsedName.getRight());

    Optional<CacheData> dataOptional = cacheUtils.getSingleEntry(kind.toString(), key);
    if (!dataOptional.isPresent()) {
        return null;
    }

    CacheData data = dataOptional.get();
    KubernetesResourceProperties properties = registry.get(account, kind);
    if (properties == null) {
        return null;
    }

    Function<KubernetesManifest, String> lastEventTimestamp = (
            m) -> (String) m.getOrDefault("lastTimestamp", m.getOrDefault("firstTimestamp", "n/a"));

    List<KubernetesManifest> events = cacheUtils
            .getTransitiveRelationship(kind.toString(), Collections.singletonList(key),
                    KubernetesKind.EVENT.toString())
            .stream().map(KubernetesCacheDataConverter::getManifest)
            .sorted(Comparator.comparing(lastEventTimestamp)).collect(Collectors.toList());

    KubernetesHandler handler = properties.getHandler();

    KubernetesManifest manifest = KubernetesCacheDataConverter.getManifest(data);
    Moniker moniker = KubernetesCacheDataConverter.getMoniker(data);

    return new KubernetesV2Manifest().builder().account(account).location(location).manifest(manifest)
            .moniker(moniker).status(handler.status(manifest)).artifacts(handler.listArtifacts(manifest))
            .events(events).build();
}

From source file:com.norconex.importer.handler.tagger.impl.TextBetweenTagger.java

@Override
protected void tagStringContent(String reference, StringBuilder content, ImporterMetadata metadata,
        boolean parsed, boolean partialContent) {
    int flags = Pattern.DOTALL | Pattern.UNICODE_CASE;
    if (!caseSensitive) {
        flags = flags | Pattern.CASE_INSENSITIVE;
    }/*from   w ww . j a va  2 s .co m*/
    for (TextBetween between : betweens) {
        List<Pair<Integer, Integer>> matches = new ArrayList<Pair<Integer, Integer>>();
        Pattern leftPattern = Pattern.compile(between.start, flags);
        Matcher leftMatch = leftPattern.matcher(content);
        while (leftMatch.find()) {
            Pattern rightPattern = Pattern.compile(between.end, flags);
            Matcher rightMatch = rightPattern.matcher(content);
            if (rightMatch.find(leftMatch.end())) {
                if (inclusive) {
                    matches.add(new ImmutablePair<Integer, Integer>(leftMatch.start(), rightMatch.end()));
                } else {
                    matches.add(new ImmutablePair<Integer, Integer>(leftMatch.end(), rightMatch.start()));
                }
            } else {
                break;
            }
        }
        for (int i = matches.size() - 1; i >= 0; i--) {
            Pair<Integer, Integer> matchPair = matches.get(i);
            String value = content.substring(matchPair.getLeft(), matchPair.getRight());
            if (value != null) {
                metadata.addString(between.name, value);
            }
        }
    }
}