Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

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

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 StringBuffer getPositionPath(Object node, List siblings, String pathToken, StringBuffer buffer) {
        if (buffer == null) {
            buffer = new StringBuffer();
        }
        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;
    }
}