Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2005-2011, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**
     * Split X-path string in to string steps, ignoring / characters inside [] 
     * 
     * @param s x-path string
     * @return list of string steps
     */
    private static List<String> splitPath(String s) {
        ArrayList<String> parts = new ArrayList<String>();

        StringBuffer b = new StringBuffer();
        int insideIndex = 0;
        for (int pos = 0; pos < s.length(); pos++) {
            if (s.charAt(pos) == '/' && insideIndex == 0) {
                parts.add(b.toString());
                b = new StringBuffer();
            } else {
                if (s.charAt(pos) == '[') {
                    insideIndex++;
                } else if (s.charAt(pos) == ']') {
                    insideIndex--;
                }
                b.append(s.charAt(pos));
            }
        }
        parts.add(b.toString());
        return parts;
    }
}