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.qwazr.webapps.example.DocumentationServlet.java

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    String path = request.getPathInfo().substring(remotePrefix.length());

    File file = new File(documentationPath, path);
    if (!file.exists()) {
        response.sendError(404, "File not found: " + file);
        return;/*from w  w w.  j a v a 2s  .  co m*/
    }
    if (file.isDirectory()) {
        if (!path.endsWith("/")) {
            response.sendRedirect(request.getPathInfo() + '/');
            return;
        }
        for (String indexFileName : indexFileNames) {
            File readMefile = new File(file, indexFileName);
            if (readMefile.exists()) {
                file = readMefile;
                break;
            }
        }
    }

    Pair<String, String[]> paths = getRemoteLink(path);
    request.setAttribute("original_link", paths.getLeft());
    request.setAttribute("breadcrumb_parts", paths.getRight());

    if (!file.exists()) {
        response.sendError(404, "File not found: " + file);
        return;
    }

    request.setAttribute("currentfile", file);
    final String extension = FilenameUtils.getExtension(file.getName());
    final List<File> fileList = getBuildList(file.getParentFile());
    if ("md".equals(extension)) {
        request.setAttribute("markdown", markdownTool.toHtml(file));
        request.setAttribute("filelist", fileList);
    } else if ("adoc".equals(extension)) {
        request.setAttribute("adoc", asciiDoctorTool.convertFile(file));
        request.setAttribute("filelist", fileList);
    } else if (file.isFile()) {
        String type = mimeTypeMap.getContentType(file);
        if (type != null)
            response.setContentType(type);
        response.setContentLengthLong(file.length());
        response.setDateHeader("Last-Modified", file.lastModified());
        response.setHeader("Cache-Control", "max-age=86400");
        response.setDateHeader("Expires", System.currentTimeMillis() + 86400 * 1000);
        InputStream inputStream = new FileInputStream(file);
        try {
            IOUtils.copy(inputStream, response.getOutputStream());
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
        return;
    } else if (file.isDirectory()) {
        request.setAttribute("filelist", getBuildList(file));
    } else {
        response.sendRedirect(paths.getLeft());
    }
    try {
        freemarkerTool.template(templatePath, request, response);
    } catch (TemplateException e) {
        throw new ServletException(e);
    }
}

From source file:com.twosigma.beaker.clojure.util.ClojureTableDeserializer.java

@Override
@SuppressWarnings("unchecked")
public Object deserialize(JsonNode n, ObjectMapper mapper) {

    org.apache.commons.lang3.tuple.Pair<String, Object> deserializeObject = TableDisplayDeSerializer
            .getDeserializeObject(parent, n, mapper);
    String subtype = deserializeObject.getLeft();
    if (subtype != null && subtype.equals(TableDisplay.DICTIONARY_SUBTYPE)) {
        return PersistentArrayMap.create((Map) deserializeObject.getRight());
    } else if (subtype != null && subtype.equals(TableDisplay.LIST_OF_MAPS_SUBTYPE)) {
        List<Map<String, Object>> rows = (List<Map<String, Object>>) deserializeObject.getRight();
        List<Object> oo = new ArrayList<Object>();
        for (Map<String, Object> row : rows) {
            oo.add(PersistentArrayMap.create(row));
        }/*from  w w w .j a va2  s  .co  m*/
        return PersistentVector.create(oo);
    } else if (subtype != null && subtype.equals(TableDisplay.MATRIX_SUBTYPE)) {
        List<List<?>> matrix = (List<List<?>>) deserializeObject.getRight();
        return PersistentVector.create(matrix);
    }
    return deserializeObject.getRight();
}

From source file:enumj.StreamComparator.java

public void build() {

    if (built) {/*  w w  w  . j  av a2 s . co  m*/
        return;
    }

    for (int i = 0; i < length; ++i) {
        final Pair<Function<Stream<T>, Stream<T>>, Function<E, E>> transf = getFuns();

        lhs = transf.getLeft().apply(lhs);
        rhs = transf.getRight().apply(rhs);
    }

    built = true;
}

From source file:eu.bittrade.libs.steemj.communication.CommunicationHandler.java

/**
 * Perform a request to the web socket API whose response will automatically
 * get transformed into the given object.
 * /*from   w  ww. ja  v a2 s . c  o  m*/
 * @param requestObject
 *            A request object that contains all needed parameters.
 * @param targetClass
 *            The type the response should be transformed to.
 * @param <T>
 *            The type that should be returned.
 * @return The server response transformed into a list of given objects.
 * @throws SteemTimeoutException
 *             If the server was not able to answer the request in the given
 *             time (@see
 *             {@link eu.bittrade.libs.steemj.configuration.SteemJConfig#setResponseTimeout(int)
 *             setResponseTimeout()})
 * @throws SteemCommunicationException
 *             If there is a connection problem.
 * @throws SteemTransformationException
 *             If the SteemJ is unable to transform the JSON response into a
 *             Java object.
 * @throws SteemResponseException
 *             If the Server returned an error object.
 */
