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:alfio.util.TemplateResourceTest.java

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

From source file:com.romeikat.datamessie.core.base.util.LuceneQueryUtil.java

public Query getProximityQuery(final Collection<String> term1Variants, final Collection<String> term2Variants,
        final Integer slop) {
    if (term1Variants.isEmpty() || term2Variants.isEmpty()) {
        return new MatchAllDocsQuery();
    }/*from w w w  .  j  av a 2 s .c  om*/

    final BooleanQuery.Builder builder = new BooleanQuery.Builder();
    final Collection<Pair<String, String>> variantsCombinations = collectionUtil.getPairs(term1Variants,
            term2Variants);
    for (final Pair<String, String> variantsCombination : variantsCombinations) {
        final PhraseQuery.Builder builder2 = new PhraseQuery.Builder();
        builder2.add(new Term(FIELD, variantsCombination.getLeft()));
        builder2.add(new Term(FIELD, variantsCombination.getRight()));
        builder2.setSlop(slop == null ? Integer.MAX_VALUE : slop);

        builder.add(builder2.build(), BooleanClause.Occur.MUST);
    }

    return builder.build();
}

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

@Override
public void visitFile(Path relativeFilePath, FileExistence existence) {
    try {//ww  w . ja v a 2 s .c  om
        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.streamsets.pipeline.stage.processor.jdbcmetadata.JdbcMetadataProcessor.java

/** {@inheritDoc} */
@Override//from w w  w.java2s .  c o m
protected List<ConfigIssue> init() {
    // Validate configuration values and open any required resources.
    List<ConfigIssue> issues = super.init();

    errorRecordHandler = new DefaultErrorRecordHandler(getContext());
    elEvals.init(getContext());

    Processor.Context context = getContext();

    issues.addAll(hikariConfigBean.validateConfigs(context, issues));

    if (issues.isEmpty() && null == dataSource) {
        try {
            dataSource = jdbcUtil.createDataSourceForWrite(hikariConfigBean, null, null, false, issues,
                    Collections.emptyList(), getContext());
        } catch (RuntimeException | SQLException | StageException e) {
            LOG.debug("Could not connect to data source", e);
            issues.add(getContext().createConfigIssue(Groups.JDBC.name(), CONNECTION_STRING, JdbcErrors.JDBC_00,
                    e.toString()));
        }
    }

    if (issues.isEmpty()) {
        try {
            schemaWriter = JdbcSchemaWriterFactory.create(hikariConfigBean.getConnectionString(), dataSource);
        } catch (JdbcStageCheckedException e) {
            issues.add(getContext().createConfigIssue(Groups.JDBC.name(), CONNECTION_STRING, e.getErrorCode(),
                    e.getParams()));
        }
        schemaReader = new JdbcSchemaReader(dataSource, schemaWriter);

        tableCache = CacheBuilder.newBuilder().maximumSize(50)
                .build(new CacheLoader<Pair<String, String>, LinkedHashMap<String, JdbcTypeInfo>>() {
                    @Override
                    public LinkedHashMap<String, JdbcTypeInfo> load(Pair<String, String> pair)
                            throws Exception {
                        return schemaReader.getTableSchema(pair.getLeft(), pair.getRight());
                    }
                });
    }

    // If issues is not empty, the UI will inform the user of each configuration issue in the list.
    return issues;
}

From source file:edu.sdsc.scigraph.internal.reachability.ReachabilityIndex.java

public Set<Pair<Node, Node>> getConnectedPairs(Set<Node> sources, Set<Node> targets) {
    return evaluatePairs(sources, targets, new Predicate<Pair<Node, Node>>() {
        @Override/* w  w w .j a  v  a 2 s  .co m*/
        public boolean apply(Pair<Node, Node> pair) {
            return canReach(pair.getLeft(), pair.getRight());
        }
    });
}

From source file:edu.sdsc.scigraph.internal.reachability.ReachabilityIndex.java

public Set<Pair<Node, Node>> getDisconnectedPairs(Set<Node> sources, Set<Node> targets) {
    return evaluatePairs(sources, targets, new Predicate<Pair<Node, Node>>() {
        @Override/*from ww  w  .  ja  va  2  s  .  c  o  m*/
        public boolean apply(Pair<Node, Node> pair) {
            return !canReach(pair.getLeft(), pair.getRight());
        }
    });
}

From source file:edu.uci.ics.hyracks.api.client.impl.ActivityClusterGraphBuilder.java

public ActivityClusterGraph inferActivityClusters(JobId jobId, JobActivityGraph jag) {
    /*//  w ww.jav a2 s .c o m
     * Build initial equivalence sets map. We create a map such that for each IOperatorTask, t -> { t }
     */
    Map<ActivityId, Set<ActivityId>> stageMap = new HashMap<ActivityId, Set<ActivityId>>();
    Set<Set<ActivityId>> stages = new HashSet<Set<ActivityId>>();
    for (ActivityId taskId : jag.getActivityMap().keySet()) {
        Set<ActivityId> eqSet = new HashSet<ActivityId>();
        eqSet.add(taskId);
        stageMap.put(taskId, eqSet);
        stages.add(eqSet);
    }

    boolean changed = true;
    while (changed) {
        changed = false;
        Pair<ActivityId, ActivityId> pair = findMergePair(jag, stages);
        if (pair != null) {
            merge(stageMap, stages, pair.getLeft(), pair.getRight());
            changed = true;
        }
    }

    ActivityClusterGraph acg = new ActivityClusterGraph();
    Map<ActivityId, ActivityCluster> acMap = new HashMap<ActivityId, ActivityCluster>();
    int acCounter = 0;
    Map<ActivityId, IActivity> activityNodeMap = jag.getActivityMap();
    List<ActivityCluster> acList = new ArrayList<ActivityCluster>();
    for (Set<ActivityId> stage : stages) {
        ActivityCluster ac = new ActivityCluster(acg, new ActivityClusterId(jobId, acCounter++));
        acList.add(ac);
        for (ActivityId aid : stage) {
            IActivity activity = activityNodeMap.get(aid);
            ac.addActivity(activity);
            acMap.put(aid, ac);
        }
    }

    for (Set<ActivityId> stage : stages) {
        for (ActivityId aid : stage) {
            IActivity activity = activityNodeMap.get(aid);
            ActivityCluster ac = acMap.get(aid);
            List<IConnectorDescriptor> aOutputs = jag.getActivityOutputMap().get(aid);
            if (aOutputs == null || aOutputs.isEmpty()) {
                ac.addRoot(activity);
            } else {
                int nActivityOutputs = aOutputs.size();
                for (int i = 0; i < nActivityOutputs; ++i) {
                    IConnectorDescriptor conn = aOutputs.get(i);
                    ac.addConnector(conn);
                    Pair<Pair<IActivity, Integer>, Pair<IActivity, Integer>> pcPair = jag
                            .getConnectorActivityMap().get(conn.getConnectorId());
                    ac.connect(conn, activity, i, pcPair.getRight().getLeft(), pcPair.getRight().getRight(),
                            jag.getConnectorRecordDescriptorMap().get(conn.getConnectorId()));
                }
            }
        }
    }

    Map<ActivityId, Set<ActivityId>> blocked2BlockerMap = jag.getBlocked2BlockerMap();
    for (ActivityCluster s : acList) {
        Map<ActivityId, Set<ActivityId>> acBlocked2BlockerMap = s.getBlocked2BlockerMap();
        Set<ActivityCluster> blockerStages = new HashSet<ActivityCluster>();
        for (ActivityId t : s.getActivityMap().keySet()) {
            Set<ActivityId> blockerTasks = blocked2BlockerMap.get(t);
            acBlocked2BlockerMap.put(t, blockerTasks);
            if (blockerTasks != null) {
                for (ActivityId bt : blockerTasks) {
                    blockerStages.add(acMap.get(bt));
                }
            }
        }
        for (ActivityCluster bs : blockerStages) {
            s.getDependencies().add(bs);
        }
    }
    acg.addActivityClusters(acList);

    if (LOGGER.isLoggable(Level.FINE)) {
        try {
            LOGGER.fine(acg.toJSON().toString(2));
        } catch (JSONException e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
    return acg;
}

From source file:net.community.chest.gitcloud.facade.AbstractContextInitializer.java

protected File resolveApplicationBase(MutablePropertySources propSources,
        ExtendedPlaceholderResolver sourcesResolver) {
    Pair<File, Boolean> result = ConfigUtils.resolveGitcloudBase(sourcesResolver);
    File rootDir = result.getLeft();
    Boolean baseExists = result.getRight();
    if (!baseExists.booleanValue()) {
        propSources.addFirst(new MapPropertySource("gitcloudBase", Collections
                .<String, Object>singletonMap(ConfigUtils.GITCLOUD_BASE_PROP, rootDir.getAbsolutePath())));
        System.setProperty(ConfigUtils.GITCLOUD_BASE_PROP, rootDir.getAbsolutePath());
        logger.info("resolveApplicationBase - added " + ConfigUtils.GITCLOUD_BASE_PROP + ": "
                + ExtendedFileUtils.toString(rootDir));
    }//from   w  w w.j a  v  a  2 s  .co m

    return rootDir;
}

From source file:com.vmware.photon.controller.api.frontend.commands.steps.TenantPushSecurityGroupsStepCmd.java

@Override
protected void execute() throws ExternalException {
    List<TenantEntity> tenantList = step.getTransientResourceEntities(null);
    checkArgument(tenantList.size() > 0);

    for (TenantEntity tenantEntity : tenantList) {
        logger.info("Propagating the security groups of tenant {}", tenantEntity.getId());

        // Since this step might be called by deployment when propagating the security groups,
        // we need to refresh the tenantEntity to make sure it has the latest security groups.
        tenantEntity = tenantBackend.findById(tenantEntity.getId());

        List<Project> projects = new ArrayList<>();
        ResourceList<Project> resourceList = projectBackend.filter(tenantEntity.getId(),
                Optional.<String>absent(), Optional.of(PaginationConfig.DEFAULT_DEFAULT_PAGE_SIZE));
        projects.addAll(resourceList.getItems());

        while (StringUtils.isNotBlank(resourceList.getNextPageLink())) {
            resourceList = projectBackend.getProjectsPage(resourceList.getNextPageLink());
            projects.addAll(resourceList.getItems());
        }//from   w ww. j av  a2 s  .c om

        List<String> tenantSecurityGroups = tenantEntity.getSecurityGroups().stream().map(g -> g.getName())
                .collect(Collectors.toList());

        for (Project project : projects) {
            logger.info("Updating the security groups of project {} using the ones from tenant {}",
                    project.getId(), tenantEntity.getId());

            List<SecurityGroup> currSecurityGroups = project.getSecurityGroups();
            Pair<List<SecurityGroup>, List<String>> result = SecurityGroupUtils
                    .mergeParentSecurityGroups(currSecurityGroups, tenantSecurityGroups);

            projectBackend.replaceSecurityGroups(project.getId(), result.getLeft());

            if (result.getRight() != null && !result.getRight().isEmpty()) {
                step.addWarning(new SecurityGroupsAlreadyInheritedException(result.getRight()));
            }
        }
    }
}

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"));
}