Example usage for org.dom4j Node numberValueOf

List of usage examples for org.dom4j Node numberValueOf

Introduction

In this page you can find the example usage for org.dom4j Node numberValueOf.

Prototype

Number numberValueOf(String xpathExpression);

Source Link

Document

numberValueOf evaluates an XPath expression and returns the numeric value of the XPath expression if the XPath expression results in a number, or null if the result is not a number.

Usage

From source file:com.adobe.ac.maven.ncss.NumericNodeComparator.java

License:Apache License

/**
 * {@inheritDoc}// w w w  .j av a2  s .c o m
 */
public int compare(final Object object1, final Object object2) {
    final Node node1 = (Node) object1;
    final Node node2 = (Node) object2;
    return node2.numberValueOf(tagProperty).intValue() - node1.numberValueOf(tagProperty).intValue();
}

From source file:com.adobe.ac.pmd.metrics.maven.utils.NumericNodeComparator.java

License:Apache License

/**
 * {@inheritDoc}//from w w w . ja v  a 2  s .  c o  m
 */
public int compare(final Node node1, final Node node2) {
    return node2.numberValueOf(tagProperty).intValue() - node1.numberValueOf(tagProperty).intValue();
}

From source file:nl.ru.cmbi.pisa.wrapper.PisaCachedWebDao.java

License:Apache License

/**
 * Gets the 3D rotation-translation biomolecule matrices from PISA.
 * <p>//from  w w w.  j  a v a2 s . c o m
 * These matrices detail how chains in the specified PDB entry should be manipulated to obtain desired the PISA
 * assembly.
 * 
 * @param rawPdbId
 *            the 4-letter PDB code we want the assembly of (e.g. "1crn")
 * @param setNr
 *            the PISA assembly set. "1" is most stable in solution, higher numbers increasingly unstable.
 * @param assemblyNr
 *            the substructure within an assembly. Note that structurally identical substructures get the
 *            same assemblyNr. This DAO ignores all but the first substructure. Ignored chains (those chains not
 *            needed to make this assembly) are listed in the {@link MatricesResult#ignoredChains} property of the
 *            returned result.
 * @return A compound result of the transformation matrices to apply and the ignored chains (I.E. those
 *         chains whose transformation lead to an identical substructure to the one returned). This result may be
 *         empty.
 * @throws IOException
 *             when web-fetching fails.
 */
@SuppressWarnings("unchecked")
public MatricesResult getMatrices(final String rawPdbId, final int setNr, final int assemblyNr)
        throws IOException {

    final String pdbId = rawPdbId.trim().toLowerCase();
    Document mmrInfo;
    try {
        mmrInfo = parseDocumentOf(getRawMultimerInfoSingle(pdbId));
    } catch (final DocumentException docex) {
        log.error("Problem parsing Pisa raw multimer info for {}, see debug level for details", pdbId);
        log.debug("Exception: ", docex);
        throw new IOException("Problem parsing multimer XML document", docex);
    }

    final List<ChainTransform> output = new ArrayList<ChainTransform>();
    final Set<String> ignoredChainIds = new HashSet<String>();

    try {
        // Unfortunately, multiple assemblies share the same <ID> subnode if they are structurally identical
        // So, we need indexing ("[1]") to get only the first of an identical set of assemblies
        // ('identical' meaning "structurally identical except for ChainIDs")
        // Sigh... reusing IDs for different things!
        final String matricesXpath = String.format(
                "(/pisa_multimers/pdb_entry[ pdb_code='%s' ]/asm_set[ ser_no=%d ]/assembly[ id=%d ])[1]/molecule",
                pdbId, setNr, assemblyNr);

        final List<Node> matrices = mmrInfo.selectNodes(matricesXpath);

        for (final Node node : matrices) {
            final ChainTransform ct = new ChainTransform(node.valueOf("chain_id"),
                    // X-row
                    (Double) node.numberValueOf("rxx"), (Double) node.numberValueOf("rxy"),
                    (Double) node.numberValueOf("rxz"), (Double) node.numberValueOf("tx"),
                    // Y-row
                    (Double) node.numberValueOf("ryx"), (Double) node.numberValueOf("ryy"),
                    (Double) node.numberValueOf("ryz"), (Double) node.numberValueOf("ty"),
                    // Z-row
                    (Double) node.numberValueOf("rzx"), (Double) node.numberValueOf("rzy"),
                    (Double) node.numberValueOf("rzz"), (Double) node.numberValueOf("tz"));
            if (ct.isUnity() && ct.isStationary()) {
                ct.setDuplication(false);
            } else {
                ct.setDuplication(true);
            }

            output.add(ct);
        }

        final String ignoredMatricesXpath = String.format(
                "(/pisa_multimers/pdb_entry[ pdb_code='%s' ]/asm_set[ ser_no=%d ]/assembly[ id=%d ])[position() > 1]/molecule/chain_id",
                pdbId, setNr, assemblyNr);
        final List<Node> ignoredChains = mmrInfo.selectNodes(ignoredMatricesXpath);

        for (final Node ignoredChain : ignoredChains) {
            ignoredChainIds.add(ignoredChain.getText());
        }

    } catch (final ClassCastException ccex) {
        log.error(
                "malformed XML response from PISA when getting matrices for assembly {}:{}.{}: expected list of matrix nodes, but obtained something else",
                new Object[] { pdbId, setNr, assemblyNr });
        throw new IOException("malformed XML response from PISA when getting matrices for assembly of " + pdbId
                + ": expected list of matrix nodes, but obtained something else", ccex);
    }

    return new MatricesResult(output, ignoredChainIds);
}

From source file:org.codehaus.mojo.javancss.NumericNodeComparator.java

License:Apache License

/**
 * {@inheritDoc}/*from w ww .j a va 2s.  com*/
 */
public int compare(Object object1, Object object2) {
    Node node1 = (Node) object1;
    Node node2 = (Node) object2;
    return node2.numberValueOf(tagProperty).intValue() - node1.numberValueOf(tagProperty).intValue();
}