public <T> List<T> performRequest(JsonRPCRequest requestObject, Class<T> targetClass)
        throws SteemCommunicationException, SteemResponseException {
    try {
        Pair<URI, Boolean> endpoint = SteemJConfig.getInstance().getNextEndpointURI(numberOfConnectionTries++);
        JsonRPCResponse rawJsonResponse = client.invokeAndReadResponse(requestObject, endpoint.getLeft(),
                endpoint.getRight());
        LOGGER.debug("Received {} ", rawJsonResponse);

        if (rawJsonResponse.isError()) {
            throw rawJsonResponse.handleError(requestObject.getId());
        } else {
            // HANDLE NORMAL RESPONSE
            JavaType expectedResultType = mapper.getTypeFactory().constructCollectionType(List.class,
                    targetClass);
            return rawJsonResponse.handleResult(expectedResultType, requestObject.getId());
        }
    } catch (SteemCommunicationException e) {
        LOGGER.warn("The connection has been closed. Switching the endpoint and reconnecting.");
        LOGGER.debug("For the following reason: ", e);

        return performRequest(requestObject, targetClass);
    }
}

From source file:de.tuberlin.uebb.jbop.optimizer.var.LocalVarInliner.java

private AbstractInsnNode skipVars(final AbstractInsnNode currentNode, final Map<Integer, Object> knownValues) {
    final Pair<AbstractInsnNode, AbstractInsnNode> loopBounds = LoopMatcher.getLoopBounds(currentNode);
    final Collection<Integer> vars = getVarsInRange(loopBounds.getLeft(), loopBounds.getRight());
    for (final Integer varInLoop : vars) {
        knownValues.remove(varInLoop);//from ww w .ja  v  a2s  . c om
    }
    return loopBounds.getRight().getNext();
}

From source file:com.act.lcms.plotter.WriteAndPlotMS1Results.java

private void writeFeedMS1Values(List<Pair<Double, Double>> concentrationIntensity, OutputStream os)
        throws IOException {
    PrintStream out = new PrintStream(os);
    for (Pair<Double, Double> ci : concentrationIntensity) {
        out.format("%f\t%f\n", ci.getLeft(), ci.getRight());
    }//from   w w w .  ja v  a 2  s  .  com
    out.flush();
}

From source file:io.cloudslang.lang.compiler.modeller.MetadataModellerImpl.java

private Pair<List<StepMetadata>, List<RuntimeException>> transformStepsData(
        Map<String, ParsedDescriptionSection> stepsData) {
    List<StepMetadata> stepsMetadata = new ArrayList<>();
    List<RuntimeException> errors = new ArrayList<>();
    for (Map.Entry<String, ParsedDescriptionSection> entry : stepsData.entrySet()) {
        String stepName = entry.getKey();
        ParsedDescriptionSection parsedData = entry.getValue();
        Pair<StepMetadata, List<RuntimeException>> transformResult = transformToStepMetadata(stepName,
                parsedData.getData());//from  www  . j a  va 2 s  .c om
        stepsMetadata.add(transformResult.getLeft());
        errors.addAll(transformResult.getRight());
    }

    return new ImmutablePair<>(stepsMetadata, errors);
}

From source file:com.ijuru.kwibuka.WordListWordifier.java

/**
 * Recursively tries sequences of words/*from   w w  w .  j  a  v  a2 s.  c  o m*/
 * @param completed the completed sequences
 * @param current the current sequence
 * @param remainder the input remainder
 */
protected void trySequence(List<WordSequence> completed, WordSequence current, String remainder) {

    if (remainder.length() == 0) {
        completed.add(current);
        return;
    }

    List<Pair<Set<String>, String>> splits = splitInput(remainder);

    for (Pair<Set<String>, String> split : splits) {

        for (String token : split.getLeft()) {
            WordSequence tokensCopy = current.clone();
            tokensCopy.add(token);

            trySequence(completed, tokensCopy, split.getRight());
        }
    }
}

From source file:net.malisis.blocks.item.MixedBlockBlockItem.java

@Override
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean advancedTooltip) {
    if (itemStack.getTagCompound() == null)
        return;//from   ww  w.  j av  a  2s .  c  om

    Pair<IBlockState, IBlockState> pair = readNBT(itemStack.getTagCompound());

    Item item = itemsAllowed.inverse().get(pair.getLeft());
    ItemStack is1 = item != null ? new ItemStack(item) : ItemUtils.getItemStackFromState(pair.getLeft());
    item = itemsAllowed.inverse().get(pair.getRight());
    ItemStack is2 = item != null ? new ItemStack(item) : ItemUtils.getItemStackFromState(pair.getRight());

    list.addAll(is1.getTooltip(player, advancedTooltip));
    list.addAll(is2.getTooltip(player, advancedTooltip));
}

From source file:at.gridtec.lambda4j.function.bi.BiFunction2.java

/**
 * Applies this function to the given tuple.
 *
 * @param tuple The tuple to be applied to the function
 * @return The return value from the function, which is its result.
 * @throws NullPointerException If given argument is {@code null}
 * @see org.apache.commons.lang3.tuple.Pair
 *//*from w w w  .  j a va  2  s.  c  o m*/
default R apply(@Nonnull Pair<T, U> tuple) {
    Objects.requireNonNull(tuple);
    return apply(tuple.getLeft(), tuple.getRight());
}