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.github.blindpirate.gogradle.core.dependency.produce.external.gopm.GopmfileParser.java

private Map<String, Object> toNotation(Pair<String, String> nameAndValue) {
    String name = nameAndValue.getLeft();
    String value = nameAndValue.getRight();

    Map<String, Object> ret = new HashMap<>();
    ret.put(NAME_KEY, name);/* ww w .  ja  v a2 s.  c  o  m*/
    if (value.startsWith(BRANCH_KEYWORD)) {
        ret.put(BRANCH_KEY, value.substring(BRANCH_KEYWORD.length()));
    } else if (value.startsWith(TAG_KEYWORD)) {
        ret.put(TAG_KEY, value.substring(TAG_KEYWORD.length()));
    } else if (value.startsWith(COMMIT_KEYWORD)) {
        ret.put(COMMIT_KEY, value.substring(COMMIT_KEYWORD.length()));
    } else if (isNotBlank(value)) {
        // it will be treated as file path
        ret.put(DIR_KEY, value);
    }
    return ret;
}

From source file:com.intuit.karate.Script.java

public static void setValueByPath(String name, String path, String exp, ScriptContext context) {
    name = StringUtils.trim(name);//from   ww w .j a v  a  2  s .c  om
    if ("request".equals(name) || "url".equals(name)) {
        throw new RuntimeException("'" + name + "' is not a variable," + " use the form '* " + name
                + " <expression>' to initialize the " + name + ", and <expression> can be a variable");
    }
    path = StringUtils.trimToNull(path);
    if (path == null) {
        Pair<String, String> pair = parseVariableAndPath(name);
        name = pair.getLeft();
        path = pair.getRight();
    }
    if (isJsonPath(path)) {
        ScriptValue target = context.vars.get(name);
        ScriptValue value = eval(exp, context);
        switch (target.getType()) {
        case JSON:
            DocumentContext dc = target.getValue(DocumentContext.class);
            JsonUtils.setValueByPath(dc, path, value.getAfterConvertingFromJsonOrXmlIfNeeded());
            break;
        case MAP:
            Map<String, Object> map = target.getValue(Map.class);
            DocumentContext fromMap = JsonPath.parse(map);
            JsonUtils.setValueByPath(fromMap, path, value.getAfterConvertingFromJsonOrXmlIfNeeded());
            context.vars.put(name, fromMap);
            break;
        default:
            throw new RuntimeException("cannot set json path on unexpected type: " + target);
        }
    } else if (isXmlPath(path)) {
        Document doc = context.vars.get(name, Document.class);
        ScriptValue sv = eval(exp, context);
        switch (sv.getType()) {
        case XML:
            Node node = sv.getValue(Node.class);
            XmlUtils.setByPath(doc, path, node);
            break;
        default:
            XmlUtils.setByPath(doc, path, sv.getAsString());
        }
    } else {
        throw new RuntimeException("unexpected path: " + path);
    }
}

From source file:com.minlia.cloud.framework.client.template.AbstractBaseClientRestTemplate.java

protected HttpHeaders readHeadersWithAuth() {
    final Pair<String, String> defaultCredentials = getReadCredentials();
    return readHeadersWithAuth(defaultCredentials.getLeft(), defaultCredentials.getRight());
}

From source file:com.facebook.presto.accumulo.AccumuloClient.java

private static List<AccumuloColumnHandle> getColumnHandles(ConnectorTableMetadata meta, String rowIdColumn) {
    // Get the column mappings from the table property or auto-generate columns if not defined
    Map<String, Pair<String, String>> mapping = AccumuloTableProperties.getColumnMapping(meta.getProperties())
            .orElse(autoGenerateMapping(meta.getColumns(),
                    AccumuloTableProperties.getLocalityGroups(meta.getProperties())));

    // The list of indexed columns
    Optional<List<String>> indexedColumns = AccumuloTableProperties.getIndexColumns(meta.getProperties());

    // And now we parse the configured columns and create handles for the metadata manager
    ImmutableList.Builder<AccumuloColumnHandle> cBuilder = ImmutableList.builder();
    for (int ordinal = 0; ordinal < meta.getColumns().size(); ++ordinal) {
        ColumnMetadata cm = meta.getColumns().get(ordinal);

        // Special case if this column is the row ID
        if (cm.getName().equalsIgnoreCase(rowIdColumn)) {
            cBuilder.add(new AccumuloColumnHandle(rowIdColumn, Optional.empty(), Optional.empty(), cm.getType(),
                    ordinal, "Accumulo row ID", false));
        } else {//from  ww w. ja  v a  2  s  .  com
            if (!mapping.containsKey(cm.getName())) {
                throw new InvalidParameterException(
                        format("Misconfigured mapping for presto column %s", cm.getName()));
            }

            // Get the mapping for this column
            Pair<String, String> famqual = mapping.get(cm.getName());
            boolean indexed = indexedColumns.isPresent()
                    && indexedColumns.get().contains(cm.getName().toLowerCase(Locale.ENGLISH));
            String comment = format("Accumulo column %s:%s. Indexed: %b", famqual.getLeft(), famqual.getRight(),
                    indexed);

            // Create a new AccumuloColumnHandle object
            cBuilder.add(new AccumuloColumnHandle(cm.getName(), Optional.of(famqual.getLeft()),
                    Optional.of(famqual.getRight()), cm.getType(), ordinal, comment, indexed));
        }
    }

    return cBuilder.build();
}

From source file:com.minlia.cloud.framework.client.template.AbstractBaseClientRestTemplate.java

