Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.util.Iterator;
import java.util.List;

public class Main {
    /**
     * Appends the specified path token to the provided buffer
     * followed by the position specification of the target node in
     * its siblings list.
     *
     * @param  node        the target node for the XPath expression.
     * @param  siblings    the siblings of the target node.
     * @param  pathToken   the path token identifying the target node.
     * @param  buffer      the buffer to which appending the XPath
     *                     sub-expression or <code>null</code> if the
     *                     method shall allocate a new buffer.
     *
     * @return the XPath sub-expression to select the target node
     *         among its siblings.
     */
    private static StringBuilder getPositionPath(Object node, List<?> siblings, String pathToken,
            StringBuilder buffer) {
        if (buffer == null) {
            buffer = new StringBuilder();
        }
        if (pathToken != null) {
            buffer.append(pathToken);
        }

        if ((siblings != null) && (siblings.size() != 1)) {
            int position = 0;
            for (Iterator<?> i = siblings.iterator(); i.hasNext();) {
                position++;
                if (i.next() == node)
                    break;
            }
            buffer.append('[').append(position).append(']');
        }
        return buffer;
    }
}