protected HttpHeaders readHeadersWithAuth(final Pair<String, String> credentials) {
    if (credentials == null) {
        final Pair<String, String> readCredentials = getReadCredentials();
        return readHeadersWithAuth(readCredentials.getLeft(), readCredentials.getRight());
    }/* w w w  .ja v a 2s  . com*/
    return readHeadersWithAuth(credentials.getLeft(), credentials.getRight());
}

From source file:com.muk.services.facades.impl.DefaultPaymentFacade.java

@Override
public Map<String, Object> startPayment(PaymentRequest paymentRequest, UriComponents redirectComponents) {
    Map<String, Object> response = new HashMap<String, Object>();
    final ObjectNode payload = JsonNodeFactory.instance.objectNode();

    if (ServiceConstants.PaymentMethods.paypalExpress.equals(paymentRequest.getPaymentMethod())) {
        payload.put("intent", "sale");
        final ObjectNode redirectUrls = payload.putObject("redirect_urls");
        redirectUrls.put("return_url", redirectComponents.toUriString() + "/id/redirect");
        redirectUrls.put("cancel_url", redirectComponents.toUriString() + "/id/cancel");
        final ObjectNode payer = payload.putObject("payer");
        payer.put("payment_method", "paypal");
        final ArrayNode transactions = payload.putArray("transactions");
        final ObjectNode transaction = transactions.addObject();
        transaction.put("description", paymentRequest.getService());
        transaction.putObject("amount").put("total", paymentRequest.getPrice()).put("currency", "USD");

        response = paypalPaymentService.startPayment(payload);
    } else if (ServiceConstants.PaymentMethods.stripe.equals(paymentRequest.getPaymentMethod())) {
        payload.put("amount", (long) Math.floor(paymentRequest.getPrice() * 100d));
        payload.put("currency", "usd");
        payload.put("description", paymentRequest.getService());
        payload.put("source", paymentRequest.getInfo());

        if (StringUtils.isNotBlank(paymentRequest.getEmail())) {
            payload.put("receipt_email", paymentRequest.getEmail());
        }//from  w w w  . j a v  a  2  s .  com

        if (paymentRequest.getMetadata() != null) {
            final ObjectNode mds = payload.putObject("metadata");

            for (final Pair<String, String> pair : paymentRequest.getMetadata()) {
                mds.put(pair.getLeft(), pair.getRight());
            }
        }

        response = stripePaymentService.startPayment(payload);

    }

    return response;
}

From source file:com.minlia.cloud.framework.client.template.AbstractBaseClientRestTemplate.java

protected HttpHeaders writeHeadersWithAuth() {
    final Pair<String, String> defaultCredentials = getWriteCredentials();
    return writeHeadersWithAuth(defaultCredentials.getLeft(), defaultCredentials.getRight());
}

From source file:com.minlia.cloud.framework.client.template.AbstractBaseClientRestTemplate.java

protected HttpHeaders writeHeadersWithAuth(final Pair<String, String> credentials) {
    if (credentials == null) {
        final Pair<String, String> writeCredentials = getWriteCredentials();
        return writeHeadersWithAuth(writeCredentials.getLeft(), writeCredentials.getRight());
    }//from w ww  .j av a2s.c o  m
    return writeHeadersWithAuth(credentials.getLeft(), credentials.getRight());
}

From source file:net.mindengine.galen.specs.reader.page.RuleStandardProcessor.java

@Override
public void processRule(ObjectSpecs objectSpecs, String ruleText, VarsContext varsContext, PageSection section,
        Properties properties, String contextPath, PageSpecReader pageSpecReader) throws IOException {

    List<Pair<String, Place>> lines = new LinkedList<Pair<String, Place>>();
    String indentation = "";

    ObjectSpecs temporaryObjectSpecs = null;
    SpecGroup specGroup = null;/*  www. ja va2  s.c o  m*/

    if (objectSpecs != null) {
        indentation = "    ";

        specGroup = new SpecGroup();
        specGroup.setName(ruleText);

        temporaryObjectSpecs = new ObjectSpecs(objectSpecs.getObjectName());
    } else {
        PageSection subSection = new PageSection();
        subSection.setName(ruleText);
        section.addSubSection(subSection);
        section = subSection;
    }

    for (Pair<String, Place> line : originalLines) {
        lines.add(new ImmutablePair<String, Place>(indentation + line.getLeft(), line.getRight()));
    }

    StateDoingSection stateDoingSection = new StateDoingSection(properties, section, contextPath,
            pageSpecReader);

    if (objectSpecs != null) {
        stateDoingSection.setCurrentObject(temporaryObjectSpecs);
    }

    for (Pair<String, Place> line : lines) {
        stateDoingSection.process(varsContext, line.getLeft(), line.getRight());
    }

    if (objectSpecs != null) {
        specGroup.getSpecs().addAll(temporaryObjectSpecs.getSpecs());
        objectSpecs.getSpecGroups().add(specGroup);
    }
}

From source file:de.tntinteractive.portalsammler.engine.MapReaderTest.java

@Test
public void testSingleEntryMap() throws Exception {
    final String input = "test123\n" + " e1\n" + " w1\n" + ".";
    final MapReader r = createReader(input);
    final Pair<String, Map<String, String>> p = r.readNext();
    assertEquals("test123", p.getLeft());
    assertEquals(Collections.singletonMap("e1", "w1"), p.getRight());
    assertNull(r.readNext());//from  ww  w.  jav a  2  s  . c o  m
}